refactored test_regexps.coffee
This commit is contained in:
parent
63bc12d3f1
commit
a19ea4b662
|
@ -0,0 +1,56 @@
|
|||
# Regular Expressions
|
||||
# -------------------
|
||||
#TODO: add some rigorous regex interpolation tests
|
||||
|
||||
test "basic regular expression literals", ->
|
||||
ok 'a'.match(/a/)
|
||||
ok 'a'.match /a/
|
||||
ok 'a'.match(/a/g)
|
||||
ok 'a'.match /a/g
|
||||
|
||||
test "division is not confused for a regular expression", ->
|
||||
eq 2, 4 / 2 / 1
|
||||
|
||||
a = 4
|
||||
b = 2
|
||||
g = 1
|
||||
eq 2, a / b/g
|
||||
|
||||
obj = method: -> 2
|
||||
two = 2
|
||||
eq 2, (obj.method()/two + obj.method()/two)
|
||||
|
||||
i = 1
|
||||
eq 2, (4)/2/i
|
||||
eq 1, i/i/i
|
||||
|
||||
test "backslash escapes", ->
|
||||
eq "\\/\\\\", /\/\\/.source
|
||||
|
||||
test "#764: regular expressions should be indexable", ->
|
||||
eq /0/['source'], ///#{0}///['source']
|
||||
|
||||
test "#584: slashes are allowed unescaped in character classes", ->
|
||||
ok /^a\/[/]b$/.test 'a//b'
|
||||
|
||||
|
||||
#### Heregexe(n|s)
|
||||
|
||||
test "a heregex will ignore whitespace and comments", ->
|
||||
eq /^I'm\x20+[a]\s+Heregex?\/\/\//gim + '', ///
|
||||
^ I'm \x20+ [a] \s+
|
||||
Heregex? / // # or not
|
||||
///gim + ''
|
||||
|
||||
test "heregex interpolation", ->
|
||||
eq /\\#{}\\\"/ + '', ///
|
||||
#{
|
||||
"#{ '\\' }" # normal comment
|
||||
}
|
||||
# regex comment
|
||||
\#{}
|
||||
\\ \"
|
||||
/// + ''
|
||||
|
||||
test "an empty heregex will compile to an empty, non-capturing group", ->
|
||||
eq /(?:)/ + '', /// /// + ''
|
|
@ -1,51 +0,0 @@
|
|||
# Regular expression literals.
|
||||
ok 'x'.match(/x/g)
|
||||
ok 'x'.match /x/g
|
||||
ok 'x'.match(/x/)
|
||||
ok 'x'.match /x/
|
||||
|
||||
ok 4 / 2 / 1 is 2
|
||||
|
||||
y = 4
|
||||
x = 2
|
||||
g = 1
|
||||
|
||||
ok y / x/g is 2
|
||||
|
||||
obj = {
|
||||
width: -> 10
|
||||
height: -> 20
|
||||
}
|
||||
id = 2
|
||||
|
||||
ok (obj.width()/id - obj.height()/id) is -5
|
||||
|
||||
eq /\\/.source, "\\\\"
|
||||
|
||||
|
||||
eq /^I'm\s+Heregex?\/\/\//gim + '', ///
|
||||
^ I'm \s+ Heregex? / // # or not
|
||||
///gim + ''
|
||||
eq '\\\\#{}\\\\\\\"', ///
|
||||
#{
|
||||
"#{ '\\' }" # normal comment
|
||||
}
|
||||
# regex comment
|
||||
\#{}
|
||||
\\ \"
|
||||
///.source
|
||||
eq /// /// + '', '/(?:)/'
|
||||
|
||||
|
||||
#764: Should be indexable.
|
||||
eq /0/['source'], ///#{0}///['source']
|
||||
|
||||
|
||||
# If not preceded by whitespace, should be stricter.
|
||||
i = 5
|
||||
eq (1000)/200/i, 1
|
||||
|
||||
eq i/i/i, 0.2
|
||||
|
||||
#584: Unescaped slashes in character classes.
|
||||
ok /:\/[/]goog/.test 'http://google.com'
|
Loading…
Reference in New Issue