opal 0.3.18 → 0.3.19
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 +1 -1
- data/Gemfile +1 -3
- data/README.md +472 -10
- data/Rakefile +10 -52
- data/core/array.rb +9 -14
- data/core/basic_object.rb +7 -10
- data/core/boolean.rb +5 -1
- data/core/class.rb +15 -38
- data/core/dir.rb +89 -0
- data/core/enumerable.rb +133 -57
- data/core/error.rb +15 -1
- data/core/file.rb +85 -0
- data/core/hash.rb +186 -32
- data/core/kernel.rb +30 -31
- data/core/load_order +4 -2
- data/core/module.rb +42 -62
- data/core/numeric.rb +7 -1
- data/core/object.rb +1 -1
- data/core/proc.rb +6 -2
- data/core/range.rb +16 -28
- data/core/regexp.rb +3 -3
- data/core/runtime.js +281 -350
- data/core/string.rb +100 -110
- data/docs/CNAME +1 -0
- data/docs/Rakefile +55 -0
- data/docs/css/styles.css +50 -0
- data/docs/css/syntax.css +63 -0
- data/docs/layout/post.html +3 -0
- data/docs/layout/pre.html +11 -0
- data/examples/dependencies/app.rb +3 -0
- data/lib/opal.rb +2 -1
- data/lib/opal/builder.rb +36 -10
- data/lib/opal/builder_task.rb +51 -24
- data/lib/opal/grammar.rb +2509 -2439
- data/lib/opal/grammar.y +38 -5
- data/lib/opal/lexer.rb +18 -2
- data/lib/opal/parser.rb +375 -349
- data/lib/opal/scope.rb +24 -2
- data/lib/opal/version.rb +1 -1
- data/spec/builder/build_order_spec.rb +20 -0
- data/spec/builder/lib_name_for_spec.rb +24 -0
- data/spec/grammar/call_spec.rb +9 -6
- data/spec/grammar/lambda_spec.rb +64 -0
- data/spec/grammar/sclass_spec.rb +5 -3
- data/{core/spec → test}/core/array/allocate_spec.rb +0 -0
- data/{core/spec → test}/core/array/append_spec.rb +0 -0
- data/{core/spec → test}/core/array/assoc_spec.rb +0 -0
- data/{core/spec → test}/core/array/at_spec.rb +0 -0
- data/{core/spec → test}/core/array/clear_spec.rb +0 -0
- data/{core/spec → test}/core/array/clone_spec.rb +0 -0
- data/{core/spec → test}/core/array/collect_spec.rb +0 -0
- data/{core/spec → test}/core/array/compact_spec.rb +0 -0
- data/{core/spec → test}/core/array/concat_spec.rb +0 -0
- data/{core/spec → test}/core/array/constructor_spec.rb +0 -0
- data/{core/spec → test}/core/array/count_spec.rb +0 -0
- data/{core/spec → test}/core/array/delete_at_spec.rb +0 -0
- data/{core/spec → test}/core/array/delete_if_spec.rb +0 -0
- data/{core/spec → test}/core/array/delete_spec.rb +0 -0
- data/{core/spec → test}/core/array/each_index_spec.rb +0 -0
- data/{core/spec → test}/core/array/each_spec.rb +0 -0
- data/{core/spec → test}/core/array/element_reference_spec.rb +0 -0
- data/{core/spec → test}/core/array/empty_spec.rb +0 -0
- data/{core/spec → test}/core/array/eql_spec.rb +0 -0
- data/{core/spec → test}/core/array/fetch_spec.rb +0 -0
- data/{core/spec → test}/core/array/first_spec.rb +0 -0
- data/{core/spec → test}/core/array/flatten_spec.rb +0 -0
- data/{core/spec → test}/core/array/include_spec.rb +0 -0
- data/{core/spec → test}/core/array/insert_spec.rb +0 -0
- data/{core/spec → test}/core/array/last_spec.rb +0 -0
- data/{core/spec → test}/core/array/length_spec.rb +0 -0
- data/{core/spec → test}/core/array/map_spec.rb +0 -0
- data/{core/spec → test}/core/array/plus_spec.rb +0 -0
- data/{core/spec → test}/core/array/pop_spec.rb +0 -0
- data/{core/spec → test}/core/array/push_spec.rb +0 -0
- data/{core/spec → test}/core/array/rassoc_spec.rb +0 -0
- data/{core/spec → test}/core/array/reject_spec.rb +0 -0
- data/{core/spec → test}/core/array/replace_spec.rb +0 -0
- data/{core/spec → test}/core/array/reverse_each_spec.rb +0 -0
- data/{core/spec → test}/core/array/reverse_spec.rb +0 -0
- data/{core/spec → test}/core/array/size_spec.rb +0 -0
- data/{core/spec → test}/core/array/to_ary_spec.rb +0 -0
- data/{core/spec → test}/core/array/uniq_spec.rb +0 -0
- data/{core/spec → test}/core/array/zip_spec.rb +0 -0
- data/test/core/class/fixtures/classes.rb +9 -0
- data/test/core/class/new_spec.rb +108 -0
- data/{core/spec → test}/core/enumerable/all_spec.rb +0 -0
- data/{core/spec → test}/core/enumerable/any_spec.rb +0 -0
- data/{core/spec → test}/core/enumerable/collect_spec.rb +0 -0
- data/{core/spec → test}/core/enumerable/count_spec.rb +0 -0
- data/test/core/enumerable/detect_spec.rb +48 -0
- data/test/core/enumerable/drop_spec.rb +17 -0
- data/test/core/enumerable/drop_while_spec.rb +24 -0
- data/test/core/enumerable/each_with_index_spec.rb +11 -0
- data/test/core/enumerable/each_with_object_spec.rb +17 -0
- data/test/core/enumerable/entries_spec.rb +6 -0
- data/test/core/enumerable/find_all_spec.rb +13 -0
- data/test/core/enumerable/find_index_spec.rb +45 -0
- data/test/core/enumerable/find_spec.rb +48 -0
- data/test/core/enumerable/first_spec.rb +40 -0
- data/{core/spec → test}/core/enumerable/fixtures/classes.rb +19 -0
- data/test/core/enumerable/grep_spec.rb +21 -0
- data/test/core/enumerable/take_spec.rb +40 -0
- data/test/core/enumerable/to_a_spec.rb +6 -0
- data/{core/spec → test}/core/false/and_spec.rb +0 -0
- data/{core/spec → test}/core/false/inspect_spec.rb +0 -0
- data/{core/spec → test}/core/false/or_spec.rb +0 -0
- data/{core/spec → test}/core/false/to_s_spec.rb +0 -0
- data/{core/spec → test}/core/false/xor_spec.rb +0 -0
- data/test/core/file/expand_path_spec.rb +20 -0
- data/{core/spec → test}/core/hash/allocate_spec.rb +0 -0
- data/{core/spec → test}/core/hash/assoc_spec.rb +0 -0
- data/{core/spec → test}/core/hash/clear_spec.rb +0 -0
- data/{core/spec → test}/core/hash/clone_spec.rb +0 -0
- data/test/core/hash/default_spec.rb +9 -0
- data/{core/spec → test}/core/hash/delete_if_spec.rb +0 -0
- data/test/core/hash/each_key_spec.rb +15 -0
- data/test/core/hash/each_pair_spec.rb +30 -0
- data/test/core/hash/each_spec.rb +30 -0
- data/test/core/hash/each_value_spec.rb +15 -0
- data/{core/spec → test}/core/hash/element_reference_spec.rb +14 -0
- data/{core/spec → test}/core/hash/element_set_spec.rb +1 -0
- data/test/core/hash/empty_spec.rb +10 -0
- data/test/core/hash/fetch_spec.rb +24 -0
- data/test/core/hash/flatten_spec.rb +46 -0
- data/test/core/hash/has_key_spec.rb +24 -0
- data/test/core/hash/has_value_spec.rb +12 -0
- data/test/core/hash/include_spec.rb +24 -0
- data/test/core/hash/index_spec.rb +13 -0
- data/test/core/hash/indexes_spec.rb +9 -0
- data/test/core/hash/indices_spec.rb +9 -0
- data/test/core/hash/invert_spec.rb +12 -0
- data/test/core/hash/keep_if_spec.rb +18 -0
- data/test/core/hash/key_spec.rb +24 -0
- data/test/core/hash/keys_spec.rb +10 -0
- data/test/core/hash/length_spec.rb +10 -0
- data/test/core/hash/member_spec.rb +24 -0
- data/{core/spec → test}/core/hash/merge_spec.rb +0 -0
- data/{core/spec → test}/core/hash/new_spec.rb +0 -0
- data/test/core/hash/rassoc_spec.rb +34 -0
- data/test/core/hash/replace_spec.rb +7 -0
- data/test/core/hash/select_spec.rb +52 -0
- data/test/core/hash/shift_spec.rb +19 -0
- data/test/core/hash/size_spec.rb +10 -0
- data/test/core/hash/update_spec.rb +17 -0
- data/test/core/hash/value_spec.rb +12 -0
- data/test/core/hash/values_at_spec.rb +9 -0
- data/test/core/hash/values_spec.rb +7 -0
- data/test/core/kernel/eql_spec.rb +15 -0
- data/test/core/kernel/equal_value_spec.rb +12 -0
- data/test/core/kernel/loop_spec.rb +23 -0
- data/test/core/kernel/nil_spec.rb +7 -0
- data/test/core/kernel/proc_spec.rb +9 -0
- data/test/core/kernel/rand_spec.rb +14 -0
- data/test/core/kernel/respond_to_spec.rb +24 -0
- data/test/core/kernel/send_spec.rb +56 -0
- data/test/core/kernel/tap_spec.rb +10 -0
- data/test/core/kernel/to_s_spec.rb +5 -0
- data/{core/spec → test}/core/matchdata/to_a_spec.rb +0 -0
- data/{core/spec → test}/core/nil/and_spec.rb +0 -0
- data/{core/spec → test}/core/nil/inspect_spec.rb +0 -0
- data/{core/spec → test}/core/nil/nil_spec.rb +0 -0
- data/{core/spec → test}/core/nil/or_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_a_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_f_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_i_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_s_spec.rb +0 -0
- data/{core/spec → test}/core/nil/xor_spec.rb +0 -0
- data/{core/spec → test}/core/numeric/equal_value_spec.rb +0 -0
- data/test/core/range/begin_spec.rb +9 -0
- data/test/core/range/case_compare_spec.rb +16 -0
- data/test/core/range/end_spec.rb +9 -0
- data/{core/spec → test}/core/regexp/match_spec.rb +0 -0
- data/test/core/string/capitalize_spec.rb +10 -0
- data/test/core/string/casecmp_spec.rb +16 -0
- data/test/core/string/chomp_spec.rb +43 -0
- data/test/core/string/chop_spec.rb +10 -0
- data/test/core/string/chr_spec.rb +13 -0
- data/test/core/string/comparison_spec.rb +13 -0
- data/test/core/string/downcase_spec.rb +6 -0
- data/test/core/string/element_reference_spec.rb +72 -0
- data/test/core/string/empty_spec.rb +8 -0
- data/test/core/string/end_with_spec.rb +12 -0
- data/test/core/string/fixtures/classes.rb +3 -0
- data/test/core/string/gsub_spec.rb +17 -0
- data/test/core/string/include_spec.rb +12 -0
- data/test/core/string/intern_spec.rb +9 -0
- data/test/core/string/length_spec.rb +9 -0
- data/test/core/string/lstrip_spec.rb +7 -0
- data/test/core/string/match_spec.rb +27 -0
- data/test/core/string/next_spec.rb +10 -0
- data/test/core/string/ord_spec.rb +9 -0
- data/test/core/string/partition_spec.rb +10 -0
- data/test/core/string/reverse_spec.rb +7 -0
- data/test/core/string/rstrip_spec.rb +7 -0
- data/test/core/string/size_spec.rb +9 -0
- data/test/core/string/slice_spec.rb +72 -0
- data/test/core/string/split_spec.rb +5 -0
- data/test/core/string/start_with_spec.rb +12 -0
- data/test/core/string/strip_spec.rb +6 -0
- data/test/core/string/sub_spec.rb +22 -0
- data/test/core/string/succ_spec.rb +10 -0
- data/test/core/string/sum_spec.rb +5 -0
- data/test/core/string/swapcase_spec.rb +18 -0
- data/test/core/string/to_a_spec.rb +9 -0
- data/test/core/string/to_f_spec.rb +14 -0
- data/test/core/string/to_i_spec.rb +25 -0
- data/test/core/string/to_s_spec.rb +13 -0
- data/test/core/string/to_str_spec.rb +13 -0
- data/test/core/string/to_sym_spec.rb +9 -0
- data/test/core/string/upcase_spec.rb +6 -0
- data/test/core/symbol/to_proc_spec.rb +12 -0
- data/{core/spec → test}/core/true/and_spec.rb +0 -0
- data/{core/spec → test}/core/true/inspect_spec.rb +0 -0
- data/{core/spec → test}/core/true/or_spec.rb +0 -0
- data/{core/spec → test}/core/true/to_s_spec.rb +0 -0
- data/{core/spec → test}/core/true/xor_spec.rb +0 -0
- data/test/index.html +11 -0
- data/{core/spec → test}/language/alias_spec.rb +4 -0
- data/{core/spec → test}/language/and_spec.rb +0 -0
- data/{core/spec → test}/language/array_spec.rb +0 -0
- data/{core/spec → test}/language/block_spec.rb +0 -0
- data/{core/spec → test}/language/break_spec.rb +0 -0
- data/{core/spec → test}/language/case_spec.rb +0 -0
- data/{core/spec → test}/language/defined_spec.rb +0 -0
- data/{core/spec → test}/language/ensure_spec.rb +0 -0
- data/test/language/fixtures/yield.rb +23 -0
- data/{core/spec → test}/language/hash_spec.rb +0 -0
- data/{core/spec → test}/language/if_spec.rb +0 -0
- data/test/language/literal_lambda_spec.rb +47 -0
- data/{core/spec → test}/language/loop_spec.rb +0 -0
- data/{core/spec → test}/language/metaclass_spec.rb +0 -0
- data/{core/spec → test}/language/next_spec.rb +0 -0
- data/{core/spec → test}/language/or_spec.rb +0 -0
- data/{core/spec → test}/language/predefined_spec.rb +0 -0
- data/{core/spec → test}/language/regexp_spec.rb +0 -0
- data/{core/spec → test}/language/send_spec.rb +0 -0
- data/{core/spec → test}/language/singleton_class_spec.rb +0 -0
- data/{core/spec → test}/language/super_spec.rb +0 -0
- data/{core/spec → test}/language/symbol_spec.rb +0 -0
- data/{core/spec → test}/language/undef_spec.rb +0 -0
- data/{core/spec → test}/language/unless_spec.rb +0 -0
- data/{core/spec → test}/language/until_spec.rb +0 -0
- data/{core/spec → test}/language/variables_spec.rb +0 -0
- data/{core/spec → test}/language/while_spec.rb +0 -0
- data/test/language/yield_spec.rb +100 -0
- data/test/opal/array/subclassing_spec.rb +32 -0
- data/test/opal/class/bridge_class_spec.rb +37 -0
- data/test/opal/exception/subclassing_spec.rb +17 -0
- data/test/opal/runtime/_methods_spec.rb +48 -0
- data/test/opal/runtime/class_hierarchy_spec.rb +22 -0
- data/test/opal/runtime/def_spec.rb +23 -0
- data/test/opal/string/subclassing_spec.rb +26 -0
- data/test/spec_helper.rb +3 -0
- metadata +437 -111
- data/core/spec/core/class/new_spec.rb +0 -16
- data/core/spec/core/hash/default_spec.rb +0 -4
- data/core/spec/core/symbol/to_proc_spec.rb +0 -6
- data/core/spec/index.html +0 -11
- data/spec/builder/build_source_spec.rb +0 -52
@@ -0,0 +1,18 @@
|
|
1
|
+
describe "String#swapcase" do
|
2
|
+
it "returns a new string with all uppercase chars from self converted to lowercase and vice versa" do
|
3
|
+
"Hello".swapcase.should == "hELLO"
|
4
|
+
"cYbEr_PuNk11".swapcase.should == "CyBeR_pUnK11"
|
5
|
+
"+++---111222???".swapcase.should == "+++---111222???"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is locale insensitive (only upcases a-z and only downcases A-Z" do
|
9
|
+
"ÄÖÜ".swapcase.should == "ÄÖÜ"
|
10
|
+
"ärger".swapcase.should == "äRGER"
|
11
|
+
"BÄR".swapcase.should == "bÄr"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns subclass instances when called on a subclass" do
|
15
|
+
StringSpecs::MyString.new("").swapcase.should be_kind_of(StringSpecs::MyString)
|
16
|
+
StringSpecs::MyString.new("hello").swapcase.should be_kind_of(StringSpecs::MyString)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "String#to_s" do
|
2
|
+
it "returns self when self.class == String" do
|
3
|
+
a = "a string"
|
4
|
+
a.should equal(a.to_s)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns a new instance of String when called on a subclass" do
|
8
|
+
a = StringSpecs::MyString.new("a string")
|
9
|
+
s = a.to_s
|
10
|
+
s.should == "a string"
|
11
|
+
s.should be_kind_of(String)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe "String#to_str" do
|
2
|
+
it "returns self when self.class == String" do
|
3
|
+
a = "a string"
|
4
|
+
a.should equal(a.to_str)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns a new instance of String when called on a subclass" do
|
8
|
+
a = StringSpecs::MyString.new("a string")
|
9
|
+
s = a.to_str
|
10
|
+
s.should == "a string"
|
11
|
+
s.should be_kind_of(String)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "String#to_sym" do
|
2
|
+
it "returns the symbol corresponding to self" do
|
3
|
+
"Koala".to_sym.should == :Koala
|
4
|
+
'cat'.to_sym.should == :cat
|
5
|
+
'@cat'.to_sym.should == :@cat
|
6
|
+
'cat and dog'.to_sym.should == :"cat and dog"
|
7
|
+
"abc=".to_sym.should == :abc=
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe "Symbol#to_proc" do
|
2
|
+
it "returns a new Proc" do
|
3
|
+
proc = :to_s.to_proc
|
4
|
+
proc.should be_kind_of(Proc)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "sends self to arguments passed when calling #call on the proc" do
|
8
|
+
obj = Object.new
|
9
|
+
def obj.to_s; "Received #to_s"; end
|
10
|
+
:to_s.to_proc.call(obj).should == "Received #to_s"
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/index.html
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title></title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<script type="text/javascript" src="../build/opal.js"></script>
|
8
|
+
<script type="text/javascript" src="../build/opal-spec.js"></script>
|
9
|
+
<script type="text/javascript" src="../build/opal.specs.js"></script>
|
10
|
+
</body>
|
11
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
describe "->(){}" do
|
2
|
+
it "can be specified as a literal" do
|
3
|
+
lambda { ->(){} }.call
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns a Proc object" do
|
7
|
+
->(){}.should be_kind_of(Proc)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a lambda" do
|
11
|
+
->(){}.lambda?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can be assigned to a variable" do
|
15
|
+
var = ->(){}
|
16
|
+
var.lambda?.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "understands a do/end block in place of {}" do
|
20
|
+
lambda do
|
21
|
+
->() do
|
22
|
+
end
|
23
|
+
end.call
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can be interpolated into a String" do
|
27
|
+
"1+2=#{->{ 1 + 2 }.call}".should == "1+2=3"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can be used as a Hash key" do
|
31
|
+
h = {}
|
32
|
+
h[->(){ 1 + 2 }.call] = :value
|
33
|
+
h.key?(3).should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can be used in method parameter lists" do
|
37
|
+
def glark7654(a=-> { :foo })
|
38
|
+
a.call
|
39
|
+
end
|
40
|
+
glark7654.should == :foo
|
41
|
+
end
|
42
|
+
|
43
|
+
it "accepts an paramter list between the paranthesis" do
|
44
|
+
lambda { ->(a) {} }.call
|
45
|
+
lambda { ->(a,b) {} }.call
|
46
|
+
end
|
47
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,100 @@
|
|
1
|
+
describe "The yield call" do
|
2
|
+
before :each do
|
3
|
+
@y = YieldSpecs::Yielder.new
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "taking no arguments" do
|
7
|
+
it "raises a LocalJumpError when the method is not passed a block" do
|
8
|
+
lambda { @y.z }.should raise_error(LocalJumpError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "taking a single argument" do
|
13
|
+
it "raises a LocalJumpError when the method is not passed a block" do
|
14
|
+
lambda { @y.s(1) }.should raise_error(LocalJumpError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "passes an empty Array when the argument is an empty Array" do
|
18
|
+
@y.s([]) { |*a| a }.should == [[]]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "passes nil as a value" do
|
22
|
+
@y.s(nil) { |*a| a }.should == [nil]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "passes a single value" do
|
26
|
+
@y.s(1) { |*a| a }.should == [1]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "passes a single, multi-value Array" do
|
30
|
+
@y.s([1, 2, 3]) { |*a| a }.should == [[1, 2, 3]]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "taking multiple arguments" do
|
35
|
+
it "raises a LocalJumpError when the method is not passed a block" do
|
36
|
+
lambda { @y.m(1, 2, 3) }.should raise_error(LocalJumpError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "passes the arguments to the block" do
|
40
|
+
@y.m(1, 2, 3) { |*a| a }.should == [1, 2, 3]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "taking a single splatted argument" do
|
45
|
+
it "raises a LocalJumpError when the method is not passed a block" do
|
46
|
+
lambda { @y.r(0) }.should raise_error(LocalJumpError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "passes a single value" do
|
50
|
+
@y.r(1) { |*a| a }.should == [1]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "passes no arguments when the argument is an empty array" do
|
54
|
+
@y.r([]) { |*a| a }.should == []
|
55
|
+
end
|
56
|
+
|
57
|
+
it "passes the value when the argument is an Array containing a single value" do
|
58
|
+
@y.r([1]) { |*a| a }.should == [1]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "passes the values of the Array as individual arguments" do
|
62
|
+
@y.r([1, 2, 3]) { |*a| a }.should == [1, 2, 3]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "passes the element of a single element Array" do
|
66
|
+
@y.r([[1, 2]]) { |*a| a }.should == [[1, 2]]
|
67
|
+
@y.r([nil]) { |*a| a }.should == [nil]
|
68
|
+
@y.r([[]]) { |*a| a }.should == [[]]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "passes nil as a value" do
|
72
|
+
@y.r(nil) { |*a| a }.should == [nil]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "taking multiple arguments with a splat" do
|
77
|
+
it "raises a LocalJumpError when the method is not passed a block" do
|
78
|
+
lambda { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "passes the arguments to the block" do
|
82
|
+
@y.rs(1, 2, 3) { |*a| a }.should == [1, 2, 3]
|
83
|
+
end
|
84
|
+
|
85
|
+
it "does not pass an argument value if the splatted argument is an empty Array" do
|
86
|
+
@y.rs(1, 2, []) { |*a| a }.should == [1, 2]
|
87
|
+
end
|
88
|
+
|
89
|
+
it "passes the Array elements as arguments if the splatted argument is a non-empty Array" do
|
90
|
+
@y.rs(1, 2, [3]) { |*a| a }.should == [1, 2, 3]
|
91
|
+
@y.rs(1, 2, [nil]) { |*a| a }.should == [1, 2, nil]
|
92
|
+
@y.rs(1, 2, [[]]) { |*a| a }.should == [1, 2, []]
|
93
|
+
@y.rs(1, 2, [3, 4, 5]) { |*a| a }.should == [1, 2, 3, 4, 5]
|
94
|
+
end
|
95
|
+
|
96
|
+
it "passes nil as the argument value if the splatted argument is nil" do
|
97
|
+
@y.rs(1, 2, nil) { |*a| a }.should == [1, 2, nil]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ArraySubclassSpec < Array
|
2
|
+
def add_val(val)
|
3
|
+
`this.push(val)`
|
4
|
+
self
|
5
|
+
end
|
6
|
+
|
7
|
+
def foo
|
8
|
+
:bar
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Array subclasses" do
|
13
|
+
it "should have their defined methods present on instances" do
|
14
|
+
ArraySubclassSpec.new.foo.should == :bar
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should correctly keep their length" do
|
18
|
+
arr = ArraySubclassSpec.new
|
19
|
+
arr.add_val :foo
|
20
|
+
arr.length.should == 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the correct class" do
|
24
|
+
ArraySubclassSpec.new.class.should == ArraySubclassSpec
|
25
|
+
Array.new.class.should == Array
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is just an instance of the bridged constructor" do
|
29
|
+
arr = ArraySubclassSpec.new
|
30
|
+
`(arr.constructor === Array)`.should == true
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
%x{
|
2
|
+
var BridgeClassProto = function() {
|
3
|
+
this.foo = 200;
|
4
|
+
};
|
5
|
+
|
6
|
+
BridgeClassProto.prototype = {
|
7
|
+
bar: 300,
|
8
|
+
baz: 400
|
9
|
+
};
|
10
|
+
}
|
11
|
+
|
12
|
+
class BridgeClassSpec < `BridgeClassProto`
|
13
|
+
def get_foo
|
14
|
+
`this.foo`
|
15
|
+
end
|
16
|
+
|
17
|
+
def say_it
|
18
|
+
"hello world"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Bridging native prototypes to a class" do
|
23
|
+
it "should have a superclass of Object" do
|
24
|
+
BridgeClassSpec.superclass.should == Object
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should report instances as kind of bridged class" do
|
28
|
+
obj = `new BridgeClassProto()`
|
29
|
+
obj.should be_kind_of(BridgeClassSpec)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have defined instance methods present on prototype" do
|
33
|
+
obj = `new BridgeClassProto()`
|
34
|
+
obj.get_foo.should == 200
|
35
|
+
obj.say_it.should == "hello world"
|
36
|
+
end
|
37
|
+
end
|