-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathes2019_spec.rb
49 lines (40 loc) · 1.18 KB
/
es2019_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
gem 'minitest'
require 'minitest/autorun'
describe "ES2019 support" do
def to_js( string)
_(Ruby2JS.convert(string, eslevel: 2019, filters: []).to_s)
end
def to_js_fn(string)
_(Ruby2JS.convert(string, eslevel: 2019,
filters: [Ruby2JS::Filter::Functions]).to_s)
end
describe :Exception do
it "should handle rescue without a variable" do
to_js( 'begin; boom(); rescue; end' ).
must_equal 'try {boom()} catch {}'
to_js( 'begin; boom(); rescue; console.log $!; end' ).
must_equal 'try {boom()} catch ($EXCEPTION) {console.log($EXCEPTION)}'
end
end
describe :Array do
it "should handle flatten" do
to_js_fn( 'a.flatten()' ).must_equal 'a.flat(Infinity)'
end
it "should handle to_h" do
to_js_fn( 'a.to_h' ).must_equal 'Object.fromEntries(a)'
end
end
describe :Hash do
it "should handle Hash[]" do
to_js_fn( 'Hash[a]' ).must_equal 'Object.fromEntries(a)'
end
end
describe :String do
it "should handle lstrip" do
to_js_fn( 'a.lstrip()' ).must_equal 'a.trimStart()'
end
it "should handle rstrip" do
to_js_fn( 'a.rstrip()' ).must_equal 'a.trimEnd()'
end
end
end