Skip to content

Commit

Permalink
move PatternSet to build-support
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Nov 24, 2024
1 parent 78024a6 commit 31a901e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
28 changes: 4 additions & 24 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _ = require 'underscore'
CoffeeScript = require './lib/coffeescript'
helpers = require './lib/coffeescript/helpers'
{ setupConsole } = require './build-support/console'
{ PatternSet } = require './build-support/patterns'

# ANSI Terminal Colors.
bold = red = green = yellow = reset = ''
Expand Down Expand Up @@ -428,27 +429,6 @@ task 'bench', 'quick benchmark of compilation time', ->
console.log "total #{ fmt total }"


class PatternSet
constructor: (patternStrings = [], {@negated = no} = {}) ->
@matchers = (new RegExp p for p in patternStrings when p isnt '')

isEmpty: -> @matchers.length is 0

iterMatchers: -> @matchers[Symbol.iterator]()

test_: (arg) -> @iterMatchers().some (m) -> m.exec arg

allows: (arg) ->
return yes if @isEmpty()
if @negated
not @test_ arg
else
@test_ arg

@fromCommaDelimitedList: (commaListStr) => new @ (commaListStr ? '').split /,/
@empty: ({negated = no} = {}) => new @ [], {negated}


# Run the CoffeeScript test suite.
runTests = (CoffeeScript, {filePatterns, negFilePatterns, descPatterns, negDescPatterns} = {}) ->
CoffeeScript.register() unless global.testingBrowser
Expand All @@ -457,7 +437,7 @@ runTests = (CoffeeScript, {filePatterns, negFilePatterns, descPatterns, negDescP
negFilePatterns ?= PatternSet.empty {negated: yes}
descPatterns ?= PatternSet.empty()
negDescPatterns ?= PatternSet.empty {negated: yes}
console.dir {filePatterns, negFilePatterns, descPatterns, negDescPatterns}
console.dir.debug {filePatterns, negFilePatterns, descPatterns, negDescPatterns}

# These are attached to `global` so that they’re accessible from within
# `test/async.coffee`, which has an async-capable version of
Expand Down Expand Up @@ -577,9 +557,9 @@ option null, '--negDesc [REGEXP*]', 'test description patterns to negatively mat

task 'test', 'run the CoffeeScript language test suite', ({
file = [],
negFile = ['sourcemap'],
negFile = [],
desc = [],
negDesc = ['#4418', '#4558', 'dynamic import assertion', 'assert keyword'],
negDesc = [],
} = {}) ->
testOptions =
filePatterns: new PatternSet file
Expand Down
18 changes: 18 additions & 0 deletions build-support/patterns.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
exports.PatternSet = class PatternSet
constructor: (patternStrings = [], {@negated = no} = {}) ->
@matchers = (new RegExp p for p in patternStrings when p isnt '')

isEmpty: -> @matchers.length is 0

iterMatchers: -> @matchers[Symbol.iterator]()

test_: (arg) -> @iterMatchers().some (m) -> m.exec arg

allows: (arg) ->
return yes if @isEmpty()
if @negated
not @test_ arg
else
@test_ arg

@empty: ({negated = no} = {}) => new @ [], {negated}

0 comments on commit 31a901e

Please sign in to comment.