opal 0.3.27 → 0.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/CONTRIBUTING.md +24 -0
- data/README.md +6 -5
- data/Rakefile +12 -2
- data/core/array.rb +3 -31
- data/core/enumerable.rb +32 -4
- data/core/hash.rb +218 -186
- data/core/json.rb +3 -2
- data/core/kernel.rb +28 -28
- data/core/numeric.rb +2 -2
- data/core/runtime.js +0 -1
- data/lib/opal.rb +4 -2
- data/lib/opal/grammar.rb +6 -2
- data/lib/opal/grammar.y +3 -0
- data/lib/opal/lexer.rb +25 -10
- data/lib/opal/parser.rb +75 -34
- data/lib/opal/scope.rb +7 -7
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +1 -1
- data/spec/core/array/reduce_spec.rb +31 -0
- data/spec/{opal → core}/array/to_json_spec.rb +0 -0
- data/spec/core/boolean/and_spec.rb +17 -0
- data/spec/core/boolean/inspect_spec.rb +9 -0
- data/spec/core/boolean/or_spec.rb +17 -0
- data/spec/{opal → core}/boolean/singleton_class_spec.rb +0 -0
- data/spec/{opal → core}/boolean/to_json_spec.rb +1 -1
- data/spec/core/boolean/to_s_spec.rb +9 -0
- data/spec/core/boolean/xor_spec.rb +17 -0
- data/spec/{opal → core}/class/bridge_class_spec.rb +0 -0
- data/spec/{opal → core}/class/instance_methods_spec.rb +0 -0
- data/spec/core/class/last_value_spec.rb +68 -0
- data/spec/core/enumerable/detect_spec.rb +1 -1
- data/spec/core/enumerable/find_spec.rb +1 -1
- data/spec/{opal → core}/hash/to_json_spec.rb +0 -0
- data/spec/{opal → core}/hash/to_native_spec.rb +0 -0
- data/spec/{opal → core}/json/parse_spec.rb +0 -0
- data/spec/core/kernel/block_given.rb +30 -0
- data/spec/core/kernel/methods_spec.rb +11 -0
- data/spec/core/kernel/p_spec.rb +13 -0
- data/spec/{opal → core}/kernel/to_json_spec.rb +0 -0
- data/spec/{opal → core}/nil/to_json_spec.rb +0 -0
- data/spec/core/numeric/abs_spec.rb +12 -0
- data/spec/core/numeric/bit_and_spec.rb +7 -0
- data/spec/core/numeric/bit_or_spec.rb +8 -0
- data/spec/core/numeric/bit_xor_spec.rb +6 -0
- data/spec/core/numeric/ceil_spec.rb +8 -0
- data/spec/core/numeric/chr_spec.rb +8 -0
- data/spec/core/numeric/comparison_spec.rb +24 -0
- data/spec/core/numeric/complement_spec.rb +8 -0
- data/spec/core/numeric/divide_spec.rb +10 -0
- data/spec/core/numeric/downto_spec.rb +19 -0
- data/spec/core/numeric/eql_spec.rb +9 -0
- data/spec/core/numeric/even_spec.rb +21 -0
- data/spec/core/numeric/exponent_spec.rb +33 -0
- data/spec/core/numeric/floor_spec.rb +8 -0
- data/spec/core/numeric/gt_spec.rb +11 -0
- data/spec/core/numeric/gte_spec.rb +12 -0
- data/spec/core/numeric/integer_spec.rb +9 -0
- data/spec/core/numeric/left_shift_spec.rb +21 -0
- data/spec/core/numeric/lt_spec.rb +11 -0
- data/spec/core/numeric/lte_spec.rb +12 -0
- data/spec/core/numeric/magnitude_spec.rb +12 -0
- data/spec/core/numeric/minus_spec.rb +8 -0
- data/spec/core/numeric/modulo_spec.rb +19 -0
- data/spec/core/numeric/multiply_spec.rb +9 -0
- data/spec/core/numeric/next_spec.rb +9 -0
- data/spec/core/numeric/odd_spec.rb +21 -0
- data/spec/core/numeric/ord_spec.rb +9 -0
- data/spec/core/numeric/plus_spec.rb +8 -0
- data/spec/core/numeric/pred_spec.rb +7 -0
- data/spec/core/numeric/right_shift_spec.rb +25 -0
- data/spec/core/numeric/succ_spec.rb +9 -0
- data/spec/core/numeric/times_spec.rb +36 -0
- data/spec/core/numeric/to_f_spec.rb +7 -0
- data/spec/core/numeric/to_i_spec.rb +7 -0
- data/spec/{opal → core}/numeric/to_json_spec.rb +0 -0
- data/spec/core/numeric/to_s_spec.rb +8 -0
- data/spec/core/numeric/uminus_spec.rb +9 -0
- data/spec/core/numeric/upto_spec.rb +19 -0
- data/spec/core/numeric/zero_spec.rb +7 -0
- data/spec/{opal → core}/runtime/call_spec.rb +0 -0
- data/spec/{opal → core}/runtime/class_hierarchy_spec.rb +0 -0
- data/spec/{opal → core}/runtime/def_spec.rb +0 -0
- data/spec/{opal → core}/runtime/defined_spec.rb +0 -0
- data/spec/{opal → core}/runtime/super_spec.rb +0 -0
- data/spec/{opal → core}/string/demodulize_spec.rb +0 -0
- data/spec/{opal → core}/string/to_json_spec.rb +0 -0
- data/spec/{opal → core}/string/underscore_spec.rb +0 -0
- data/spec/{opal → core}/strscan/check_spec.rb +0 -0
- data/spec/{opal → core}/strscan/scan_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/alias_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/and_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/array_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/attrasgn_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/begin_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/block_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/break_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/call_spec.rb +23 -1
- data/spec/{lib/grammar → grammar}/class_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/const_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/cvar_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/def_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/false_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/file_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/gvar_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/hash_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/iasgn_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/if_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/iter_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/ivar_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/lambda_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/lasgn_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/line_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/lvar_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/masgn_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/module_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/nil_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/not_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/op_asgn1_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/op_asgn2_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/or_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/return_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/sclass_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/self_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/str_spec.rb +7 -0
- data/spec/{lib/grammar → grammar}/super_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/true_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/undef_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/unless_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/while_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/xstr_spec.rb +0 -0
- data/spec/{lib/grammar → grammar}/yield_spec.rb +0 -0
- data/spec/language/string_spec.rb +5 -0
- data/spec/{lib/parser → parser}/simple_spec.rb +0 -0
- metadata +231 -159
- data/spec/core/false/and_spec.rb +0 -9
- data/spec/core/false/inspect_spec.rb +0 -5
- data/spec/core/false/or_spec.rb +0 -9
- data/spec/core/false/to_s_spec.rb +0 -5
- data/spec/core/false/xor_spec.rb +0 -9
- data/spec/core/true/and_spec.rb +0 -9
- data/spec/core/true/inspect_spec.rb +0 -5
- data/spec/core/true/or_spec.rb +0 -9
- data/spec/core/true/to_s_spec.rb +0 -5
- data/spec/core/true/xor_spec.rb +0 -9
- data/spec/lib/erb_parser/simple.erb +0 -1
- data/spec/opal/kernel/attribute_spec.rb +0 -57
- data/spec/opal/runtime/method_missing_spec.rb +0 -17
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
describe "Numeric#downto [stop] when self and stop are Fixnums" do
|
|
2
|
+
it "does not yield when stop is greater than self" do
|
|
3
|
+
result = []
|
|
4
|
+
5.downto(6) { |x| result << x }
|
|
5
|
+
result.should == []
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "yields once when stop equals self" do
|
|
9
|
+
result = []
|
|
10
|
+
5.downto(5) { |x| result << x }
|
|
11
|
+
result.should == [5]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "yields while decreasing self until it is less than stop" do
|
|
15
|
+
result = []
|
|
16
|
+
5.downto(2) { |x| result << x }
|
|
17
|
+
result.should == [5, 4, 3, 2]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
describe "Numeric#even?" do
|
|
2
|
+
it "is true for zero" do
|
|
3
|
+
0.even?.should be_true
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "is true for even positive Fixnums" do
|
|
7
|
+
4.even?.should be_true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "is true for even negative Fixnums" do
|
|
11
|
+
(-4).even?.should be_true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "is false for odd positive Fixnums" do
|
|
15
|
+
5.even?.should be_false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "is false for odd negative Fixnums" do
|
|
19
|
+
(-5).even?.should be_false
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
describe "Numeric#**" do
|
|
2
|
+
it "returns self raised to the given power" do
|
|
3
|
+
(2 ** 0).should == 1
|
|
4
|
+
(2 ** 1).should == 2
|
|
5
|
+
(2 ** 2).should == 4
|
|
6
|
+
|
|
7
|
+
(2 ** 40).should == 1099511627776
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "overflows the answer to a bignum transparantly" do
|
|
11
|
+
(2 ** 29).should == 536870912
|
|
12
|
+
(2 ** 30).should == 1073741824
|
|
13
|
+
(2 ** 31).should == 2147483648
|
|
14
|
+
(2 ** 32).should == 4294967296
|
|
15
|
+
|
|
16
|
+
(2 ** 61).should == 2305843009213693952
|
|
17
|
+
(2 ** 62).should == 4611686018427387904
|
|
18
|
+
(2 ** 63).should == 9223372036854775808
|
|
19
|
+
(2 ** 64).should == 18446744073709551616
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "raises negative numbers to the given power" do
|
|
23
|
+
((-2) ** 29).should == -536870912
|
|
24
|
+
((-2) ** 30).should == 1073741824
|
|
25
|
+
((-2) ** 31).should == -2147483648
|
|
26
|
+
((-2) ** 32).should == 4294967296
|
|
27
|
+
|
|
28
|
+
((-2) ** 61).should == -2305843009213693952
|
|
29
|
+
((-2) ** 62).should == 4611686018427387904
|
|
30
|
+
((-2) ** 63).should == -9223372036854775808
|
|
31
|
+
((-2) ** 64).should == 18446744073709551616
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
describe "Numeric#>=" do
|
|
2
|
+
it "returns true if self is greater than or equal to the given argument" do
|
|
3
|
+
(13 >= 2).should == true
|
|
4
|
+
(-500 >= -600).should == true
|
|
5
|
+
|
|
6
|
+
(1 >= 5).should == false
|
|
7
|
+
(2 >= 2).should == true
|
|
8
|
+
(5 >= 5).should == true
|
|
9
|
+
|
|
10
|
+
(5 >= 4.999).should == true
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
describe "Numeric#<< with n << m" do
|
|
2
|
+
it "returns n shifted left m bits when n > 0, m > 0" do
|
|
3
|
+
(1 << 1).should == 2
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "returns n shifted left m bits when n < 0, m > 0" do
|
|
7
|
+
(-1 << 1).should == -2
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "returns 0 when n == 0" do
|
|
11
|
+
(0 << 1).should == 0
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "returns n when n > 0, m == 0" do
|
|
15
|
+
(1 << 0).should == 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "returns n when n < 0, m == 0" do
|
|
19
|
+
(-1 << 0).should == -1
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
describe "Numeric#<=" do
|
|
2
|
+
it "returns true if self is less than or equal to other" do
|
|
3
|
+
(2 <= 13).should == true
|
|
4
|
+
(-600 <= -500).should == true
|
|
5
|
+
|
|
6
|
+
(5 <= 1).should == false
|
|
7
|
+
(5 <= 5).should == true
|
|
8
|
+
(-2 <= -2).should == true
|
|
9
|
+
|
|
10
|
+
(5 <= 4.999).should == false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
describe "Numeric#magnitude" do
|
|
2
|
+
it "returns self's absolute value" do
|
|
3
|
+
(-100).magnitude.should == 100
|
|
4
|
+
(100).magnitude.should == 100
|
|
5
|
+
|
|
6
|
+
(-0).magnitude.should == 0
|
|
7
|
+
(0).magnitude.should == 0
|
|
8
|
+
|
|
9
|
+
(-42).magnitude.should == 42
|
|
10
|
+
(42).magnitude.should == 42
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
describe "Numeric#modulo" do
|
|
2
|
+
it "returns the modulus obtained from dividing self by the given argument" do
|
|
3
|
+
13.modulo(4).should == 1
|
|
4
|
+
4.modulo(13).should == 4
|
|
5
|
+
|
|
6
|
+
13.modulo(4.0).should == 1
|
|
7
|
+
4.modulo(13.0).should == 4
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "Numeric#%" do
|
|
12
|
+
it "returns the modulus obtained from dividing self by the given argument" do
|
|
13
|
+
(13 % 4).should == 1
|
|
14
|
+
(4 % 13).should == 4
|
|
15
|
+
|
|
16
|
+
(13 % 4.0).should == 1
|
|
17
|
+
(4 % 13.0).should == 4
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
describe "Numeric#odd?" do
|
|
2
|
+
it "is false for zero" do
|
|
3
|
+
0.odd?.should be_false
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "is false for even positive Fixnums" do
|
|
7
|
+
4.odd?.should be_false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "is false for even negative Fixnums" do
|
|
11
|
+
(-4).odd?.should be_false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "is true for odd positive Fixnums" do
|
|
15
|
+
5.odd?.should be_true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "is true for odd negative Fixnums" do
|
|
19
|
+
(-5).odd?.should be_true
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
describe "Numeric#>> with n >> m" do
|
|
2
|
+
it "returns n shifted right m bits when n > 0, m > 0" do
|
|
3
|
+
(2 >> 1).should == 1
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "returns n shifted right m bits when n < 0, m > 0" do
|
|
7
|
+
(-2 >> 1).should == -1
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "returns 0 when n == 0" do
|
|
11
|
+
(0 >> 1).should == 0
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "returns n when n > 0, m == 0" do
|
|
15
|
+
(1 >> 0).should == 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "returns n when n < 0, m == 0" do
|
|
19
|
+
(-1 >> 0).should == -1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)" do
|
|
23
|
+
(4 >> 3).should == 0
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
describe "Numeric#times" do
|
|
2
|
+
it "returns self" do
|
|
3
|
+
5.times {}.should == 5
|
|
4
|
+
9.times {}.should == 9
|
|
5
|
+
9.times { |n| n - 2 }.should == 9
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "yields each value from 0 to self - 1" do
|
|
9
|
+
a = []
|
|
10
|
+
9.times { |i| a << i }
|
|
11
|
+
(-2).times { |i| a << i }
|
|
12
|
+
a.should == [0, 1, 2, 3, 4, 5, 6, 7, 8]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "skips the current iteration when encountering 'next'" do
|
|
16
|
+
a = []
|
|
17
|
+
3.times do |i|
|
|
18
|
+
next if i == 1
|
|
19
|
+
a << i
|
|
20
|
+
end
|
|
21
|
+
a.should == [0, 2]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "skips all iterations when encountering 'break'" do
|
|
25
|
+
a = []
|
|
26
|
+
5.times do |i|
|
|
27
|
+
break if i == 3
|
|
28
|
+
a << i
|
|
29
|
+
end
|
|
30
|
+
a.should == [0, 1, 2]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "skips all iterations when encountering break with an argument and returns that argument" do
|
|
34
|
+
9.times { break 2 }.should == 2
|
|
35
|
+
end
|
|
36
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
describe "Numeric#upto [stop] when self and stop are Fixnums" do
|
|
2
|
+
it "does not yield when stop is less than self" do
|
|
3
|
+
result = []
|
|
4
|
+
5.upto(4) { |x| result << x }
|
|
5
|
+
result.should == []
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "yields once when stop equals self" do
|
|
9
|
+
result = []
|
|
10
|
+
5.upto(5) { |x| result << x }
|
|
11
|
+
result.should == [5]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "yields while increasing self until it is less than stop" do
|
|
15
|
+
result = []
|
|
16
|
+
2.upto(5) { |x| result << x }
|
|
17
|
+
result.should == [2, 3, 4, 5]
|
|
18
|
+
end
|
|
19
|
+
end
|