opal 0.3.26 → 0.3.27
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -6
- data/.travis.yml +1 -4
- data/Gemfile +1 -1
- data/README.md +3 -8
- data/Rakefile +26 -3
- data/core/array.rb +33 -91
- data/core/boolean.rb +1 -4
- data/core/class.rb +25 -71
- data/core/error.rb +5 -3
- data/core/hash.rb +3 -2
- data/core/kernel.rb +40 -1
- data/core/load_order +1 -1
- data/core/nil_class.rb +1 -3
- data/core/runtime.js +4 -44
- data/core/template.rb +20 -0
- data/core/{opal-spec → test_runner}/runner.js +0 -6
- data/lib/opal.rb +1 -12
- data/lib/opal/builder.rb +3 -10
- data/lib/opal/lexer.rb +1095 -1110
- data/lib/opal/parser.rb +229 -26
- data/lib/opal/rake_task.rb +3 -3
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +2 -2
- data/spec/core/array/assoc_spec.rb +2 -3
- data/spec/core/array/comparison_spec.rb +16 -0
- data/spec/core/array/constructor_spec.rb +0 -9
- data/spec/core/array/drop_spec.rb +21 -0
- data/spec/core/array/dup_spec.rb +15 -0
- data/spec/core/array/{eql_spec.rb → equal_value_spec.rb} +0 -0
- data/spec/core/array/index_spec.rb +26 -0
- data/spec/core/array/inspect_spec.rb +13 -0
- data/spec/core/array/intersection_spec.rb +22 -0
- data/spec/core/array/join_spec.rb +9 -0
- data/spec/core/array/keep_if_spec.rb +7 -0
- data/spec/core/array/minus_spec.rb +19 -9
- data/spec/core/array/multiply_spec.rb +13 -0
- data/spec/core/array/new_spec.rb +40 -0
- data/spec/core/array/rindex_spec.rb +21 -0
- data/spec/core/array/select_spec.rb +13 -0
- data/spec/core/array/shift_spec.rb +51 -0
- data/spec/core/array/slice_spec.rb +37 -0
- data/spec/core/array/take_spec.rb +21 -0
- data/spec/core/array/take_while_spec.rb +13 -0
- data/spec/core/array/to_a_spec.rb +7 -0
- data/spec/core/array/unshift_spec.rb +29 -0
- data/spec/core/hash/constructor_spec.rb +13 -0
- data/spec/core/hash/default_proc_spec.rb +20 -0
- data/spec/core/hash/default_spec.rb +8 -0
- data/spec/core/hash/delete_spec.rb +11 -0
- data/spec/core/hash/dup_spec.rb +10 -0
- data/spec/core/hash/reject_spec.rb +18 -0
- data/spec/core/hash/to_a_spec.rb +13 -0
- data/spec/core/kernel/Array_spec.rb +10 -0
- data/spec/core/kernel/class_spec.rb +6 -0
- data/spec/core/kernel/equal_spec.rb +12 -0
- data/spec/core/kernel/extend_spec.rb +21 -0
- data/spec/core/kernel/instance_eval_spec.rb +28 -0
- data/spec/core/kernel/instance_variable_get_spec.rb +14 -0
- data/spec/core/kernel/instance_variable_set_spec.rb +10 -0
- data/spec/core/kernel/match_spec.rb +5 -0
- data/spec/core/module/alias_method_spec.rb +10 -0
- data/spec/core/module/ancestors_spec.rb +11 -0
- data/spec/core/module/append_features_spec.rb +14 -0
- data/spec/core/proc/call_spec.rb +21 -0
- data/spec/core/proc/proc_tricks_spec.rb +1 -1
- data/spec/language/alias_spec.rb +1 -1
- data/spec/opal/class/instance_methods_spec.rb +13 -0
- data/spec/opal/kernel/attribute_spec.rb +57 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/test_case.html +13 -0
- metadata +88 -12
- data/core/erb.rb +0 -32
- data/lib/opal/erb_parser.rb +0 -20
- data/spec/opal/erb/erb_spec.rb +0 -23
data/opal.gemspec
CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'opal'
|
6
6
|
s.version = Opal::VERSION
|
7
7
|
s.author = 'Adam Beynon'
|
8
|
-
s.email = 'adam@
|
9
|
-
s.homepage = 'http://
|
8
|
+
s.email = 'adam.beynon@gmail.com'
|
9
|
+
s.homepage = 'http://opal.github.com'
|
10
10
|
s.summary = 'Ruby runtime and core library for javascript'
|
11
11
|
s.description = 'Ruby runtime and core library for javascript.'
|
12
12
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe "Array#assoc" do
|
2
2
|
it "returns the first array whose 1st item is == obj or nil" do
|
3
3
|
s1 = ["colors", "red", "blue", "green"]
|
4
|
-
s2 = [:
|
4
|
+
s2 = [:letters, "a", "b", "c"]
|
5
5
|
s3 = [4]
|
6
6
|
s4 = ["colors", "cyan", "yellow", "magenda"]
|
7
7
|
s5 = [:letters, "a", "i", "u"]
|
@@ -11,8 +11,7 @@ describe "Array#assoc" do
|
|
11
11
|
a.assoc(s2.first).should == s2
|
12
12
|
a.assoc(s3.first).should == s3
|
13
13
|
a.assoc(s4.first).should == s1
|
14
|
-
|
15
|
-
# a.assoc(s5.first).should == s2
|
14
|
+
a.assoc(s5.first).should == s2
|
16
15
|
end
|
17
16
|
|
18
17
|
it "ignores any non-Array elements" do
|
@@ -0,0 +1,16 @@
|
|
1
|
+
describe "Array#<=>" do
|
2
|
+
it "returns 0 if the arrays are equal" do
|
3
|
+
([] <=> []).should == 0
|
4
|
+
([1, 2, 3, 4, 5, 6] <=> [1, 2, 3, 4, 5, 6]).should == 0
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns -1 if the array is shorter than the other array" do
|
8
|
+
([] <=> [1]).should == -1
|
9
|
+
([1, 1] <=> [1, 1, 1]).should == -1
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns +1 if the array is longer than the other array" do
|
13
|
+
([1] <=> []).should == 1
|
14
|
+
([1, 1, 1] <=> [1, 1]).should == 1
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Array#drop" do
|
2
|
+
it "removes the specified number of elements from the start of the array" do
|
3
|
+
[1, 2, 3, 4, 5].drop(2).should == [3, 4, 5]
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns an empty Array if all elements are dropped" do
|
7
|
+
[1, 2].drop(2).should == []
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns an empty Array when called on an empty Array" do
|
11
|
+
[].drop(0).should == []
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not drop any elements when passed zero" do
|
15
|
+
[1, 2].drop(0).should == [1, 2]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an empty Array if more elements than exist are dropped" do
|
19
|
+
[1, 2].drop(3).should == []
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe "Array#dup" do
|
2
|
+
it "produces a shallow copy where the references are directly copied" do
|
3
|
+
a = [mock('1'), mock('2')]
|
4
|
+
b = a.dup
|
5
|
+
b.first.object_id.should == a.first.object_id
|
6
|
+
b.last.object_id.should == a.last.object_id
|
7
|
+
end
|
8
|
+
|
9
|
+
it "creates a new array containing all the elements of the original" do
|
10
|
+
a = [1, 2, 3, 4]
|
11
|
+
b = a.dup
|
12
|
+
b.should == a
|
13
|
+
b.object_id.should_not == a.object_id
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe "Array#index" do
|
2
|
+
it "returns the index of the first element == to object" do
|
3
|
+
[1, 2, 3, 4, 5, 6].index(3).should == 2
|
4
|
+
[1, 2, 3, 4, 5, 6].index(4).should == 3
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns 0 if first element == to object" do
|
8
|
+
[2, 1, 3, 2, 5].index(2).should == 0
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns size-1 if only last element == to object" do
|
12
|
+
[2, 1, 3, 1, 5].index(5).should == 4
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil if no element == to object" do
|
16
|
+
[2, 1, 1, 1, 1].index(3).should == nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "accepts a block instead of an argument" do
|
20
|
+
[4, 2, 1, 5, 1, 3].index { |x| x < 2 }.should == 2
|
21
|
+
end
|
22
|
+
|
23
|
+
it "ignores the block if there is an argument" do
|
24
|
+
[4, 2, 1, 5, 1, 3].index(5) { |x| x < 2 }.should == 3
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "Array#inspect" do
|
2
|
+
it "returns a String" do
|
3
|
+
[1, 2, 3].inspect.should be_kind_of(String)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns '[]' for an empty Array" do
|
7
|
+
[].inspect.should == "[]"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "calls inspect on its elements and joins the results with commas" do
|
11
|
+
[0, 1, 2].inspect.should == "[0, 1, 2]"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe "Array#&" do
|
2
|
+
it "creates an array with elements common to both arrays (intersection)" do
|
3
|
+
([] & []).should == []
|
4
|
+
([1, 2] & []).should == []
|
5
|
+
([] & [1, 2]).should == []
|
6
|
+
([1, 3, 5] & [1, 2, 3]).should == [1, 3]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "creates an array with no duplicates" do
|
10
|
+
([1, 1, 3, 5] & [1, 2, 3]).uniq!.should == nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "creates an array with elements in order they are first encountered" do
|
14
|
+
([1, 2, 3, 2, 5] & [5, 2, 3, 4]).should == [2, 3, 5]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "does not modify the original Array" do
|
18
|
+
a = [1, 1, 3, 5]
|
19
|
+
a & [1, 2, 3]
|
20
|
+
a.should == [1, 1, 3, 5]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Array#join" do
|
2
|
+
it "returns a string formed by concatenating each element with separator" do
|
3
|
+
[1, 2, 3, 4, 5].join(' | ').should == "1 | 2 | 3 | 4 | 5"
|
4
|
+
end
|
5
|
+
|
6
|
+
it "does not separate elements when the passed separator is nil" do
|
7
|
+
[1, 2, 3].join(nil).should == '123'
|
8
|
+
end
|
9
|
+
end
|
@@ -1,13 +1,23 @@
|
|
1
1
|
describe "Array#-" do
|
2
|
-
it "
|
3
|
-
([
|
4
|
-
([
|
5
|
-
([] - [
|
6
|
-
([] - []).should == []
|
2
|
+
it "creates an array minus any items from other array" do
|
3
|
+
([] - [1, 2, 4]).should == []
|
4
|
+
([1, 2, 4] - []).should == [1, 2, 4]
|
5
|
+
([1, 2, 3, 4, 5] - [1, 2, 4]).should == [3, 5]
|
7
6
|
end
|
8
7
|
|
9
|
-
it "
|
10
|
-
|
11
|
-
(ary - ary).should == []
|
8
|
+
it "removes multiple items on the lhs equal to one on the rhs" do
|
9
|
+
([1, 1, 2, 2, 3, 3, 4, 5] - [1, 2, 4]).should == [3, 3, 5]
|
12
10
|
end
|
13
|
-
|
11
|
+
|
12
|
+
it "is not destructive" do
|
13
|
+
a = [1, 2, 3]
|
14
|
+
a - []
|
15
|
+
a.should == [1, 2, 3]
|
16
|
+
a - [1]
|
17
|
+
a.should == [1, 2, 3]
|
18
|
+
a - [1, 2, 3]
|
19
|
+
a.should == [1, 2, 3]
|
20
|
+
a - [:a, :b, :c]
|
21
|
+
a.should == [1, 2, 3]
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "Array#* with an integer" do
|
2
|
+
it "concatenates n copies of the array when passed an integer" do
|
3
|
+
([1, 2, 3] * 0).should == []
|
4
|
+
([1, 2, 3] * 1).should == [1, 2, 3]
|
5
|
+
([1, 2, 3] * 3).should == [1, 2, 3, 1, 2, 3, 1, 2, 3]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Array#* with a string" do
|
10
|
+
it "returns a string formed by concatenating each element with separator" do
|
11
|
+
([1, 2, 3, 4, 5] * ' | ').should == "1 | 2 | 3 | 4 | 5"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
describe "Array.new" do
|
2
|
+
it "returns an instance of Array" do
|
3
|
+
Array.new.should be_kind_of(Array)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "Array.new with no arguments" do
|
8
|
+
it "returns an empty array" do
|
9
|
+
Array.new.empty?.should be_true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Array.new with (array)" do
|
14
|
+
it "returns an array initialized to the other array" do
|
15
|
+
b = [4, 5, 6]
|
16
|
+
Array.new(b).should == b
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Array.new with (size, object=nil)" do
|
21
|
+
it "returns an array of size filled with object" do
|
22
|
+
obj = [3]
|
23
|
+
a = Array.new(2, obj)
|
24
|
+
a.should == [obj, obj]
|
25
|
+
a[0].should equal(obj)
|
26
|
+
a[1].should equal(obj)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns an array of size filled with nil when object is omitted" do
|
30
|
+
Array.new(3).should == [nil, nil, nil]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "yields the index of the element and sets the element to the value of the block" do
|
34
|
+
Array.new(3) { |i| i.to_s }.should == ['0', '1', '2']
|
35
|
+
end
|
36
|
+
|
37
|
+
it "uses the block value instead of using the default value" do
|
38
|
+
Array.new(3, :obj) { |i| i.to_s }.should == ['0', '1', '2']
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Array#rindex" do
|
2
|
+
it "returns the first index backwards from the end where element == to object" do
|
3
|
+
[2, 1, 3, 5, 1].rindex(3).should == 2
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns size-1 if last element == to object" do
|
7
|
+
[2, 1, 3, 2, 5].rindex(5).should == 4
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns 0 if only first element == to object" do
|
11
|
+
[2, 1, 3, 1, 5].rindex(2).should == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns nil if no element == to object" do
|
15
|
+
[1, 1, 3, 2, 1, 3].rindex(4).should == nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "accepts a block instead of an argument" do
|
19
|
+
[4, 2, 1, 5, 1, 3].rindex { |x| x < 2 }.should == 4
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "Array#select" do
|
2
|
+
it "returns a new array of elements for which block is true" do
|
3
|
+
[1, 3, 4, 5, 6, 9].select { |i| i.odd? }.should == [1, 3, 5, 9]
|
4
|
+
[1, 2, 3, 4, 5, 6].select { true }.should == [1, 2, 3, 4, 5, 6]
|
5
|
+
[1, 2, 3, 4, 5, 6].select { false }.should == []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Array#select!" do
|
10
|
+
it "returns nil if no changes were made in the array" do
|
11
|
+
[1, 2, 3].select! { true }.should be_nil
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
describe "Array#shift" do
|
2
|
+
it "removes and returns the first element" do
|
3
|
+
a = [5, 1, 1, 5, 4]
|
4
|
+
a.shift.should == 5
|
5
|
+
a.should == [1, 1, 5, 4]
|
6
|
+
a.shift.should == 1
|
7
|
+
a.should == [1, 5, 4]
|
8
|
+
a.shift.should == 1
|
9
|
+
a.should == [5, 4]
|
10
|
+
a.shift.should == 5
|
11
|
+
a.should == [4]
|
12
|
+
a.shift.should == 4
|
13
|
+
a.should == []
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil whent the array is empty" do
|
17
|
+
[].shift.should == nil
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "passed a number n as an argument" do
|
21
|
+
it "removes and returns an array with the first n element of the array" do
|
22
|
+
a = [1, 2, 3, 4, 5, 6]
|
23
|
+
|
24
|
+
a.shift(0).should == []
|
25
|
+
a.should == [1, 2, 3, 4, 5, 6]
|
26
|
+
|
27
|
+
a.shift(1).should == [1]
|
28
|
+
a.should == [2, 3, 4, 5, 6]
|
29
|
+
|
30
|
+
a.shift(2).should == [2, 3]
|
31
|
+
a.should == [4, 5, 6]
|
32
|
+
|
33
|
+
a.shift(3).should == [4, 5, 6]
|
34
|
+
a.should == []
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does not corrupt the array when shift without arguments is followed by shift with an argument" do
|
38
|
+
a = [1, 2, 3, 4, 5]
|
39
|
+
|
40
|
+
a.shift.should == 1
|
41
|
+
a.shift(3).should == [2, 3, 4]
|
42
|
+
a.should == [5]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns whole elements if n exceeds size of the array" do
|
46
|
+
a = [1, 2, 3, 4, 5]
|
47
|
+
a.shift(6).should == [1, 2, 3, 4, 5]
|
48
|
+
a.should == []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe "Array#slice!" do
|
2
|
+
it "removes and return the element at index" do
|
3
|
+
a = [1, 2, 3, 4]
|
4
|
+
a.slice!(10).should == nil
|
5
|
+
a.should == [1, 2, 3, 4]
|
6
|
+
a.slice!(-10).should == nil
|
7
|
+
a.should == [1, 2, 3, 4]
|
8
|
+
a.slice!(2).should == 3
|
9
|
+
a.should == [1, 2, 4]
|
10
|
+
a.slice!(-1).should == 4
|
11
|
+
a.should == [1, 2]
|
12
|
+
a.slice!(1).should == 2
|
13
|
+
a.should == [1]
|
14
|
+
a.slice!(-1).should == 1
|
15
|
+
a.should == []
|
16
|
+
a.slice!(-1).should == nil
|
17
|
+
a.should == []
|
18
|
+
a.slice!(0).should == nil
|
19
|
+
a.should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it "removes and returns length elements beginning at start" do
|
23
|
+
a = [1, 2, 3, 4, 5, 6]
|
24
|
+
a.slice!(2, 3).should == [3, 4, 5]
|
25
|
+
a.should == [1, 2, 6]
|
26
|
+
a.slice!(1, 1).should == [2]
|
27
|
+
a.should == [1, 6]
|
28
|
+
a.slice!(1, 0).should == []
|
29
|
+
a.should == [1, 6]
|
30
|
+
a.slice!(2, 0).should == []
|
31
|
+
a.should == [1, 6]
|
32
|
+
a.slice!(0, 4).should == [1, 6]
|
33
|
+
a.should == []
|
34
|
+
a.slice!(0, 4).should == []
|
35
|
+
a.should == []
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "Array#take" do
|
2
|
+
it "returns the first specified number of elements" do
|
3
|
+
[1, 2, 3].take(2).should == [1, 2]
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns all elements when the argument is greater than the Array size" do
|
7
|
+
[1, 2].take(99).should == [1, 2]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns all elements when the argument is less than the Array size" do
|
11
|
+
[1, 2].take(4).should == [1, 2]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an empty Array when passed zero" do
|
15
|
+
[1].take(0).should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an empty Array when called on an empty Array" do
|
19
|
+
[].take(3).should == []
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "Array#take_while" do
|
2
|
+
it "returns all elements until the block returns false" do
|
3
|
+
[1, 2, 3].take_while{ |element| element < 3 }.should == [1, 2]
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns all elements until the block returns nil" do
|
7
|
+
[1, 2, nil, 4].take_while{ |element| element }.should == [1, 2]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns all elements until the block returns false" do
|
11
|
+
[1, 2, false, 4].take_while{ |element| element }.should == [1, 2]
|
12
|
+
end
|
13
|
+
end
|