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,52 @@
|
|
1
|
+
describe "Hash#select" do
|
2
|
+
before(:each) do
|
3
|
+
@hsh = {1 => 2, 3 => 4, 5 => 6}
|
4
|
+
@empty = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
it "yields two arguments: key and value" do
|
8
|
+
all_args = []
|
9
|
+
{1 => 2, 3 => 4}.select { |*args| all_args << args }
|
10
|
+
all_args.should == [[1, 2], [3, 4]]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a Hash of entries for which block is true" do
|
14
|
+
a_pairs = {'a' => 9, 'c' => 4, 'b' => 5, 'd' => 2}.select { |k,v| v % 2 == 0 }
|
15
|
+
a_pairs.should be_kind_of(Hash)
|
16
|
+
a_pairs.should == {'c' => 4, 'd' => 2}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "processes entries with the same order as reject" do
|
20
|
+
h = {:a => 9, :c => 4, :b => 5, :d => 2}
|
21
|
+
|
22
|
+
select_pairs = []
|
23
|
+
reject_pairs = []
|
24
|
+
h.select { |*pair| select_pairs << pair }
|
25
|
+
h.reject { |*pair| reject_pairs << pair }
|
26
|
+
|
27
|
+
select_pairs.should == reject_pairs
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Hash#select!" do
|
32
|
+
before(:each) do
|
33
|
+
@hsh = {1 => 2, 3 => 4, 5 => 6}
|
34
|
+
@empty = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "is equivalent to keep_if if changes are made" do
|
38
|
+
{:a => 2}.select! { |k,v| v <= 1 }.should ==
|
39
|
+
{:a => 2}.keep_if { |k, v| v <= 1 }
|
40
|
+
|
41
|
+
h = {1 => 2, 3 => 4}
|
42
|
+
all_args_select = []
|
43
|
+
all_args_keep_if = []
|
44
|
+
h.dup.select! { |*args| all_args_select << args }
|
45
|
+
h.dup.keep_if { |*args| all_args_keep_if << args }
|
46
|
+
all_args_select.should == all_args_keep_if
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns nil if no changes were made" do
|
50
|
+
{:a => 1}.select! { |k,v| v <= 1 }.should == nil
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "Hash#shift" do
|
2
|
+
it "removes a pair from hash and return it" do
|
3
|
+
h = {:a => 1, :b => 2, "c" => 3, nil => 4, [] => 5}
|
4
|
+
h2 = h.dup
|
5
|
+
|
6
|
+
h.size.times do |i|
|
7
|
+
r = h.shift
|
8
|
+
# r.should be_kind_of(Array)
|
9
|
+
# h2[r.first].should == r.last
|
10
|
+
# h.size.should == h2.size - i - 1
|
11
|
+
end
|
12
|
+
|
13
|
+
h.should == {}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "removes nil from an empty hash" do
|
17
|
+
{}.shift.should == nil
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
describe "Hash#size" do
|
2
|
+
it "returns the number of entries" do
|
3
|
+
{:a => 1, :b => 'c'}.size.should == 2
|
4
|
+
{:a => 1, :b => 2, :a => 2}.size.should == 2
|
5
|
+
{:a => 1, :b => 1, :c => 1}.size.should == 3
|
6
|
+
Hash.new.size.should == 0
|
7
|
+
Hash.new(5).size.should == 0
|
8
|
+
Hash.new { 5 }.size.should == 0
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "Hash#update" do
|
2
|
+
it "adds the entries from other, overwriting duplicate keys. Returns self" do
|
3
|
+
h = {:_1 => 'a', :_2 => '3'}
|
4
|
+
h.update(:_1 => '9', :_9 => 2).should equal(h)
|
5
|
+
h.should == {:_1 => "9", :_2 => "3", :_9 => 2}
|
6
|
+
end
|
7
|
+
|
8
|
+
it "sets any duplicate key to the value of block if passed a block" do
|
9
|
+
h1 = {:a => 2, :b => -1}
|
10
|
+
h2 = {:a => -2, :c => 1}
|
11
|
+
h1.update(h2) { |k,x,y| 3.14 }.should equal(h1)
|
12
|
+
h1.should == {:c => 1, :b => -1, :a => 3.14}
|
13
|
+
|
14
|
+
h1.update(h1) { nil }
|
15
|
+
h1.should == {:a => nil, :b => nil, :c => nil}
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe "Hash#value?" do
|
2
|
+
it "returns true if the value exists in the hash" do
|
3
|
+
{:a => :b}.value?(:a).should == false
|
4
|
+
{1 => 2}.value?(2).should == true
|
5
|
+
h = Hash.new 5
|
6
|
+
h.value?(5).should == false
|
7
|
+
end
|
8
|
+
|
9
|
+
it "uses == semantics for comparing values" do
|
10
|
+
{5 => 2.0}.value?(2).should == true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Hash#values_at" do
|
2
|
+
it "returns an array of values for the given keys" do
|
3
|
+
h = {:a => 9, :b => 'a', :c => -10, :d => nil}
|
4
|
+
h.values_at.should be_kind_of(Array)
|
5
|
+
h.values_at.should == []
|
6
|
+
h.values_at(:a, :d, :b).should be_kind_of(Array)
|
7
|
+
h.values_at(:a, :d, :b).should == [9, nil, 'a']
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe "Kernel#eql?" do
|
2
|
+
it "returns true if obj and anObject are the same object." do
|
3
|
+
o1 = Object.new
|
4
|
+
o2 = Object.new
|
5
|
+
o1.eql?(o1).should be_true
|
6
|
+
o2.eql?(o2).should be_true
|
7
|
+
o1.eql?(o2).should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns true if obj and anObject have the same value." do
|
11
|
+
:hola.eql?(1).should be_false
|
12
|
+
1.eql?(1).should be_true
|
13
|
+
:hola.eql?(:hola).should be_true
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
describe "Kernel#==" do
|
2
|
+
it "returns true only if obj and other are the same object" do
|
3
|
+
o1 = Object.new
|
4
|
+
o2 = Object.new
|
5
|
+
(o1 == o1).should == true
|
6
|
+
(o2 == o2).should == true
|
7
|
+
(o1 == o2).should == false
|
8
|
+
(nil == nil).should == true
|
9
|
+
(o1 == nil).should == false
|
10
|
+
(nil == o2).should == false
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
describe "Kernel.loop" do
|
2
|
+
it "calls block until it is terminated by a break" do
|
3
|
+
i = 0
|
4
|
+
loop do
|
5
|
+
i += 1
|
6
|
+
break if i == 10
|
7
|
+
end
|
8
|
+
|
9
|
+
i.should == 10
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns value passed to break" do
|
13
|
+
loop do
|
14
|
+
break 123
|
15
|
+
end.should == 123
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns nil if no value passed to break" do
|
19
|
+
loop do
|
20
|
+
break
|
21
|
+
end.should == nil
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe "Kernel.rand" do
|
2
|
+
it "returns a float if no argument is passed" do
|
3
|
+
# rand.should be_kind_of(Float)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns an integer for an integer argument" do
|
7
|
+
# rand(77).should be_kind_of(Integer)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a numeric in opal" do
|
11
|
+
rand.should be_kind_of(Numeric)
|
12
|
+
rand(77).should be_kind_of(Numeric)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class RespondToSpecs
|
2
|
+
def self.bar
|
3
|
+
'done'
|
4
|
+
end
|
5
|
+
|
6
|
+
def undefed_method
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
undef undefed_method
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Kernel.respond_to?" do
|
14
|
+
it "indicates if a singleton object responds to a particular message" do
|
15
|
+
RespondToSpecs.respond_to?(:bar).should == true
|
16
|
+
RespondToSpecs.respond_to?(:baz).should == false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Kernel#respond_to?" do
|
21
|
+
before :each do
|
22
|
+
@a = RespondToSpecs.new
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module KernelSpecs
|
2
|
+
class Foo
|
3
|
+
def bar
|
4
|
+
'done'
|
5
|
+
end
|
6
|
+
|
7
|
+
alias :aka :bar
|
8
|
+
|
9
|
+
def baz(*args) args end
|
10
|
+
|
11
|
+
def foo(first, *rest) [first, *rest] end
|
12
|
+
|
13
|
+
def buz(first = true) first end
|
14
|
+
|
15
|
+
def self.bar
|
16
|
+
'done'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Kernel#send" do
|
22
|
+
it "invokes the named public method" do
|
23
|
+
KernelSpecs::Foo.new.send(:bar).should == 'done'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "invokes the named alias of a public method" do
|
27
|
+
KernelSpecs::Foo.new.send(:aka).should == 'done'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Kernel#send" do
|
32
|
+
it "invokes the named method" do
|
33
|
+
KernelSpecs::Foo.new.send(:bar).should == 'done'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "invokes a class method if called on a class" do
|
37
|
+
KernelSpecs::Foo.send(:bar).should == 'done'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "succeeds if passed an arbitrary number of arguments as a splat parameter" do
|
41
|
+
KernelSpecs::Foo.new.send(:baz).should == []
|
42
|
+
KernelSpecs::Foo.new.send(:baz, :quux).should == [:quux]
|
43
|
+
KernelSpecs::Foo.new.send(:baz, :quux, :foo).should == [:quux, :foo]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "succeeds when passing 1 or more arguments as a required and a splat parameter" do
|
47
|
+
KernelSpecs::Foo.new.send(:foo, :quux).should == [:quux]
|
48
|
+
KernelSpecs::Foo.new.send(:foo, :quux, :bar).should == [:quux, :bar]
|
49
|
+
KernelSpecs::Foo.new.send(:foo, :quux, :bar, :baz).should == [:quux, :bar, :baz]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "succeeds when passing 0 arguments to a method with one parameter with a default" do
|
53
|
+
KernelSpecs::Foo.new.send(:buz).should == true
|
54
|
+
KernelSpecs::Foo.new.send(:buz, :arg).should == :arg
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
describe "Kernel#tap" do
|
2
|
+
it "always yields self and returns self" do
|
3
|
+
a = Object.new
|
4
|
+
a.tap {|o| o.should equal(a); 42}.should equal(a)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "raises a LocalJumpError when no block given" do
|
8
|
+
lambda { 3.tap }.should raise_error(LocalJumpError)
|
9
|
+
end
|
10
|
+
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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
describe "Range#===" do
|
2
|
+
it "returns true if other is an element of self" do
|
3
|
+
((0..5) === 2).should == true
|
4
|
+
((-5..5) === 0).should == true
|
5
|
+
((-1...1) === 10.5).should == false
|
6
|
+
((-10..-2) === -2.5).should == true
|
7
|
+
(('C'..'X') === 'M').should == true
|
8
|
+
(('C'..'X') === 'A').should == false
|
9
|
+
(('B'...'W') === 'W').should == false
|
10
|
+
(('B'...'W') === 'Q').should == true
|
11
|
+
((0.5..2.4) === 2).should == true
|
12
|
+
((0.5..2.4) === 2.5).should == false
|
13
|
+
((0.5...2.4) === 2.4).should == true
|
14
|
+
((0.5...2.4) === 2.4).should == false
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
describe "String#capitalize" do
|
2
|
+
it "returns a copy of self with the first character converted to uppercase and the remainder to lowercase" do
|
3
|
+
"".capitalize.should == ""
|
4
|
+
"h".capitalize.should == "H"
|
5
|
+
"H".capitalize.should == "H"
|
6
|
+
"hello".capitalize.should == "Hello"
|
7
|
+
"HELLO".capitalize.should == "Hello"
|
8
|
+
"123ABC".capitalize.should == "123abc"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
describe "String#casecmp" do
|
2
|
+
it "returns -1 when less than other" do
|
3
|
+
"a".casecmp("b").should == -1
|
4
|
+
"A".casecmp("b").should == -1
|
5
|
+
end
|
6
|
+
|
7
|
+
it "returns 0 when equal to other" do
|
8
|
+
"a".casecmp("a").should == 0
|
9
|
+
"A".casecmp("a").should == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns 1 when greater than other" do
|
13
|
+
"b".casecmp("a").should == 1
|
14
|
+
"B".casecmp("a").should == 1
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
describe "String#chomp with separator" do
|
2
|
+
it "returns a new string with the given record separator removed" do
|
3
|
+
"hello".chomp("llo").should == "he"
|
4
|
+
"hellollo".chomp("llo").should == "hello"
|
5
|
+
end
|
6
|
+
|
7
|
+
it "removes carriage return (except \\r) chars multiple times when separator is an empty string" do
|
8
|
+
"".chomp("").should == ""
|
9
|
+
"hello".chomp("").should == "hello"
|
10
|
+
"hello\n".chomp("").should == "hello"
|
11
|
+
"hello\nx".chomp("").should == "hello\nx"
|
12
|
+
"hello\r\n".chomp("").should == "hello"
|
13
|
+
"hello\r\n\r\n\n\n\r\n".chomp("").should == "hello"
|
14
|
+
|
15
|
+
"hello\r".chomp("").should == "hello\r"
|
16
|
+
"hello\n\r".chomp("").should == "hello\n\r"
|
17
|
+
"hello\r\r\r\n".chomp("").should == "hello\r\r"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "removes carriage return chars(\\n, \\r, \\r\\n) when separator is \\n" do
|
21
|
+
"hello".chomp("\n").should == "hello"
|
22
|
+
"hello\n".chomp("\n").should == "hello"
|
23
|
+
"hello\r\n".chomp("\n").should == "hello"
|
24
|
+
"hello\n\r".chomp("\n").should == "hello\n"
|
25
|
+
"hello\r".chomp("\n").should == "hello"
|
26
|
+
"hello \n there".chomp("\n").should == "hello \n there"
|
27
|
+
"hello\r\n\r\n\n\n\r\n".chomp("\n").should == "hello\r\n\r\n\n\n"
|
28
|
+
|
29
|
+
"hello\n\r".chomp("\r").should == "hello\n"
|
30
|
+
"hello\n\r\n".chomp("\r\n").should == "hello\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns self if the separator is nil" do
|
34
|
+
"hello\n\n".chomp(nil).should == "hello\n\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns an empty string when called on an empty string" do
|
38
|
+
"".chomp("\n").should == ""
|
39
|
+
"".chomp("\r").should == ""
|
40
|
+
"".chomp("").should == ""
|
41
|
+
"".chomp(nil).should == ""
|
42
|
+
end
|
43
|
+
end
|