opal 0.3.2 → 0.3.6
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/README.md +85 -127
- data/bin/opal +3 -3
- data/lib/core.rb +114 -0
- data/{gems/core/lib → lib}/core/array.rb +68 -187
- data/{gems/core/lib → lib}/core/basic_object.rb +22 -5
- data/lib/core/class.rb +38 -0
- data/{gems/core/lib → lib}/core/dir.rb +1 -1
- data/lib/core/enumerable.rb +33 -0
- data/{gems/core/lib → lib}/core/error.rb +1 -4
- data/{gems/core/lib → lib}/core/false_class.rb +0 -0
- data/{gems/core/lib → lib}/core/file.rb +11 -3
- data/{gems/core/lib → lib}/core/hash.rb +12 -0
- data/{gems/core/lib → lib}/core/kernel.rb +114 -86
- data/lib/core/match_data.rb +33 -0
- data/lib/core/module.rb +97 -0
- data/{gems/core/lib → lib}/core/nil_class.rb +0 -0
- data/{gems/core/lib → lib}/core/numeric.rb +5 -0
- data/{gems/core/lib → lib}/core/object.rb +0 -0
- data/{gems/core/lib → lib}/core/proc.rb +13 -3
- data/{gems/core/lib → lib}/core/range.rb +10 -0
- data/{gems/core/lib → lib}/core/regexp.rb +33 -1
- data/{gems/core/lib → lib}/core/string.rb +25 -10
- data/{gems/core/lib → lib}/core/symbol.rb +3 -3
- data/{gems/core/lib → lib}/core/top_self.rb +0 -0
- data/{gems/core/lib → lib}/core/true_class.rb +0 -0
- data/lib/dev.rb +169 -0
- data/{gems/ospec/lib → lib}/ospec.rb +1 -0
- data/lib/ospec/autorun.rb +8 -0
- data/{gems/ospec/lib → lib}/ospec/dsl.rb +2 -2
- data/{gems/ospec/lib → lib}/ospec/example.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/before_and_after_hooks.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/errors.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/example_group.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/example/example_group_factory.rb +0 -3
- data/{gems/ospec/lib → lib}/ospec/example/example_group_hierarchy.rb +4 -3
- data/{gems/ospec/lib → lib}/ospec/example/example_group_methods.rb +1 -1
- data/{gems/ospec/lib → lib}/ospec/example/example_group_proxy.rb +3 -2
- data/{gems/ospec/lib → lib}/ospec/example/example_methods.rb +1 -1
- data/{gems/ospec/lib → lib}/ospec/example/example_proxy.rb +7 -7
- data/{gems/ospec/lib → lib}/ospec/expectations.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/expectations/errors.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/expectations/fail_with.rb +4 -3
- data/{gems/ospec/lib → lib}/ospec/expectations/handler.rb +6 -0
- data/lib/ospec/helpers/scratch.rb +18 -0
- data/{gems/ospec/lib → lib}/ospec/matchers.rb +2 -2
- data/{gems/ospec/lib → lib}/ospec/matchers/be.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/matchers/generated_descriptions.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/matchers/operator_matcher.rb +2 -0
- data/lib/ospec/matchers/raise_error.rb +38 -0
- data/lib/ospec/runner.rb +90 -0
- data/{gems/ospec/lib → lib}/ospec/runner/example_group_runner.rb +10 -13
- data/lib/ospec/runner/formatter/html_formatter.rb +139 -0
- data/{gems/ospec/lib → lib}/ospec/runner/formatter/terminal_formatter.rb +0 -0
- data/{gems/ospec/lib → lib}/ospec/runner/options.rb +1 -3
- data/{gems/ospec/lib → lib}/ospec/runner/reporter.rb +0 -9
- data/lib/racc/parser.rb +165 -0
- data/lib/strscan.rb +52 -0
- data/{lib → opal_lib}/opal.rb +2 -0
- data/opal_lib/opal/build_methods.rb +51 -0
- data/opal_lib/opal/builder.rb +164 -0
- data/opal_lib/opal/bundle.rb +70 -0
- data/opal_lib/opal/command.rb +68 -0
- data/{lib → opal_lib}/opal/context.rb +21 -9
- data/{lib → opal_lib}/opal/context/console.rb +0 -2
- data/opal_lib/opal/context/file_system.rb +34 -0
- data/{lib → opal_lib}/opal/context/loader.rb +26 -8
- data/opal_lib/opal/gem.rb +84 -0
- data/{lib → opal_lib}/opal/rake/builder_task.rb +2 -2
- data/opal_lib/opal/rake/spec_task.rb +32 -0
- data/{lib → opal_lib}/opal/ruby/nodes.rb +730 -109
- data/{lib → opal_lib}/opal/ruby/parser.rb +90 -23
- data/opal_lib/opal/ruby/ruby_parser.rb +4862 -0
- data/opal_lib/opal/ruby/ruby_parser.y +1454 -0
- data/opal_lib/opal/version.rb +4 -0
- data/runtime/class.js +359 -0
- data/runtime/debug.js +84 -0
- data/runtime/fs.js +199 -0
- data/runtime/init.js +558 -0
- data/runtime/loader.js +351 -0
- data/runtime/module.js +109 -0
- data/runtime/post.js +10 -0
- data/runtime/pre.js +7 -0
- data/runtime/runtime.js +351 -0
- metadata +88 -175
- data/.gitignore +0 -7
- data/Changelog +0 -31
- data/LICENSE +0 -75
- data/Rakefile +0 -86
- data/gems/core/README.md +0 -14
- data/gems/core/Rakefile +0 -8
- data/gems/core/core.gemspec +0 -13
- data/gems/core/lib/core.rb +0 -34
- data/gems/core/lib/core/class.rb +0 -31
- data/gems/core/lib/core/module.rb +0 -100
- data/gems/core/lib/core/vm.rb +0 -16
- data/gems/core/spec/core/array/append_spec.rb +0 -30
- data/gems/core/spec/core/array/assoc_spec.rb +0 -29
- data/gems/core/spec/core/array/at_spec.rb +0 -37
- data/gems/core/spec/core/array/clear_spec.rb +0 -22
- data/gems/core/spec/core/array/collect_bang_spec.rb +0 -27
- data/gems/core/spec/core/array/collect_spec.rb +0 -27
- data/gems/core/spec/core/array/compact_spec.rb +0 -41
- data/gems/core/spec/core/array/concat_spec.rb +0 -15
- data/gems/core/spec/core/array/constructor_spec.rb +0 -14
- data/gems/core/spec/core/array/each_spec.rb +0 -9
- data/gems/core/spec/core/array/element_reference_spec.rb +0 -4
- data/gems/core/spec/core/array/first_spec.rb +0 -35
- data/gems/core/spec/core/array/include_spec.rb +0 -9
- data/gems/core/spec/core/array/join_spec.rb +0 -6
- data/gems/core/spec/core/array/last_spec.rb +0 -51
- data/gems/core/spec/core/array/length_spec.rb +0 -6
- data/gems/core/spec/core/array/map_spec.rb +0 -33
- data/gems/core/spec/core/array/reverse_spec.rb +0 -6
- data/gems/core/spec/core/builtin_constants/builtin_constants_spec.rb +0 -7
- data/gems/core/spec/core/false/and_spec.rb +0 -10
- data/gems/core/spec/core/false/inspect_spec.rb +0 -6
- data/gems/core/spec/core/false/or_spec.rb +0 -10
- data/gems/core/spec/core/false/to_s_spec.rb +0 -6
- data/gems/core/spec/core/false/xor_spec.rb +0 -10
- data/gems/core/spec/core/file/join_spec.rb +0 -19
- data/gems/core/spec/core/hash/assoc_spec.rb +0 -32
- data/gems/core/spec/core/kernel/instance_eval_spec.rb +0 -0
- data/gems/core/spec/core/kernel/loop_spec.rb +0 -24
- data/gems/core/spec/core/kernel/raise_spec.rb +0 -0
- data/gems/core/spec/core/module/attr_accessor_spec.rb +0 -28
- data/gems/core/spec/core/number/lt_spec.rb +0 -12
- data/gems/core/spec/core/string/sub_spec.rb +0 -24
- data/gems/core/spec/core/true/and_spec.rb +0 -10
- data/gems/core/spec/core/true/inspect_spec.rb +0 -6
- data/gems/core/spec/core/true/or_spec.rb +0 -10
- data/gems/core/spec/core/true/to_s_spec.rb +0 -6
- data/gems/core/spec/core/true/xor_spec.rb +0 -10
- data/gems/core/spec/language/and_spec.rb +0 -61
- data/gems/core/spec/language/array_spec.rb +0 -68
- data/gems/core/spec/language/block_spec.rb +0 -38
- data/gems/core/spec/language/break_spec.rb +0 -36
- data/gems/core/spec/language/case_spec.rb +0 -103
- data/gems/core/spec/language/def_spec.rb +0 -21
- data/gems/core/spec/language/eigenclass_spec.rb +0 -60
- data/gems/core/spec/language/file_spec.rb +0 -13
- data/gems/core/spec/language/fixtures/block.rb +0 -21
- data/gems/core/spec/language/fixtures/super.rb +0 -293
- data/gems/core/spec/language/hash_spec.rb +0 -29
- data/gems/core/spec/language/if_spec.rb +0 -54
- data/gems/core/spec/language/loop_spec.rb +0 -11
- data/gems/core/spec/language/metaclass_spec.rb +0 -21
- data/gems/core/spec/language/method_spec.rb +0 -124
- data/gems/core/spec/language/next_spec.rb +0 -25
- data/gems/core/spec/language/or_spec.rb +0 -34
- data/gems/core/spec/language/redo_spec.rb +0 -24
- data/gems/core/spec/language/regexp_spec.rb +0 -26
- data/gems/core/spec/language/rescue_spec.rb +0 -20
- data/gems/core/spec/language/return_spec.rb +0 -47
- data/gems/core/spec/language/string_spec.rb +0 -25
- data/gems/core/spec/language/super_spec.rb +0 -32
- data/gems/core/spec/language/until_spec.rb +0 -157
- data/gems/core/spec/language/variables_spec.rb +0 -155
- data/gems/core/spec/language/while_spec.rb +0 -163
- data/gems/core/spec/spec_helper.rb +0 -5
- data/gems/core_fs/README.md +0 -19
- data/gems/dev/Rakefile +0 -5
- data/gems/dev/lib/dev.js +0 -99
- data/gems/dev/lib/dev/generator.js +0 -1264
- data/gems/dev/lib/dev/parser.js +0 -979
- data/gems/dev/lib/dev/ruby_parser.js +0 -1088
- data/gems/dev/lib/dev/ruby_parser.y +0 -1267
- data/gems/dev/lib/dev/string_scanner.js +0 -38
- data/gems/dev/tools/racc2js/README.md +0 -39
- data/gems/dev/tools/racc2js/math_parser.js +0 -222
- data/gems/dev/tools/racc2js/math_parser.rb +0 -133
- data/gems/dev/tools/racc2js/math_parser.y +0 -28
- data/gems/dev/tools/racc2js/parser.js +0 -218
- data/gems/dev/tools/racc2js/racc2js.rb +0 -153
- data/gems/json/README.md +0 -4
- data/gems/json/json.gemspec +0 -14
- data/gems/json/lib/json.rb +0 -64
- data/gems/json/lib/json/ext.rb +0 -51
- data/gems/json/lib/json/json2.js +0 -481
- data/gems/ospec/README.md +0 -0
- data/gems/ospec/lib/ospec/autorun.rb +0 -3
- data/gems/ospec/lib/ospec/runner.rb +0 -40
- data/gems/ospec/lib/ospec/runner/formatter/html_formatter.rb +0 -91
- data/gems/ospec/ospec.gemspec +0 -0
- data/gems/rquery/README.md +0 -9
- data/gems/rquery/lib/rquery.rb +0 -10
- data/gems/rquery/lib/rquery/ajax.rb +0 -4
- data/gems/rquery/lib/rquery/css.rb +0 -96
- data/gems/rquery/lib/rquery/document.rb +0 -25
- data/gems/rquery/lib/rquery/element.rb +0 -292
- data/gems/rquery/lib/rquery/event.rb +0 -108
- data/gems/rquery/lib/rquery/jquery.js +0 -8177
- data/gems/rquery/lib/rquery/request.rb +0 -138
- data/gems/rquery/lib/rquery/response.rb +0 -49
- data/gems/rquery/rquery.gemspec +0 -16
- data/lib/opal.js +0 -1597
- data/lib/opal/builder.rb +0 -117
- data/lib/opal/bundle.rb +0 -131
- data/lib/opal/command.rb +0 -11
- data/lib/opal/context/file_system.rb +0 -19
- data/lib/opal/gem.rb +0 -153
- data/lib/opal/ruby/ruby_parser.rb +0 -5170
- data/lib/opal/ruby/ruby_parser.y +0 -1298
- data/opal.gemspec +0 -15
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "FalseClass#^" do
|
|
3
|
-
it "returns false if other is nil or false, otherwise true" do
|
|
4
|
-
(false ^ false).should == false
|
|
5
|
-
(false ^ true).should == true
|
|
6
|
-
(false ^ nil).should == false
|
|
7
|
-
(false ^ "").should == true
|
|
8
|
-
(false ^ 'x').should == true
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "File.join" do
|
|
3
|
-
it "returns an empty string when given no arguments" do
|
|
4
|
-
File.join.should == ""
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
it "when given a single argument returns an equal string" do
|
|
8
|
-
# File.join("").should == ""
|
|
9
|
-
File.join("usr").should == "usr"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "joins parts using File::SEPARATOR" do
|
|
13
|
-
File.join('usr', 'bin').should == 'usr/bin'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "supports any number of arguments" do
|
|
17
|
-
File.join("a", "b", "c", "d").should == "a/b/c/d"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
describe "Hash#assoc" do
|
|
4
|
-
# before each
|
|
5
|
-
$h = {:apple => :green, :orange => :orange, :grape => :green, :banana => :yellow}
|
|
6
|
-
|
|
7
|
-
it "returns an Array if the argument is == to a key of the Hash" do
|
|
8
|
-
$h.assoc(:apple).class.should == Array
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "returns a 2-element Array if the argument is == to a key of the Hash" do
|
|
12
|
-
$h.assoc(:grape).size.should == 2
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "sets the first element of the Array to the located key" do
|
|
16
|
-
$h.assoc(:banana).first.should == :banana
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "sets the last element of the array to the value of the located key" do
|
|
20
|
-
$h.assoc(:banana).last.should == :yellow
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "uses #== to compare the argument to the keys" do
|
|
24
|
-
$h[1.0] = :value
|
|
25
|
-
1.should == 1.0
|
|
26
|
-
$h.assoc(1).should == [1.0, :value]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "returns nil if the argument is not a key of the Hash" do
|
|
30
|
-
$h.assoc(:green).should == nil
|
|
31
|
-
end
|
|
32
|
-
end
|
|
File without changes
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Kernel.loop" do
|
|
3
|
-
it "calls block until it is terminated by a break" do
|
|
4
|
-
i = 0
|
|
5
|
-
loop do
|
|
6
|
-
i = i + 1
|
|
7
|
-
break if i == 10
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
i.should == 10
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "returns value passed to break" do
|
|
14
|
-
loop do
|
|
15
|
-
break 123
|
|
16
|
-
end.should == 123
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "returns nil if no value passed to break" do
|
|
20
|
-
loop do
|
|
21
|
-
break
|
|
22
|
-
end.should == nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
File without changes
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# describe "Module#attr_accessor" do
|
|
3
|
-
# it "creates a getter and setter for each given attribute name" do
|
|
4
|
-
# class AttrAccessorSpec
|
|
5
|
-
# attr_accessor :a, 'b'
|
|
6
|
-
# end
|
|
7
|
-
#
|
|
8
|
-
# o = AttrAccessorSpec.new
|
|
9
|
-
#
|
|
10
|
-
# ['a', 'b'].each do |x|
|
|
11
|
-
# o.respond_to?(x).should == true
|
|
12
|
-
# o.respond_to?("#{x}=").should == true
|
|
13
|
-
# end
|
|
14
|
-
#
|
|
15
|
-
# o.a = "a"
|
|
16
|
-
# o.a.should == "a"
|
|
17
|
-
#
|
|
18
|
-
# o.b = "b"
|
|
19
|
-
# o.b.should == "b"
|
|
20
|
-
# o.a = o.b = nil
|
|
21
|
-
#
|
|
22
|
-
# o.__send__(:a=, "a")
|
|
23
|
-
# o.__send__(:a).should == "a"
|
|
24
|
-
#
|
|
25
|
-
# o.__send__(:b=, "b")
|
|
26
|
-
# o.__send__(:b).should == "b"
|
|
27
|
-
# end
|
|
28
|
-
# end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
-
|
|
3
|
-
describe "String#sub with pattern, replacement" do
|
|
4
|
-
it "returns a copy of self with all occurrences of pattern replaced with replacement" do
|
|
5
|
-
"hello".sub(/[aeiou]/, '*').should == "h*llo"
|
|
6
|
-
"hello".sub(//, ".").should == "hello"
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "ignores a block if supplied" do
|
|
10
|
-
"food".sub(/f/, "g") { "W" }.should == "good"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "supports /i for ignoring case" do
|
|
14
|
-
"Hello".sub(/h/i, "j").should == "jello"
|
|
15
|
-
"hello".sub(/H/i, "j").should == "jello"
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "String#sub with pattern and block" do
|
|
20
|
-
it "returns a copy of self with the first occurrences of pattern replaced with the block's return value" do
|
|
21
|
-
# "hi".sub(/./) { |s| s + ' ' }.should == "h i"
|
|
22
|
-
# "hi!".sub(/(.)(.)/) { |*a| " " }.should == '["hi"]!'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "The '&&' statement" do
|
|
3
|
-
it "short-circuits evaluation at the first condition to be false" do
|
|
4
|
-
x = nil
|
|
5
|
-
true && false && x = 1
|
|
6
|
-
x.should == nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "evaluates to the first condition not to be true" do
|
|
10
|
-
("yes" && 1 && nil && true).should == nil
|
|
11
|
-
("yes" && 1 && false && true).should == false
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "evaluates to the last condition if all are true" do
|
|
15
|
-
("yes" && 1).should == 1
|
|
16
|
-
(1 && "yes").should == "yes"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "evaluates the full set of chained conditions during assignment" do
|
|
20
|
-
x, y = nil
|
|
21
|
-
x = 1 && y = 2
|
|
22
|
-
x.should == 2
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "treats empty expressions as nil" do
|
|
26
|
-
(() && true).should == nil
|
|
27
|
-
(true && ()).should == nil
|
|
28
|
-
(() && ()).should == nil
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "The 'and' statement" do
|
|
33
|
-
it "short-circuits evaluation at the first condition to be false" do
|
|
34
|
-
x = nil
|
|
35
|
-
true and false and x = 1
|
|
36
|
-
x.should == nil
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "evaluates to the first condition not to be true" do
|
|
40
|
-
("yes" and 1 and nil and true).should == nil
|
|
41
|
-
("yes" and 1 and false and true).should == false
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "evaluates to the last condition if all are true" do
|
|
45
|
-
("yes" and 1).should == 1
|
|
46
|
-
(1 and "yes").should == "yes"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "when used in assignment, evaluates and assigns the expressions individually" do
|
|
50
|
-
x = nil
|
|
51
|
-
y = nil
|
|
52
|
-
x = 1 and y = 2
|
|
53
|
-
x.should == 1
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "treats empty expressions as nil" do
|
|
57
|
-
(() and true).should == nil
|
|
58
|
-
(true and ()).should == nil
|
|
59
|
-
(() and ()).should == nil
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "Array literals" do
|
|
3
|
-
it "[] should return a new array populated with the given elements" do
|
|
4
|
-
array = [1, 'a', nil]
|
|
5
|
-
array.class.should == Array
|
|
6
|
-
array[0].should == 1
|
|
7
|
-
array[1].should == "a"
|
|
8
|
-
array[2].should == nil
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "[] treats empty expressions as nil elements" do
|
|
12
|
-
array = [0, (), 2, (), 4]
|
|
13
|
-
array.class.should == Array
|
|
14
|
-
array[0].should == 0
|
|
15
|
-
array[1].should == nil
|
|
16
|
-
array[2].should == 2
|
|
17
|
-
array[3].should == nil
|
|
18
|
-
array[4].should == 4
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "[] accepts a literal hash without curly braces as its only parameter" #do
|
|
22
|
-
# ["foo" => :bar, :baz => 42].should == nil
|
|
23
|
-
# end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "Bareword array literal" do
|
|
27
|
-
it "%w() transforms unquoted barewords into an array" #do
|
|
28
|
-
# a = 3
|
|
29
|
-
# %w(a #{3+a} 3).should
|
|
30
|
-
# end
|
|
31
|
-
|
|
32
|
-
it "%W() transforms unquoted barewords into an array, supporing interpolation" do
|
|
33
|
-
a = 3
|
|
34
|
-
# %W(a #{3+a} 3).should == ["a", "6", "3"]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "%W() always treats interpolated expressions as a single word" do
|
|
38
|
-
a = "hello world"
|
|
39
|
-
# %W(a b c #{a} d e).should == ["a", "b", "c", "hello world", "d", "e"]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "treats consecutive whitespace characters the same as one" do
|
|
43
|
-
# %W(a b c d).should == ["a", "b", "c", "d"]
|
|
44
|
-
# %W(hello
|
|
45
|
-
# world).should == ["hello", "world"]
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "treats whitespace as literals characters when escaped by a backslash" #do
|
|
49
|
-
# %W(a b\ c d e).should == ["a", "b c", "d", "e"]
|
|
50
|
-
# end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "The unpacking splat operator (*)" do
|
|
55
|
-
it "when applied to a literal nested array, unpacks its elements into the containing array" do
|
|
56
|
-
[1, 2, *[3, 4, 5]].should == [1, 2, 3, 4, 5]
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "when applied to a nested referenced array, unpacks its elements into the containing array" do
|
|
60
|
-
splatted_array = [3, 4, 5]
|
|
61
|
-
[1, 2, *splatted_array].should == [1, 2, 3, 4, 5]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "when applied to a value with no other items in the containing array, coerces the passed value to an array and returns it unchanged" do
|
|
65
|
-
splatted_array = [3, 4, 5]
|
|
66
|
-
[*splatted_array].should == splatted_array
|
|
67
|
-
end
|
|
68
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
-
require File.dirname(__FILE__) + '/fixtures/block'
|
|
3
|
-
|
|
4
|
-
describe "A block with a 'rest' arg" do
|
|
5
|
-
it "collects all of the arguments passed to yield" do
|
|
6
|
-
ret = nil
|
|
7
|
-
BlockSpecs::Yield.new.splat(1,2,3) {|*args| ret = args}
|
|
8
|
-
ret.should == [1,2,3]
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "A block with an anonymous 'rest' arg" do
|
|
13
|
-
it "ignores all of the arguments passed to yield" do
|
|
14
|
-
ret = [1].each {|*| }
|
|
15
|
-
ret.should == [1]
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "A block whose arguments are splatted" do
|
|
20
|
-
it "captures the arguments passed to the block in an array" do
|
|
21
|
-
a = []
|
|
22
|
-
BlockSpecs::Yield.new.two_args { |*args| a << args }
|
|
23
|
-
a.should == [[1, 2]]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "captures the array passed to the block in an array" do
|
|
27
|
-
a = []
|
|
28
|
-
BlockSpecs::Yield.new.two_arg_array { |*args| a << args }
|
|
29
|
-
a.should == [[[1, 2]]]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "yields the correct arguments in a nested block" do
|
|
33
|
-
a = []
|
|
34
|
-
BlockSpecs::Yield.new.yield_splat_inside_block { |a1, a2| a << [a1, a2]}
|
|
35
|
-
# a.should == [[1, 0], [2, 1]]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
describe "The break statement" do
|
|
3
|
-
it "ends block execution if used within block" do
|
|
4
|
-
a = []
|
|
5
|
-
lambda {
|
|
6
|
-
a << 1
|
|
7
|
-
break
|
|
8
|
-
a << 2
|
|
9
|
-
}.call
|
|
10
|
-
a.should == [1]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "causes block to return value passed to break" do
|
|
14
|
-
lambda { break 123; 456 }.call.should == 123
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "causes block to return nil if an empty expression passed to break" do
|
|
18
|
-
lambda { break (); 456 }.call.should == nil
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "causes block to return nil if no value passed to break" do
|
|
22
|
-
lambda { break; 456 }.call.should == nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# describe "Executing break from within a block" do
|
|
27
|
-
#
|
|
28
|
-
# it "returns from the invoking singleton method" do
|
|
29
|
-
# obj = Object.new
|
|
30
|
-
# def obj.meth_with_block
|
|
31
|
-
# yield
|
|
32
|
-
# raise "break didn't break from the singleton method"
|
|
33
|
-
# end
|
|
34
|
-
# obj.meth_with_block { break :value }.should == :value
|
|
35
|
-
# end
|
|
36
|
-
# end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# describe "The 'case'-construct" do
|
|
3
|
-
# it "evaluates the body of the when clause matching the case target expression" do
|
|
4
|
-
# case 1
|
|
5
|
-
# when 2; false
|
|
6
|
-
# when 1; true
|
|
7
|
-
# end.should == true
|
|
8
|
-
# end
|
|
9
|
-
#
|
|
10
|
-
# it "evaluates the body of the when clause whose array expression includes the case target expression" do
|
|
11
|
-
# case 2
|
|
12
|
-
# when 3, 4; false
|
|
13
|
-
# when 1, 2; true
|
|
14
|
-
# end.should == true
|
|
15
|
-
# end
|
|
16
|
-
#
|
|
17
|
-
# it "evaluates the body of the when clause in left-to-right order if it's an array expression" do
|
|
18
|
-
# @calls = []
|
|
19
|
-
# def foo; @calls << :foo; end
|
|
20
|
-
# def bar; @calls << :bar; end
|
|
21
|
-
#
|
|
22
|
-
# case true
|
|
23
|
-
# when foo, bar;
|
|
24
|
-
# end
|
|
25
|
-
#
|
|
26
|
-
# @calls.should == [:foo, :bar]
|
|
27
|
-
# end
|
|
28
|
-
#
|
|
29
|
-
# it "evaluates the body of the when clause whose range expression includes the case target expression" do
|
|
30
|
-
# case 5
|
|
31
|
-
# when 21..30; false
|
|
32
|
-
# when 1..20; true
|
|
33
|
-
# end.should == true
|
|
34
|
-
# end
|
|
35
|
-
#
|
|
36
|
-
# it "returns nil when no 'then'-bodies are given" do
|
|
37
|
-
# case "a"
|
|
38
|
-
# when "a"
|
|
39
|
-
# when "b"
|
|
40
|
-
# end.should == nil
|
|
41
|
-
# end
|
|
42
|
-
#
|
|
43
|
-
# it "evaluates the 'else'-body when no other expression matches" do
|
|
44
|
-
# case "c"
|
|
45
|
-
# when "a"; 'foo'
|
|
46
|
-
# when "b"; 'bar'
|
|
47
|
-
# else 'zzz'
|
|
48
|
-
# end.should == 'zzz'
|
|
49
|
-
# end
|
|
50
|
-
#
|
|
51
|
-
# it "returns nil when no expression matches and 'else'-body is empty" do
|
|
52
|
-
# case "c"
|
|
53
|
-
# when "a"; "a"
|
|
54
|
-
# when "b"; "b"
|
|
55
|
-
# else
|
|
56
|
-
# end.should == nil
|
|
57
|
-
# end
|
|
58
|
-
#
|
|
59
|
-
# it "returns 2 when a then body is empty" do
|
|
60
|
-
# case Object.new
|
|
61
|
-
# when Number then
|
|
62
|
-
# 1
|
|
63
|
-
# when String then
|
|
64
|
-
# # ok
|
|
65
|
-
# else
|
|
66
|
-
# 2
|
|
67
|
-
# end.should == 2
|
|
68
|
-
# end
|
|
69
|
-
#
|
|
70
|
-
# it "returns that statement following 'then'" do
|
|
71
|
-
# case "a"
|
|
72
|
-
# when "a" then 'foo'
|
|
73
|
-
# when "b" then 'bar'
|
|
74
|
-
# end.should == 'foo'
|
|
75
|
-
# end
|
|
76
|
-
#
|
|
77
|
-
# it "tests classes with case equality" do
|
|
78
|
-
# case "a"
|
|
79
|
-
# when String
|
|
80
|
-
# 'foo'
|
|
81
|
-
# when Symbol
|
|
82
|
-
# 'bar'
|
|
83
|
-
# end.should == 'foo'
|
|
84
|
-
# end
|
|
85
|
-
#
|
|
86
|
-
# it "tests with matching regexps" do
|
|
87
|
-
# case "hello"
|
|
88
|
-
# when /abc/; false
|
|
89
|
-
# when /^hell/; true
|
|
90
|
-
# end.should == true
|
|
91
|
-
# end
|
|
92
|
-
#
|
|
93
|
-
# it "takes a list of values" do
|
|
94
|
-
# case 'z'
|
|
95
|
-
# when 'a', 'b', 'c', 'd'
|
|
96
|
-
# "foo"
|
|
97
|
-
# when 'x', 'y', 'z'
|
|
98
|
-
# "bar"
|
|
99
|
-
# end.should == "bar"
|
|
100
|
-
# end
|
|
101
|
-
#
|
|
102
|
-
# it "takes an expanded array in addition to a list of values"
|
|
103
|
-
# end
|