opal 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +40 -9
- data/CHANGELOG.md +349 -0
- data/Gemfile +7 -8
- data/README.md +25 -3
- data/Rakefile +4 -2
- data/bin/opal +1 -1
- data/examples/rack/Gemfile +3 -0
- data/examples/rack/app/application.rb +13 -0
- data/examples/rack/app/user.rb +21 -0
- data/examples/rack/config.ru +7 -0
- data/examples/rack/index.html.erb +10 -0
- data/examples/sinatra/Gemfile +4 -0
- data/examples/sinatra/app/application.rb +7 -0
- data/examples/sinatra/config.ru +21 -0
- data/lib/mspec/opal/rake_task.rb +29 -8
- data/lib/mspec/opal/runner.rb +5 -4
- data/lib/opal.rb +1 -0
- data/lib/opal/builder.rb +0 -28
- data/lib/opal/cli.rb +0 -14
- data/lib/opal/compiler.rb +12 -11
- data/lib/opal/fragment.rb +8 -1
- data/lib/opal/nodes/array.rb +1 -1
- data/lib/opal/nodes/base.rb +4 -0
- data/lib/opal/nodes/call.rb +6 -2
- data/lib/opal/nodes/call_special.rb +1 -1
- data/lib/opal/nodes/class.rb +2 -2
- data/lib/opal/nodes/constants.rb +3 -1
- data/lib/opal/nodes/helpers.rb +23 -14
- data/lib/opal/nodes/if.rb +16 -9
- data/lib/opal/nodes/literal.rb +37 -5
- data/lib/opal/nodes/logic.rb +7 -1
- data/lib/opal/nodes/module.rb +2 -2
- data/lib/opal/nodes/scope.rb +13 -2
- data/lib/opal/nodes/top.rb +9 -0
- data/lib/opal/nodes/variables.rb +5 -2
- data/lib/opal/parser.rb +306 -71
- data/lib/opal/parser/grammar.rb +2667 -2775
- data/lib/opal/parser/grammar.y +177 -233
- data/lib/opal/parser/lexer.rb +511 -427
- data/lib/opal/parser/sexp.rb +15 -3
- data/lib/opal/source_map.rb +8 -4
- data/lib/opal/sprockets.rb +4 -0
- data/lib/opal/sprockets/cache_key_fix.rb +17 -0
- data/lib/opal/sprockets/environment.rb +21 -0
- data/lib/opal/sprockets/erb.rb +30 -0
- data/lib/opal/sprockets/processor.rb +127 -0
- data/lib/opal/sprockets/server.rb +166 -0
- data/lib/opal/util.rb +29 -0
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +1 -1
- data/opal/corelib/array.rb +106 -187
- data/opal/corelib/array/inheritance.rb +113 -0
- data/opal/corelib/basic_object.rb +6 -2
- data/opal/corelib/boolean.rb +4 -0
- data/opal/corelib/class.rb +2 -0
- data/opal/corelib/complex.rb +3 -0
- data/opal/corelib/enumerable.rb +75 -8
- data/opal/corelib/enumerator.rb +2 -0
- data/opal/corelib/error.rb +23 -23
- data/opal/corelib/hash.rb +5 -5
- data/opal/corelib/helpers.rb +51 -16
- data/opal/corelib/io.rb +7 -24
- data/opal/corelib/kernel.rb +23 -11
- data/opal/corelib/module.rb +44 -47
- data/opal/corelib/nil_class.rb +4 -0
- data/opal/corelib/numeric.rb +101 -15
- data/opal/corelib/range.rb +2 -0
- data/opal/corelib/rational.rb +3 -0
- data/opal/corelib/regexp.rb +36 -17
- data/opal/corelib/runtime.js +22 -7
- data/opal/corelib/string.rb +213 -110
- data/opal/corelib/string/inheritance.rb +78 -0
- data/opal/corelib/struct.rb +8 -0
- data/opal/corelib/time.rb +54 -42
- data/opal/corelib/variables.rb +24 -0
- data/opal/opal.rb +5 -27
- data/spec/cli/compiler_spec.rb +136 -0
- data/spec/cli/dependency_resolver_spec.rb +40 -0
- data/spec/cli/lexer_spec.rb +110 -0
- data/spec/cli/parser/alias_spec.rb +26 -0
- data/spec/cli/parser/and_spec.rb +13 -0
- data/spec/cli/parser/attrasgn_spec.rb +28 -0
- data/spec/cli/parser/begin_spec.rb +42 -0
- data/spec/cli/parser/block_spec.rb +12 -0
- data/spec/cli/parser/break_spec.rb +17 -0
- data/spec/cli/parser/call_spec.rb +139 -0
- data/spec/cli/parser/class_spec.rb +35 -0
- data/spec/cli/parser/comments_spec.rb +11 -0
- data/spec/cli/parser/def_spec.rb +61 -0
- data/spec/cli/parser/if_spec.rb +26 -0
- data/spec/cli/parser/iter_spec.rb +59 -0
- data/spec/cli/parser/lambda_spec.rb +64 -0
- data/spec/cli/parser/literal_spec.rb +113 -0
- data/spec/cli/parser/masgn_spec.rb +37 -0
- data/spec/cli/parser/module_spec.rb +27 -0
- data/spec/cli/parser/not_spec.rb +27 -0
- data/spec/cli/parser/op_asgn1_spec.rb +23 -0
- data/spec/cli/parser/op_asgn2_spec.rb +23 -0
- data/spec/cli/parser/or_spec.rb +13 -0
- data/spec/cli/parser/return_spec.rb +17 -0
- data/spec/cli/parser/sclass_spec.rb +21 -0
- data/spec/cli/parser/string_spec.rb +269 -0
- data/spec/cli/parser/super_spec.rb +20 -0
- data/spec/cli/parser/undef_spec.rb +15 -0
- data/spec/cli/parser/unless_spec.rb +13 -0
- data/spec/cli/parser/variables_spec.rb +92 -0
- data/spec/cli/parser/while_spec.rb +15 -0
- data/spec/cli/parser/yield_spec.rb +20 -0
- data/spec/cli/spec_helper.rb +31 -11
- data/spec/opal/core/array/set_range_to_array_spec.rb +7 -0
- data/spec/opal/core/date_spec.rb +122 -0
- data/spec/opal/core/language/predefined_spec.rb +1 -1
- data/spec/opal/core/runtime/operator_call_spec.rb +13 -0
- data/spec/opal/core/runtime/truthy_spec.rb +23 -0
- data/spec/opal/filters/bugs/array.rb +96 -87
- data/spec/opal/filters/bugs/basic_object.rb +9 -0
- data/spec/opal/filters/bugs/class.rb +16 -0
- data/spec/opal/filters/bugs/enumerable.rb +54 -0
- data/spec/opal/filters/bugs/language.rb +37 -3
- data/spec/opal/filters/bugs/math.rb +93 -0
- data/spec/opal/filters/bugs/nil.rb +7 -0
- data/spec/opal/filters/bugs/numeric.rb +19 -0
- data/spec/opal/filters/bugs/opal.rb +12 -0
- data/spec/opal/filters/bugs/regexp.rb +0 -2
- data/spec/opal/filters/bugs/string.rb +317 -19
- data/spec/opal/filters/bugs/struct.rb +29 -0
- data/spec/opal/filters/bugs/time.rb +130 -9
- data/spec/opal/filters/unsupported/encoding.rb +52 -4
- data/spec/opal/filters/unsupported/enumerator.rb +0 -3
- data/spec/opal/filters/unsupported/integer_size.rb +7 -0
- data/spec/opal/filters/unsupported/method_added.rb +10 -0
- data/spec/opal/filters/unsupported/mutable_strings.rb +299 -1
- data/spec/opal/filters/unsupported/private_constants.rb +30 -0
- data/spec/opal/filters/unsupported/private_methods.rb +16 -0
- data/spec/opal/filters/unsupported/random.rb +4 -0
- data/spec/opal/filters/unsupported/tainted.rb +53 -0
- data/spec/opal/filters/unsupported/trusted.rb +5 -0
- data/spec/opal/rubyspecs +167 -234
- data/spec/opal/spec_helper.rb +3 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +35 -0
- data/spec/opal/stdlib/promise/then_spec.rb +54 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +35 -0
- data/spec/opal/stdlib/promise/value_spec.rb +15 -0
- data/spec/opal/stdlib/promise/when_spec.rb +34 -0
- data/stdlib/base64.rb +152 -0
- data/stdlib/date.rb +82 -49
- data/{opal/corelib → stdlib}/encoding.rb +3 -1
- data/stdlib/erb.rb +0 -1
- data/stdlib/json.rb +10 -26
- data/stdlib/math.rb +370 -0
- data/stdlib/native.rb +40 -33
- data/stdlib/opal-parser.rb +7 -4
- data/stdlib/promise.rb +292 -0
- data/stdlib/strscan.rb +1 -1
- data/stdlib/template.rb +1 -3
- data/stdlib/time.rb +9 -0
- metadata +143 -204
- data/doc/compiler.md +0 -42
- data/doc/compiler_options.md +0 -5
- data/doc/examples/node_http_server.rb +0 -49
- data/doc/external_libraries.md +0 -9
- data/doc/generated_javascript.md +0 -272
- data/doc/home.md +0 -17
- data/doc/method_missing.md +0 -58
- data/doc/static_applications.md +0 -60
- data/doc/using_ruby_from_javascript.md +0 -18
- data/doc/using_sprockets.md +0 -65
- data/spec/opal/core/numeric/abs_spec.rb +0 -12
- data/spec/opal/core/numeric/downto_spec.rb +0 -19
- data/spec/opal/core/numeric/equal_value_spec.rb +0 -9
- data/spec/opal/core/numeric/even_spec.rb +0 -21
- data/spec/opal/core/numeric/magnitude_spec.rb +0 -12
- data/spec/opal/core/numeric/odd_spec.rb +0 -21
- data/spec/opal/core/string/chop_spec.rb +0 -10
- data/spec/opal/core/string/chr_spec.rb +0 -13
- data/spec/opal/core/string/clone_spec.rb +0 -8
- data/spec/opal/core/string/comparison_spec.rb +0 -13
- data/spec/opal/core/string/dup_spec.rb +0 -8
- data/spec/opal/core/string/element_reference_spec.rb +0 -96
- data/spec/opal/core/string/fixtures/classes.rb +0 -49
- data/spec/opal/core/string/format_spec.rb +0 -9
- data/spec/opal/core/string/freeze_spec.rb +0 -15
- data/spec/opal/core/string/gsub_spec.rb +0 -31
- data/spec/opal/core/string/lines_spec.rb +0 -9
- data/spec/opal/core/string/ljust_spec.rb +0 -32
- data/spec/opal/core/string/lstrip_spec.rb +0 -7
- data/spec/opal/core/string/match_spec.rb +0 -49
- data/spec/opal/core/string/next_spec.rb +0 -10
- data/spec/opal/core/string/ord_spec.rb +0 -9
- data/spec/opal/core/string/partition_spec.rb +0 -10
- data/spec/opal/core/string/rindex_spec.rb +0 -50
- data/spec/opal/core/string/rjust_spec.rb +0 -32
- data/spec/opal/core/string/rstrip_spec.rb +0 -7
- data/spec/opal/core/string/scan_spec.rb +0 -66
- data/spec/opal/core/string/slice_spec.rb +0 -74
- data/spec/opal/core/string/split_spec.rb +0 -5
- data/spec/opal/core/string/strip_spec.rb +0 -6
- data/spec/opal/core/string/sub_spec.rb +0 -38
- data/spec/opal/core/string/succ_spec.rb +0 -10
- data/spec/opal/core/string/sum_spec.rb +0 -5
- data/spec/opal/core/string/to_f_spec.rb +0 -14
- data/spec/opal/core/string/to_i_spec.rb +0 -25
- data/spec/opal/core/string/tr_s_spec.rb +0 -31
- data/spec/opal/core/string/tr_spec.rb +0 -31
- data/spec/opal/filters/bugs/parser.rb +0 -10
- data/spec/opal/filters/unsupported/immutable_strings.rb +0 -24
- data/spec/opal/filters/unsupported/string_subclasses.rb +0 -8
- data/spec/opal/parser/alias_spec.rb +0 -26
- data/spec/opal/parser/and_spec.rb +0 -13
- data/spec/opal/parser/array_spec.rb +0 -22
- data/spec/opal/parser/attrasgn_spec.rb +0 -28
- data/spec/opal/parser/begin_spec.rb +0 -42
- data/spec/opal/parser/block_spec.rb +0 -12
- data/spec/opal/parser/break_spec.rb +0 -17
- data/spec/opal/parser/call_spec.rb +0 -131
- data/spec/opal/parser/class_spec.rb +0 -35
- data/spec/opal/parser/const_spec.rb +0 -13
- data/spec/opal/parser/cvar_spec.rb +0 -11
- data/spec/opal/parser/def_spec.rb +0 -61
- data/spec/opal/parser/false_spec.rb +0 -17
- data/spec/opal/parser/file_spec.rb +0 -7
- data/spec/opal/parser/gvar_spec.rb +0 -13
- data/spec/opal/parser/hash_spec.rb +0 -17
- data/spec/opal/parser/heredoc_spec.rb +0 -30
- data/spec/opal/parser/iasgn_spec.rb +0 -9
- data/spec/opal/parser/if_spec.rb +0 -26
- data/spec/opal/parser/int_spec.rb +0 -13
- data/spec/opal/parser/iter_spec.rb +0 -59
- data/spec/opal/parser/ivar_spec.rb +0 -9
- data/spec/opal/parser/lambda_spec.rb +0 -64
- data/spec/opal/parser/lasgn_spec.rb +0 -8
- data/spec/opal/parser/line_spec.rb +0 -8
- data/spec/opal/parser/lvar_spec.rb +0 -38
- data/spec/opal/parser/masgn_spec.rb +0 -37
- data/spec/opal/parser/module_spec.rb +0 -27
- data/spec/opal/parser/nil_spec.rb +0 -17
- data/spec/opal/parser/not_spec.rb +0 -27
- data/spec/opal/parser/nth_ref_spec.rb +0 -13
- data/spec/opal/parser/op_asgn1_spec.rb +0 -23
- data/spec/opal/parser/op_asgn2_spec.rb +0 -23
- data/spec/opal/parser/or_spec.rb +0 -13
- data/spec/opal/parser/parse_spec.rb +0 -66
- data/spec/opal/parser/regexp_spec.rb +0 -16
- data/spec/opal/parser/return_spec.rb +0 -17
- data/spec/opal/parser/sclass_spec.rb +0 -21
- data/spec/opal/parser/self_spec.rb +0 -17
- data/spec/opal/parser/str_spec.rb +0 -107
- data/spec/opal/parser/string_spec.rb +0 -8
- data/spec/opal/parser/super_spec.rb +0 -20
- data/spec/opal/parser/true_spec.rb +0 -17
- data/spec/opal/parser/undef_spec.rb +0 -15
- data/spec/opal/parser/unless_spec.rb +0 -13
- data/spec/opal/parser/while_spec.rb +0 -15
- data/spec/opal/parser/xstr_spec.rb +0 -116
- data/spec/opal/parser/yield_spec.rb +0 -20
@@ -1,38 +0,0 @@
|
|
1
|
-
describe "String#sub with pattern, replacement" do
|
2
|
-
it "returns a copy of self with all occurrences of pattern replaced with replacement" do
|
3
|
-
"hello".sub(/[aeiou]/, '*').should == "h*llo"
|
4
|
-
"hello".sub(//, ".").should == ".hello"
|
5
|
-
end
|
6
|
-
|
7
|
-
it "ignores a block if supplied" do
|
8
|
-
"food".sub(/f/, "g") { "w" }.should == "good"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "supports /i for ignoring case" do
|
12
|
-
"Hello".sub(/h/i, "j").should == "jello"
|
13
|
-
"hello".sub(/H/i, "j").should == "jello"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "converts and supports back references in replacement string" do
|
17
|
-
"javascript".sub(/(j).*(s).*/, '.\\1\\2').should == '.js'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "String#sub with pattern and block" do
|
22
|
-
it "returns a copy of self with the first occurences of pattern replaces with block's return value" do
|
23
|
-
"hi".sub(/./) { |s| s + ' ' }.should == "h i"
|
24
|
-
"hi!".sub(/(.)(.)/) { |*a| a.inspect }.should == '["hi"]!'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should set the global match variable $~ inside block" do
|
28
|
-
match_datas = []
|
29
|
-
"hello".sub(/(.)./) { match_datas << $~; $~[1].succ }.should == "illo"
|
30
|
-
match_datas.length.should == 1
|
31
|
-
match_datas[0].length.should == 2
|
32
|
-
match_datas[0].should == ["he", "h"]
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should set the global match variable $& inside block" do
|
36
|
-
"hello".sub(/./) { "#{$&} " }.should == "h ello"
|
37
|
-
end
|
38
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
describe "String#succ" do
|
2
|
-
it "returns an empty string for empty strings" do
|
3
|
-
"".succ.should == ""
|
4
|
-
end
|
5
|
-
|
6
|
-
it "returns the successor by increasing the rightmost alphanumeric" do
|
7
|
-
"abcd".succ.should == "abce"
|
8
|
-
"THX1138".succ.should == "THX1139"
|
9
|
-
end
|
10
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
describe "String#to_f" do
|
2
|
-
it "treats leading characters of self as a floating point number" do
|
3
|
-
"45.67 degress".to_f.should == 45.67
|
4
|
-
"0".to_f.should == 0.0
|
5
|
-
|
6
|
-
".5".to_f.should == 0.5
|
7
|
-
"5e".to_f.should == 5.0
|
8
|
-
"5E".to_f.should == 5.0
|
9
|
-
end
|
10
|
-
|
11
|
-
it "treats special float value strings as characters" do
|
12
|
-
"NaN".to_f.should == 0
|
13
|
-
end
|
14
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
describe "String#to_i" do
|
2
|
-
it "returns 0 for strings with leading underscores" do
|
3
|
-
"_123".to_i.should == 0
|
4
|
-
end
|
5
|
-
|
6
|
-
it "ignores subsequent invalid characters" do
|
7
|
-
"123asdf".to_i.should == 123
|
8
|
-
"123#123".to_i.should == 123
|
9
|
-
"123 456".to_i.should == 123
|
10
|
-
end
|
11
|
-
|
12
|
-
it "interprets leading characters as a number in the given base" do
|
13
|
-
"10110010010".to_i(2).should == 1426
|
14
|
-
"100110201001".to_i(3).should == 186409
|
15
|
-
"103110201001".to_i(4).should == 5064769
|
16
|
-
"103110241001".to_i(5).should == 55165126
|
17
|
-
"153110241001".to_i(6).should == 697341529
|
18
|
-
"153160241001".to_i(7).should == 3521513430
|
19
|
-
"153160241701".to_i(8).should == 14390739905
|
20
|
-
"853160241701".to_i(9).should == 269716550518
|
21
|
-
"853160241791".to_i(10).should == 853160241791
|
22
|
-
|
23
|
-
"5e10".to_i.should == 5
|
24
|
-
end
|
25
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
describe "String#tr_s" do
|
2
|
-
it "replaces occurrences of character with substitute, dropping repeating substitutes" do
|
3
|
-
# identity checks (no substitution)
|
4
|
-
'abc'.tr_s('', 'a').should == 'abc'
|
5
|
-
'aabbcc'.tr_s('', 'a').should == 'aabbcc'
|
6
|
-
|
7
|
-
# single char substitutions
|
8
|
-
'a'.tr_s('a', 'b').should == 'b'
|
9
|
-
'aa'.tr_s('a', 'b').should == 'b'
|
10
|
-
'bbabcbb'.tr_s('b', 'z').should == 'zazcz'
|
11
|
-
'hello'.tr_s('l', 'r').should == 'hero'
|
12
|
-
|
13
|
-
# multiple char substitutions
|
14
|
-
'aabbcc'.tr_s('abc', 'abc').should == 'abc'
|
15
|
-
'hello'.tr_s('el', '*').should == 'h*o'
|
16
|
-
'hello'.tr_s('el', 'hx').should == 'hhxo'
|
17
|
-
|
18
|
-
# inverted substitutions
|
19
|
-
'hello'.tr_s('^aeiou', '*').should == '*e*o'
|
20
|
-
|
21
|
-
# range substitutions
|
22
|
-
'abc'.tr_s('a-c', '*').should == '*'
|
23
|
-
'hello'.tr_s('e-lo', 'rb').should == 'brb'
|
24
|
-
'hello'.tr_s('a-y', 'b-z').should == 'ifmp'
|
25
|
-
|
26
|
-
# truncation
|
27
|
-
'abcd'.tr_s('a', '').should == 'bcd'
|
28
|
-
'abcd'.tr_s('abc', '').should == 'd'
|
29
|
-
'abcd'.tr_s('b-d', '').should == 'a'
|
30
|
-
end
|
31
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
describe "String#tr" do
|
2
|
-
it "replaces occurances of character with substitute" do
|
3
|
-
# identity checks (no substitution)
|
4
|
-
'abc'.tr('', 'z').should == 'abc'
|
5
|
-
'abc'.tr('a', 'a').should == 'abc'
|
6
|
-
'abc'.tr('a', 'az').should == 'abc'
|
7
|
-
|
8
|
-
# single char substitutions
|
9
|
-
'a'.tr('a', 'b').should == 'b'
|
10
|
-
'aa'.tr('a', 'b').should == 'bb'
|
11
|
-
'abc'.tr('b', 'z').should == 'azc'
|
12
|
-
'hello'.tr('e', 'ip').should == 'hillo'
|
13
|
-
|
14
|
-
# multiple char substitutions
|
15
|
-
'hello'.tr('el', 'ip').should == 'hippo'
|
16
|
-
'hello'.tr('aeiou', '*').should == 'h*ll*'
|
17
|
-
|
18
|
-
# inverted substitutions
|
19
|
-
'hello'.tr('^aeiou', '*').should == '*e**o'
|
20
|
-
|
21
|
-
# range substitutions
|
22
|
-
'abc'.tr('a-c', '*').should == '***'
|
23
|
-
'hello'.tr('e-lo', 'ab').should == 'babbb'
|
24
|
-
'hello'.tr('a-y', 'b-z').should == 'ifmmp'
|
25
|
-
|
26
|
-
# truncation
|
27
|
-
'abcd'.tr('a', '').should == 'bcd'
|
28
|
-
'abcd'.tr('abc', '').should == 'd'
|
29
|
-
'abcd'.tr('b-d', '').should == 'a'
|
30
|
-
end
|
31
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
opal_filter "Opal::Parser" do
|
2
|
-
fails "Singleton classes returns an empty s(:scope) when given an empty body"
|
3
|
-
fails "Singleton classes should accept any expressions for singleton part"
|
4
|
-
fails "Strings from %Q construction should match '{' and '}' pairs used to start string before ending match"
|
5
|
-
fails "Strings from %Q construction should match '(' and ')' pairs used to start string before ending match"
|
6
|
-
fails "Strings from %Q construction should match '[' and ']' pairs used to start string before ending match"
|
7
|
-
fails "x-strings created using %x notation should match '{' and '}' pairs used to start string before ending match"
|
8
|
-
fails "x-strings created using %x notation should match '(' and ')' pairs used to start string before ending match"
|
9
|
-
fails "x-strings created using %x notation should match '[' and ']' pairs used to start string before ending match"
|
10
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
opal_filter "immutable strings" do
|
2
|
-
fails "Array#fill does not replicate the filler"
|
3
|
-
|
4
|
-
fails "Hash literal freezes string keys on initialization"
|
5
|
-
|
6
|
-
fails "Time#strftime formats time according to the directives in the given format string"
|
7
|
-
fails "Time#strftime with %z formats a local time with positive UTC offset as '+HHMM'"
|
8
|
-
fails "Time#strftime with %z formats a local time with negative UTC offset as '-HHMM'"
|
9
|
-
|
10
|
-
fails "String#chomp when passed no argument returns a copy of the String when it is not modified"
|
11
|
-
|
12
|
-
fails "String#chop returns a new string when applied to an empty string"
|
13
|
-
|
14
|
-
fails "String#chop! removes the final character"
|
15
|
-
fails "String#chop! removes the final carriage return"
|
16
|
-
fails "String#chop! removes the final newline"
|
17
|
-
fails "String#chop! removes the final carriage return, newline"
|
18
|
-
fails "String#chop! removes the carrige return, newline if they are the only characters"
|
19
|
-
fails "String#chop! does not remove more than the final carriage return, newline"
|
20
|
-
fails "String#chop! returns self if modifications were made"
|
21
|
-
fails "String#chop! returns nil when called on an empty string"
|
22
|
-
fails "String#chop! raises a RuntimeError on a frozen instance that is modified"
|
23
|
-
fails "String#chop! raises a RuntimeError on a frozen instance that would not be modified"
|
24
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
opal_filter "String subclasses" do
|
2
|
-
fails "String#upcase returns a subclass instance for subclasses"
|
3
|
-
fails "String#swapcase returns subclass instances when called on a subclass"
|
4
|
-
fails "String#downcase returns a subclass instance for subclasses"
|
5
|
-
fails "String#capitalize returns subclass instances when called on a subclass"
|
6
|
-
fails "String#center with length, padding returns subclass instances when called on subclasses"
|
7
|
-
fails "String#chomp when passed no argument returns subclass instances when called on a subclass"
|
8
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "The alias keyword" do
|
4
|
-
describe "with fitem" do
|
5
|
-
it "should return an s(:alias) with s(:sym)" do
|
6
|
-
opal_parse("alias a b").should == [:alias, [:sym, :a], [:sym, :b]]
|
7
|
-
opal_parse("alias == equals").should == [:alias, [:sym, :==], [:sym, :equals]]
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should accept symbols as names" do
|
11
|
-
opal_parse("alias :foo :bar").should == [:alias, [:sym, :foo], [:sym, :bar]]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "with gvar" do
|
16
|
-
it "should return a s(:valias) with two gvars as arguments" do
|
17
|
-
opal_parse("alias $foo $bar").should == [:valias, :$foo, :$bar]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "with gvar and nth ref" do
|
22
|
-
it "should return a s(:valias) with two values as arguments" do
|
23
|
-
opal_parse("alias $foo $1").should == [:valias, :$foo, :"1"]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "The and statement" do
|
4
|
-
it "should always return s(:and)" do
|
5
|
-
opal_parse("1 and 2").should == [:and, [:int, 1], [:int, 2]]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "The && expression" do
|
10
|
-
it "should always return s(:and)" do
|
11
|
-
opal_parse("1 && 2").should == [:and, [:int, 1], [:int, 2]]
|
12
|
-
end
|
13
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Arrays" do
|
4
|
-
it "should parse empty arrays as s(:array)" do
|
5
|
-
opal_parse("[]").should == [:array]
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should append regular args onto end of array sexp" do
|
9
|
-
opal_parse("[1]").should == [:array, [:int, 1]]
|
10
|
-
opal_parse("[1, 2]").should == [:array, [:int, 1], [:int, 2]]
|
11
|
-
opal_parse("[1, 2, 3]").should == [:array, [:int, 1], [:int, 2], [:int, 3]]
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should return a single item s(:array) with given splat if no norm args" do
|
15
|
-
opal_parse("[*1]").should == [:array, [:splat, [:int, 1]]]
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should allow splats combined with any number of norm args" do
|
19
|
-
opal_parse("[1, *2]").should == [:array, [:int, 1], [:splat, [:int, 2]]]
|
20
|
-
opal_parse("[1, 2, *3]").should == [:array, [:int, 1], [:int, 2], [:splat, [:int, 3]]]
|
21
|
-
end
|
22
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Attribute assignments" do
|
4
|
-
it "should return a s(:attrasgn) for simple assignments" do
|
5
|
-
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
|
6
|
-
opal_parse('bar.foo = 1').should == [:attrasgn, [:call, nil, :bar, [:arglist]], :foo=, [:arglist, [:int, 1]]]
|
7
|
-
opal_parse('@bar.foo = 1').should == [:attrasgn, [:ivar, :@bar], :foo=, [:arglist, [:int, 1]]]
|
8
|
-
end
|
9
|
-
|
10
|
-
it "accepts both '.' and '::' for method call operators" do
|
11
|
-
opal_parse('self.foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
|
12
|
-
opal_parse('self::foo = 1').should == [:attrasgn, [:self], :foo=, [:arglist, [:int, 1]]]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "can accept a constant as assignable name when using '.'" do
|
16
|
-
opal_parse('self.FOO = 1').should == [:attrasgn, [:self], :FOO=, [:arglist, [:int, 1]]]
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "when setting element reference" do
|
20
|
-
it "uses []= as the method call" do
|
21
|
-
opal_parse('self[1] = 2').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2]]]
|
22
|
-
end
|
23
|
-
|
24
|
-
it "supports multiple arguments inside brackets" do
|
25
|
-
opal_parse('self[1, 2] = 3').should == [:attrasgn, [:self], :[]=, [:arglist, [:int, 1], [:int, 2], [:int, 3]]]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "The begin keyword" do
|
4
|
-
it "should be removed when used without a resuce or enusre body" do
|
5
|
-
opal_parse('begin; 1; end').should == [:int, 1]
|
6
|
-
opal_parse('begin; 1; 2; end').should == [:block, [:int, 1], [:int, 2]]
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "with 'rescue' bodies" do
|
10
|
-
it "should create a s(:rescue) sexp" do
|
11
|
-
opal_parse('begin; 1; rescue; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
|
12
|
-
end
|
13
|
-
|
14
|
-
it "allows multiple rescue bodies" do
|
15
|
-
opal_parse('begin 1; rescue; 2; rescue; 3; end').should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]], [:resbody, [:array], [:int, 3]]]
|
16
|
-
end
|
17
|
-
|
18
|
-
it "accepts a list of classes used to match against the exception" do
|
19
|
-
opal_parse('begin 1; rescue Klass; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass]], [:int, 2]]]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "accepts an identifier to assign exception to" do
|
23
|
-
opal_parse('begin 1; rescue => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
|
24
|
-
opal_parse('begin 1; rescue Klass => a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:lasgn, :a, [:gvar, :$!]]], [:int, 2]]]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "accepts an ivar to assign exception to" do
|
28
|
-
opal_parse('begin 1; rescue => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
|
29
|
-
opal_parse('begin 1; rescue Klass => @a; 2; end').should == [:rescue, [:int, 1], [:resbody, [:array, [:const, :Klass],[:iasgn, :@a, [:gvar, :$!]]], [:int, 2]]]
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should parse newline right after rescue" do
|
33
|
-
opal_parse("begin; 1; rescue\n 2; end").should == [:rescue, [:int, 1], [:resbody, [:array], [:int, 2]]]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "with an 'ensure' block" do
|
38
|
-
it "should propagate into single s(:ensure) statement when no rescue block given" do
|
39
|
-
opal_parse('begin; 1; ensure; 2; end').should == [:ensure, [:int, 1], [:int, 2]]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Block statements" do
|
4
|
-
it "should return the direct expression if only one expresssion in block" do
|
5
|
-
opal_parse("42").should == [:int, 42]
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return an s(:block) with all expressions appended for > 1 expression" do
|
9
|
-
opal_parse("42; 43").should == [:block, [:int, 42], [:int, 43]]
|
10
|
-
opal_parse("42; 43\n44").should == [:block, [:int, 42], [:int, 43], [:int, 44]]
|
11
|
-
end
|
12
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "The break keyword" do
|
4
|
-
it "should return s(:break) when given no args" do
|
5
|
-
opal_parse("break").should == [:break]
|
6
|
-
end
|
7
|
-
|
8
|
-
it "returns s(:break) with a single arg not wrapped in s(:array)" do
|
9
|
-
opal_parse("break 1").should == [:break, [:int, 1]]
|
10
|
-
opal_parse("break *1").should == [:break, [:splat, [:int, 1]]]
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns s(:break) with an s(:array) for args size > 1" do
|
14
|
-
opal_parse("break 1, 2").should == [:break, [:array, [:int, 1], [:int, 2]]]
|
15
|
-
opal_parse("break 1, *2").should == [:break, [:array, [:int, 1], [:splat, [:int, 2]]]]
|
16
|
-
end
|
17
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Method calls" do
|
4
|
-
it "should use 'nil' for calls without a receiver" do
|
5
|
-
opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
|
6
|
-
opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should always have an arglist when not passed any arguments" do
|
10
|
-
opal_parse("foo").should == [:call, nil, :foo, [:arglist]]
|
11
|
-
opal_parse("self.foo").should == [:call, [:self], :foo, [:arglist]]
|
12
|
-
opal_parse("foo()").should == [:call, nil, :foo, [:arglist]]
|
13
|
-
opal_parse("self.foo()").should == [:call, [:self], :foo, [:arglist]]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "appends all arguments onto arglist" do
|
17
|
-
opal_parse("foo 1").should == [:call, nil, :foo, [:arglist, [:int, 1]]]
|
18
|
-
opal_parse("foo 1, 2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:int, 2]]]
|
19
|
-
opal_parse("foo 1, *2").should == [:call, nil, :foo, [:arglist, [:int, 1], [:splat, [:int, 2]]]]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "supports leading dots on newline" do
|
23
|
-
opal_parse("foo\n.bar").should == [:call, [:call, nil, :foo, [:arglist]], :bar, [:arglist]]
|
24
|
-
lambda { opal_parse("foo\n..bar") }.should raise_error(Exception)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "Operator calls" do
|
29
|
-
it "should parse all other operators into method calls" do
|
30
|
-
opal_parse("1 % 2").should == [:call, [:int, 1], :%, [:arglist, [:int, 2]]]
|
31
|
-
opal_parse("1 ** 2").should == [:call, [:int, 1], :**, [:arglist, [:int, 2]]]
|
32
|
-
|
33
|
-
opal_parse("+self").should == [:call, [:self], :+@, [:arglist]]
|
34
|
-
opal_parse("-self").should == [:call, [:self], :-@, [:arglist]]
|
35
|
-
|
36
|
-
opal_parse("1 | 2").should == [:call, [:int, 1], :|, [:arglist, [:int, 2]]]
|
37
|
-
opal_parse("1 ^ 2").should == [:call, [:int, 1], :^, [:arglist, [:int, 2]]]
|
38
|
-
opal_parse("1 & 2").should == [:call, [:int, 1], :&, [:arglist, [:int, 2]]]
|
39
|
-
opal_parse("1 <=> 2").should == [:call, [:int, 1], :<=>, [:arglist, [:int, 2]]]
|
40
|
-
|
41
|
-
opal_parse("1 < 2").should == [:call, [:int, 1], :<, [:arglist, [:int, 2]]]
|
42
|
-
opal_parse("1 <= 2").should == [:call, [:int, 1], :<=, [:arglist, [:int, 2]]]
|
43
|
-
opal_parse("1 > 2").should == [:call, [:int, 1], :>, [:arglist, [:int, 2]]]
|
44
|
-
opal_parse("1 >= 2").should == [:call, [:int, 1], :>=, [:arglist, [:int, 2]]]
|
45
|
-
|
46
|
-
opal_parse("1 == 2").should == [:call, [:int, 1], :==, [:arglist, [:int, 2]]]
|
47
|
-
opal_parse("1 === 2").should == [:call, [:int, 1], :===, [:arglist, [:int, 2]]]
|
48
|
-
opal_parse("1 =~ 2").should == [:call, [:int, 1], :=~, [:arglist, [:int, 2]]]
|
49
|
-
|
50
|
-
opal_parse("~1").should == [:call, [:int, 1], :~, [:arglist]]
|
51
|
-
opal_parse("1 << 2").should == [:call, [:int, 1], :<<, [:arglist, [:int, 2]]]
|
52
|
-
opal_parse("1 >> 2").should == [:call, [:int, 1], :>>, [:arglist, [:int, 2]]]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "optimizes +@ and -@ on numerics" do
|
56
|
-
opal_parse("+1").should == [:int, 1]
|
57
|
-
opal_parse("-1").should == [:int, -1]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "Optional paren calls" do
|
62
|
-
it "should correctly parse - and -@" do
|
63
|
-
opal_parse("x - 1").should == [:call, [:call, nil, :x, [:arglist]], :-, [:arglist, [:int, 1]]]
|
64
|
-
opal_parse("x -1").should == [:call, nil, :x, [:arglist, [:int, -1]]]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should correctly parse + and +@" do
|
68
|
-
opal_parse("x + 1").should == [:call, [:call, nil, :x, [:arglist]], :+, [:arglist, [:int, 1]]]
|
69
|
-
opal_parse("x +1").should == [:call, nil, :x, [:arglist, [:int, 1]]]
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should correctly parse / and regexps" do
|
73
|
-
opal_parse("x / 500").should == [:call, [:call, nil, :x, [:arglist]], :/, [:arglist, [:int, 500]]]
|
74
|
-
opal_parse("x /foo/").should == [:call, nil, :x, [:arglist, [:regexp, /foo/]]]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should parse LPAREN_ARG correctly" do
|
78
|
-
opal_parse("x (1).y").should == [:call, nil, :x, [:arglist, [:call, [:int, 1], :y, [:arglist]]]]
|
79
|
-
opal_parse("x(1).y").should == [:call, [:call, nil, :x, [:arglist, [:int, 1]]], :y, [:arglist]]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "Operator precedence" do
|
84
|
-
it "should be raised with parentheses" do
|
85
|
-
opal_parse("(1 + 2) + (3 - 4)").should == [:call,
|
86
|
-
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
|
87
|
-
:+,
|
88
|
-
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
|
89
|
-
]
|
90
|
-
opal_parse("(1 + 2) - (3 - 4)").should == [:call,
|
91
|
-
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
|
92
|
-
:-,
|
93
|
-
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
|
94
|
-
]
|
95
|
-
opal_parse("(1 + 2) * (3 - 4)").should == [:call,
|
96
|
-
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
|
97
|
-
:*,
|
98
|
-
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
|
99
|
-
]
|
100
|
-
opal_parse("(1 + 2) / (3 - 4)").should == [:call,
|
101
|
-
[:paren, [:call, [:int, 1], :+, [:arglist, [:int, 2]]]],
|
102
|
-
:/,
|
103
|
-
[:arglist, [:paren, [:call, [:int, 3], :-, [:arglist, [:int, 4]]]]],
|
104
|
-
]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "Calls with keywords as method names" do
|
109
|
-
|
110
|
-
keywords = %w[class module defined? def undef end do if unless else elsif self true false
|
111
|
-
nil __LINE__ __FILE__ begin rescue ensure case when or and not return next
|
112
|
-
redo break super then while until yield alias]
|
113
|
-
|
114
|
-
it "should correctly parse the keyword as a method name when after a '.'" do
|
115
|
-
keywords.each do |kw|
|
116
|
-
opal_parse("self.#{kw}").should == [:call, [:self], kw.to_sym, [:arglist]]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "Calls with operators as method names" do
|
122
|
-
operators = %w[+ - * / & ** | ^ & <=> > >= < <= << >>]
|
123
|
-
|
124
|
-
it "should correctly parse the operator as method name after '.'" do
|
125
|
-
operators.each do |op|
|
126
|
-
opal_parse("self.#{op}").should == [:call, [:self], op.to_sym, [:arglist]]
|
127
|
-
opal_parse("self.#{op}(1)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1]]]
|
128
|
-
opal_parse("self.#{op}(1, 2)").should == [:call, [:self], op.to_sym, [:arglist, [:int, 1], [:int, 2]]]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|