-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmatchAll_spec.rb
60 lines (49 loc) · 1.86 KB
/
matchAll_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
gem 'minitest'
require 'minitest/autorun'
require 'ruby2js/filter/matchAll'
require 'ruby2js/filter/functions'
describe "matchAll support" do
def to_js(string)
_(Ruby2JS.convert(string, filters: [Ruby2JS::Filter::MatchAll]).to_s)
end
def to_js_fn1(string)
_(Ruby2JS.convert(string,
filters: [Ruby2JS::Filter::Functions, Ruby2JS::Filter::MatchAll]).to_s)
end
def to_js_2020(string)
_(Ruby2JS.convert(string, eslevel: 2020,
filters: [Ruby2JS::Filter::MatchAll]).to_s)
end
def to_js_fn2(string)
_(Ruby2JS.convert(string,
filters: [Ruby2JS::Filter::MatchAll, Ruby2JS::Filter::Functions]).to_s)
end
describe "without filter functions" do
it "should convert String.matchAll to RegExp.exec for ESLevel < 2020" do
to_js( 'str.matchAll(pattern).forEach {|match| console.log match}' ).
must_equal 'var match; ' +
'while (match = pattern.exec(str)) {console.log(match)}'
end
it "should leave String.matchAll alone for ESLevel >= 2020" do
to_js_2020( 'str.matchAll(pattern).forEach {|match| console.log match}' ).
must_equal 'str.matchAll(pattern).forEach(match => console.log(match))'
end
end
describe "with filter functions" do
it "should convert with filter functions first" do
to_js_fn1( 'str.matchAll(pattern).each {|match| puts match}' ).
must_equal 'var match; ' +
'while (match = pattern.exec(str)) {console.log(match)}'
end
it "should convert with filter functions second" do
to_js_fn2( 'str.matchAll(pattern).each {|match| puts match}' ).
must_equal 'var match; ' +
'while (match = pattern.exec(str)) {console.log(match)}'
end
end
describe Ruby2JS::Filter::DEFAULTS do
it "should include MatchAll" do
_(Ruby2JS::Filter::DEFAULTS).must_include Ruby2JS::Filter::MatchAll
end
end
end