opal 0.3.11 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/Gemfile +10 -0
- data/LICENSE +20 -0
- data/README.md +11 -116
- data/Rakefile +126 -0
- data/bin/opal +1 -2
- data/docs/spec_runner.html +16 -0
- data/index.html +434 -0
- data/lib/opal.rb +14 -15
- data/lib/opal/builder.rb +46 -148
- data/lib/opal/command.rb +45 -115
- data/lib/opal/context.rb +139 -78
- data/lib/opal/dependency_builder.rb +34 -0
- data/lib/opal/environment.rb +92 -0
- data/lib/opal/parser/grammar.rb +4915 -0
- data/lib/opal/{parser.y → parser/grammar.y} +430 -284
- data/lib/opal/parser/lexer.rb +1329 -0
- data/lib/opal/parser/parser.rb +1460 -0
- data/lib/opal/parser/scope.rb +140 -0
- data/lib/opal/parser/sexp.rb +17 -0
- data/lib/opal/version.rb +2 -1
- data/opal.gemspec +23 -0
- data/opal.js +3149 -4162
- data/runtime/README.md +25 -0
- data/runtime/corelib/alpha.rb +10 -0
- data/runtime/corelib/array.rb +962 -0
- data/runtime/corelib/basic_object.rb +66 -0
- data/runtime/corelib/boolean.rb +44 -0
- data/runtime/corelib/class.rb +43 -0
- data/runtime/corelib/comparable.rb +25 -0
- data/runtime/corelib/complex.rb +2 -0
- data/runtime/corelib/dir.rb +29 -0
- data/runtime/corelib/enumerable.rb +316 -0
- data/runtime/corelib/enumerator.rb +80 -0
- data/runtime/corelib/error.rb +25 -0
- data/runtime/corelib/file.rb +80 -0
- data/runtime/corelib/hash.rb +503 -0
- data/runtime/corelib/io.rb +44 -0
- data/runtime/corelib/kernel.rb +237 -0
- data/runtime/corelib/load_order +29 -0
- data/runtime/corelib/match_data.rb +37 -0
- data/runtime/corelib/module.rb +171 -0
- data/runtime/corelib/native.rb +50 -0
- data/runtime/corelib/nil_class.rb +47 -0
- data/runtime/corelib/numeric.rb +219 -0
- data/runtime/corelib/object.rb +21 -0
- data/runtime/corelib/proc.rb +42 -0
- data/runtime/corelib/range.rb +38 -0
- data/runtime/corelib/rational.rb +16 -0
- data/runtime/corelib/regexp.rb +63 -0
- data/runtime/corelib/string.rb +185 -0
- data/runtime/corelib/struct.rb +97 -0
- data/runtime/corelib/time.rb +196 -0
- data/runtime/corelib/top_self.rb +7 -0
- data/runtime/gemlib/alpha.rb +5 -0
- data/runtime/gemlib/kernel.rb +17 -0
- data/runtime/gemlib/load_order +2 -0
- data/runtime/kernel/class.js +256 -0
- data/runtime/kernel/debug.js +42 -0
- data/runtime/kernel/init.js +114 -0
- data/runtime/kernel/load_order +5 -0
- data/runtime/kernel/loader.js +151 -0
- data/runtime/kernel/runtime.js +414 -0
- data/runtime/spec/README.md +34 -0
- data/runtime/spec/core/array/allocate_spec.rb +15 -0
- data/runtime/spec/core/array/append_spec.rb +31 -0
- data/runtime/spec/core/array/assoc_spec.rb +29 -0
- data/runtime/spec/core/array/at_spec.rb +38 -0
- data/runtime/spec/core/array/clear_spec.rb +22 -0
- data/runtime/spec/core/array/collect_spec.rb +3 -0
- data/runtime/spec/core/array/compact_spec.rb +42 -0
- data/runtime/spec/core/array/concat_spec.rb +21 -0
- data/runtime/spec/core/array/constructor_spec.rb +24 -0
- data/runtime/spec/core/array/count_spec.rb +11 -0
- data/runtime/spec/core/array/delete_at_spec.rb +31 -0
- data/runtime/spec/core/array/delete_if_spec.rb +24 -0
- data/runtime/spec/core/array/delete_spec.rb +26 -0
- data/runtime/spec/core/array/each_index_spec.rb +33 -0
- data/runtime/spec/core/array/each_spec.rb +11 -0
- data/runtime/spec/core/array/element_reference_spec.rb +136 -0
- data/runtime/spec/core/array/element_set_spec.rb +7 -0
- data/runtime/spec/core/array/empty_spec.rb +10 -0
- data/runtime/spec/core/array/eql_spec.rb +3 -0
- data/runtime/spec/core/array/equal_value_spec.rb +3 -0
- data/runtime/spec/core/array/fetch_spec.rb +26 -0
- data/runtime/spec/core/array/first_spec.rb +54 -0
- data/runtime/spec/core/array/fixtures/classes.rb +8 -0
- data/runtime/spec/core/array/flatten_spec.rb +41 -0
- data/runtime/spec/core/array/include_spec.rb +20 -0
- data/runtime/spec/core/array/insert_spec.rb +59 -0
- data/runtime/spec/core/array/last_spec.rb +57 -0
- data/runtime/spec/core/array/length_spec.rb +3 -0
- data/runtime/spec/core/array/map_spec.rb +3 -0
- data/runtime/spec/core/array/plus_spec.rb +16 -0
- data/runtime/spec/core/array/pop_spec.rb +79 -0
- data/runtime/spec/core/array/push_spec.rb +19 -0
- data/runtime/spec/core/array/rassoc_spec.rb +12 -0
- data/runtime/spec/core/array/reject_spec.rb +54 -0
- data/runtime/spec/core/array/replace_spec.rb +3 -0
- data/runtime/spec/core/array/reverse_each_spec.rb +18 -0
- data/runtime/spec/core/array/reverse_spec.rb +9 -0
- data/runtime/spec/core/array/shared/collect.rb +53 -0
- data/runtime/spec/core/array/shared/eql.rb +19 -0
- data/runtime/spec/core/array/shared/length.rb +6 -0
- data/runtime/spec/core/array/shared/replace.rb +31 -0
- data/runtime/spec/core/class/new_spec.rb +19 -0
- data/runtime/spec/core/enumerable/all_spec.rb +102 -0
- data/runtime/spec/core/enumerable/any_spec.rb +115 -0
- data/runtime/spec/core/enumerable/collect_spec.rb +3 -0
- data/runtime/spec/core/enumerable/count_spec.rb +29 -0
- data/runtime/spec/core/enumerable/detect_spec.rb +3 -0
- data/runtime/spec/core/enumerable/find_spec.rb +3 -0
- data/runtime/spec/core/enumerable/fixtures/classes.rb +26 -0
- data/runtime/spec/core/enumerable/shared/collect.rb +12 -0
- data/runtime/spec/core/enumerable/shared/entries.rb +7 -0
- data/runtime/spec/core/enumerable/shared/find.rb +49 -0
- data/runtime/spec/core/enumerable/to_a_spec.rb +7 -0
- data/runtime/spec/core/false/and_spec.rb +11 -0
- data/runtime/spec/core/false/inspect_spec.rb +7 -0
- data/runtime/spec/core/false/or_spec.rb +11 -0
- data/runtime/spec/core/false/to_s_spec.rb +7 -0
- data/runtime/spec/core/false/xor_spec.rb +11 -0
- data/runtime/spec/core/hash/allocate_spec.rb +15 -0
- data/runtime/spec/core/hash/assoc_spec.rb +29 -0
- data/runtime/spec/core/hash/clear_spec.rb +21 -0
- data/runtime/spec/core/hash/clone_spec.rb +12 -0
- data/runtime/spec/core/hash/default_spec.rb +6 -0
- data/runtime/spec/core/hash/delete_if_spec.rb +15 -0
- data/runtime/spec/core/hash/element_reference_spec.rb +16 -0
- data/runtime/spec/core/hash/element_set_spec.rb +8 -0
- data/runtime/spec/core/hash/new_spec.rb +13 -0
- data/runtime/spec/core/matchdata/to_a_spec.rb +7 -0
- data/runtime/spec/core/nil/and_spec.rb +12 -0
- data/runtime/spec/core/nil/inspect_spec.rb +8 -0
- data/runtime/spec/core/nil/nil_spec.rb +8 -0
- data/runtime/spec/core/nil/or_spec.rb +12 -0
- data/runtime/spec/core/nil/to_a_spec.rb +8 -0
- data/runtime/spec/core/nil/to_f_spec.rb +12 -0
- data/runtime/spec/core/nil/to_i_spec.rb +12 -0
- data/runtime/spec/core/nil/to_s_spec.rb +8 -0
- data/runtime/spec/core/nil/xor_spec.rb +12 -0
- data/runtime/spec/core/numeric/equal_value_spec.rb +11 -0
- data/runtime/spec/core/object/is_a_spec.rb +2 -0
- data/runtime/spec/core/object/shared/kind_of.rb +0 -0
- data/runtime/spec/core/regexp/match_spec.rb +23 -0
- data/runtime/spec/core/regexp/shared/match.rb +11 -0
- data/runtime/spec/core/symbol/to_proc_spec.rb +8 -0
- data/runtime/spec/core/true/and_spec.rb +11 -0
- data/runtime/spec/core/true/inspect_spec.rb +7 -0
- data/runtime/spec/core/true/or_spec.rb +11 -0
- data/runtime/spec/core/true/to_s_spec.rb +7 -0
- data/runtime/spec/core/true/xor_spec.rb +11 -0
- data/runtime/spec/language/alias_spec.rb +25 -0
- data/runtime/spec/language/and_spec.rb +62 -0
- data/runtime/spec/language/array_spec.rb +68 -0
- data/runtime/spec/language/block_spec.rb +105 -0
- data/runtime/spec/language/break_spec.rb +49 -0
- data/runtime/spec/language/case_spec.rb +165 -0
- data/runtime/spec/language/defined_spec.rb +80 -0
- data/runtime/spec/language/ensure_spec.rb +82 -0
- data/runtime/spec/language/fixtures/block.rb +19 -0
- data/runtime/spec/language/fixtures/break.rb +39 -0
- data/runtime/spec/language/fixtures/defined.rb +9 -0
- data/runtime/spec/language/fixtures/ensure.rb +37 -0
- data/runtime/spec/language/fixtures/next.rb +46 -0
- data/runtime/spec/language/fixtures/send.rb +36 -0
- data/runtime/spec/language/fixtures/super.rb +43 -0
- data/runtime/spec/language/hash_spec.rb +43 -0
- data/runtime/spec/language/if_spec.rb +278 -0
- data/runtime/spec/language/loop_spec.rb +32 -0
- data/runtime/spec/language/next_spec.rb +128 -0
- data/runtime/spec/language/or_spec.rb +65 -0
- data/runtime/spec/language/predefined_spec.rb +21 -0
- data/runtime/spec/language/regexp/interpolation_spec.rb +9 -0
- data/runtime/spec/language/regexp_spec.rb +7 -0
- data/runtime/spec/language/send_spec.rb +105 -0
- data/runtime/spec/language/string_spec.rb +4 -0
- data/runtime/spec/language/super_spec.rb +18 -0
- data/runtime/spec/language/symbol_spec.rb +41 -0
- data/runtime/spec/language/undef_spec.rb +16 -0
- data/runtime/spec/language/unless_spec.rb +44 -0
- data/runtime/spec/language/until_spec.rb +137 -0
- data/runtime/spec/language/variables_spec.rb +28 -0
- data/runtime/spec/language/versions/hash_1.9.rb +20 -0
- data/runtime/spec/language/while_spec.rb +175 -0
- data/runtime/spec/library/stringscanner/scan_spec.rb +36 -0
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +49 -0
- data/runtime/spec/opal/opal/defined_spec.rb +15 -0
- data/runtime/spec/opal/opal/function_spec.rb +11 -0
- data/runtime/spec/opal/opal/native_spec.rb +16 -0
- data/runtime/spec/opal/opal/null_spec.rb +10 -0
- data/runtime/spec/opal/opal/number_spec.rb +11 -0
- data/runtime/spec/opal/opal/object_spec.rb +16 -0
- data/runtime/spec/opal/opal/string_spec.rb +11 -0
- data/runtime/spec/opal/opal/typeof_spec.rb +9 -0
- data/runtime/spec/opal/opal/undefined_spec.rb +10 -0
- data/runtime/spec/opal/true/case_compare_spec.rb +12 -0
- data/runtime/spec/opal/true/class_spec.rb +10 -0
- data/runtime/spec/spec_helper.rb +25 -0
- data/runtime/stdlib/base64.rb +91 -0
- data/runtime/stdlib/date.rb +4 -0
- data/{stdlib → runtime/stdlib}/dev.rb +0 -0
- data/runtime/stdlib/forwardable.rb +33 -0
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +6 -0
- data/{stdlib → runtime/stdlib}/racc/parser.rb +0 -0
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +17 -0
- data/runtime/stdlib/strscan.rb +53 -0
- data/runtime/stdlib/uri.rb +111 -0
- data/runtime/stdlib/uri/common.rb +1014 -0
- data/runtime/stdlib/uri/ftp.rb +261 -0
- data/runtime/stdlib/uri/generic.rb +1599 -0
- data/runtime/stdlib/uri/http.rb +106 -0
- data/runtime/stdlib/uri/https.rb +22 -0
- data/runtime/stdlib/uri/ldap.rb +260 -0
- data/runtime/stdlib/uri/ldaps.rb +20 -0
- data/runtime/stdlib/uri/mailto.rb +280 -0
- data/spec/builder/build_source_spec.rb +52 -0
- data/spec/builder/fixtures/build_source/adam.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/spec/builder/fixtures/build_source/beynon.rb +0 -0
- data/spec/builder/fixtures/build_source/charles.js +0 -0
- data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/x.js +0 -0
- data/spec/builder/fixtures/build_source/foo/y.js +0 -0
- data/spec/builder/output_path_spec.rb +50 -0
- data/spec/grammar/alias_spec.rb +26 -0
- data/spec/grammar/and_spec.rb +13 -0
- data/spec/grammar/array_spec.rb +22 -0
- data/spec/grammar/attrasgn_spec.rb +28 -0
- data/spec/grammar/begin_spec.rb +38 -0
- data/spec/grammar/block_spec.rb +12 -0
- data/spec/grammar/break_spec.rb +17 -0
- data/spec/grammar/call_spec.rb +58 -0
- data/spec/grammar/class_spec.rb +35 -0
- data/spec/grammar/const_spec.rb +13 -0
- data/spec/grammar/cvar_spec.rb +11 -0
- data/spec/grammar/def_spec.rb +60 -0
- data/spec/grammar/false_spec.rb +17 -0
- data/spec/grammar/file_spec.rb +7 -0
- data/spec/grammar/gvar_spec.rb +13 -0
- data/spec/grammar/hash_spec.rb +17 -0
- data/spec/grammar/iasgn_spec.rb +9 -0
- data/spec/grammar/if_spec.rb +26 -0
- data/spec/grammar/iter_spec.rb +59 -0
- data/spec/grammar/ivar_spec.rb +9 -0
- data/spec/grammar/lasgn_spec.rb +8 -0
- data/spec/grammar/line_spec.rb +8 -0
- data/spec/grammar/lvar_spec.rb +38 -0
- data/spec/grammar/module_spec.rb +27 -0
- data/spec/grammar/nil_spec.rb +17 -0
- data/spec/grammar/not_spec.rb +27 -0
- data/spec/grammar/op_asgn1_spec.rb +23 -0
- data/spec/grammar/op_asgn2_spec.rb +23 -0
- data/spec/grammar/or_spec.rb +13 -0
- data/spec/grammar/return_spec.rb +17 -0
- data/spec/grammar/sclass_spec.rb +20 -0
- data/spec/grammar/self_spec.rb +17 -0
- data/spec/grammar/str_spec.rb +96 -0
- data/spec/grammar/super_spec.rb +20 -0
- data/spec/grammar/true_spec.rb +17 -0
- data/spec/grammar/undef_spec.rb +15 -0
- data/spec/grammar/unless_spec.rb +13 -0
- data/spec/grammar/while_spec.rb +15 -0
- data/spec/grammar/xstr_spec.rb +116 -0
- data/spec/grammar/yield_spec.rb +20 -0
- data/spec/spec_helper.rb +9 -0
- metadata +346 -21
- data/lib/opal/bundle.rb +0 -34
- data/lib/opal/lexer.rb +0 -902
- data/lib/opal/nodes.rb +0 -2150
- data/lib/opal/parser.rb +0 -4894
- data/lib/opal/rake/bundle_task.rb +0 -63
- data/opal-parser.js +0 -8343
- data/stdlib/strscan.rb +0 -52
- data/templates/init/Rakefile +0 -7
- data/templates/init/index.html +0 -17
- data/templates/init/lib/__NAME__.rb +0 -2
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Basic assignment" do
|
4
|
+
it "allows the rhs to be assigned to the lhs" do
|
5
|
+
a = nil
|
6
|
+
a.should == nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it "assigns nil to lhs when rhs is an empty expression" do
|
10
|
+
a = ()
|
11
|
+
a.should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "assigns [] to lhs when rhs is an empty splat expression" do
|
15
|
+
a = *()
|
16
|
+
a.should == []
|
17
|
+
end
|
18
|
+
|
19
|
+
it "allows the assignment of the rhs to the lhs using the rhs splat operator" do
|
20
|
+
a = *nil; a.should == []
|
21
|
+
a = *1; a.should == [1]
|
22
|
+
a = *[]; a.should == []
|
23
|
+
a = *[1]; a.should == [1]
|
24
|
+
a = *[nil]; a.should == [nil]
|
25
|
+
a = *[[]]; a.should == [[]]
|
26
|
+
a = *[1,2]; a.should == [1,2]
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Hash literal" do
|
4
|
+
describe "new-style hash syntax" do
|
5
|
+
it "constructs a new hash with the given elements" do
|
6
|
+
{foo: 123}.should == {:foo => 123}
|
7
|
+
{rbx: :cool, specs: 'fail_sometimes'}.should == {:rbx => :cool, :specs => 'fail_sometimes'}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "ignores a hanging comma" do
|
11
|
+
{foo: 123,}.should == {:foo => 123}
|
12
|
+
{rbx: :cool, specs: 'fail_sometimes',}.should == {:rbx => :cool, :specs => 'fail_sometimes'}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can mix and match syntax styles" do
|
16
|
+
{rbx: :cool, :specs => 'fail_sometimes'}.should == {:rbx => :cool, :specs => 'fail_sometimes'}
|
17
|
+
{'rbx' => :cool, specs: 'fail_sometimes'}.should == {'rbx' => :cool, :specs => 'fail_sometimes'}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "The while expression" do
|
4
|
+
it "runs while the expression is true" do
|
5
|
+
i = 0
|
6
|
+
while i < 3
|
7
|
+
i += 1
|
8
|
+
end
|
9
|
+
i.should == 3
|
10
|
+
end
|
11
|
+
|
12
|
+
it "optionally takes a 'do' after the expression" do
|
13
|
+
i = 0
|
14
|
+
while i < 3 do
|
15
|
+
i += 1
|
16
|
+
end
|
17
|
+
|
18
|
+
i.should == 3
|
19
|
+
end
|
20
|
+
|
21
|
+
it "allows body begin on the same line if do is used" do
|
22
|
+
i = 0
|
23
|
+
while i < 3 do i += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
i.should == 3
|
27
|
+
end
|
28
|
+
|
29
|
+
it "executes code in containing variable scope" do
|
30
|
+
i = 0
|
31
|
+
while i != 1
|
32
|
+
a = 123
|
33
|
+
i = 1
|
34
|
+
end
|
35
|
+
|
36
|
+
a.should == 123
|
37
|
+
end
|
38
|
+
|
39
|
+
it "exectues code in containing variable scope with 'do'" do
|
40
|
+
i = 0
|
41
|
+
while i != 1 do
|
42
|
+
a = 123
|
43
|
+
i = 1
|
44
|
+
end
|
45
|
+
|
46
|
+
a.should == 123
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns nil is ended when condition became false" do
|
50
|
+
i = 0
|
51
|
+
while i < 3
|
52
|
+
i += 1
|
53
|
+
end.should == nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not evaluate the body if expression is empty" do
|
57
|
+
a = []
|
58
|
+
while ()
|
59
|
+
a << :body_evaluated
|
60
|
+
end
|
61
|
+
a.should == []
|
62
|
+
end
|
63
|
+
|
64
|
+
it "stops running body if interrupted by break" do
|
65
|
+
i = 0
|
66
|
+
while i < 10
|
67
|
+
i += 1
|
68
|
+
break if i > 5
|
69
|
+
end
|
70
|
+
i.should == 6
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns value passed to break if interrupted by break" do
|
74
|
+
while true
|
75
|
+
break 123
|
76
|
+
end.should == 123
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns nil if interrupted by break with no arguments" do
|
80
|
+
while true
|
81
|
+
break
|
82
|
+
end.should == nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "skips to end of body with next" do
|
86
|
+
a = []
|
87
|
+
i = 0
|
88
|
+
while (i+=1)<5
|
89
|
+
next if i==3
|
90
|
+
a << i
|
91
|
+
end
|
92
|
+
a.should == [1, 2, 4]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "restarts the current iteration without reevaluating condition with redo" do
|
96
|
+
a = []
|
97
|
+
i = 0
|
98
|
+
j = 0
|
99
|
+
while (i+=1) <3
|
100
|
+
a << i
|
101
|
+
j+=1
|
102
|
+
redo if j<3
|
103
|
+
end
|
104
|
+
a.should == [1, 1, 1, 2]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "The while modifier" do
|
109
|
+
it "runs preceding statement while the condition is true" do
|
110
|
+
i = 0
|
111
|
+
i += 1 while i < 3
|
112
|
+
i.should == 3
|
113
|
+
end
|
114
|
+
|
115
|
+
it "evaluates condition before statement execution" do
|
116
|
+
a = []
|
117
|
+
i = 0
|
118
|
+
a << i while (i+=1) < 3
|
119
|
+
a.should == [1, 2]
|
120
|
+
end
|
121
|
+
|
122
|
+
it "does not run preceding statement if the condition is false" do
|
123
|
+
i = 0
|
124
|
+
i += 1 while false
|
125
|
+
i.should == 0
|
126
|
+
end
|
127
|
+
|
128
|
+
it "does not run preceding statement if the condition is empty" do
|
129
|
+
i = 0
|
130
|
+
i += 1 while ()
|
131
|
+
i.should == 0
|
132
|
+
end
|
133
|
+
|
134
|
+
it "returns nil if ended when condition became false" do
|
135
|
+
i = 0
|
136
|
+
(i += 1 while i<10).should == nil
|
137
|
+
end
|
138
|
+
|
139
|
+
it "returns value passed to break if interrupted by break" do
|
140
|
+
(break 123 while true).should == 123
|
141
|
+
end
|
142
|
+
|
143
|
+
it "returns nil if interrupted by break with no arguments" do
|
144
|
+
(break while true).should == nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "The while modifier with begin .. end block" do
|
149
|
+
it "runs block while the expression is true" do
|
150
|
+
i = 0
|
151
|
+
begin
|
152
|
+
i += 1
|
153
|
+
end while i < 3
|
154
|
+
|
155
|
+
i.should == 3
|
156
|
+
end
|
157
|
+
|
158
|
+
it "stops running block if interrupted by break" do
|
159
|
+
i = 0
|
160
|
+
begin
|
161
|
+
i += 1
|
162
|
+
break if i > 5
|
163
|
+
end while i < 10
|
164
|
+
|
165
|
+
i.should == 6
|
166
|
+
end
|
167
|
+
|
168
|
+
it "returns values passed to break if interrupted by break" do
|
169
|
+
(begin; break 123; end while true).should == 123
|
170
|
+
end
|
171
|
+
|
172
|
+
it "returns nil if interrupted by break with no arguments" do
|
173
|
+
(begin; break; end while true).should == nil
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
#require 'strscan'
|
3
|
+
|
4
|
+
describe "StringScanner#scan" do
|
5
|
+
before :each do
|
6
|
+
@s = StringScanner.new("This is a test")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the matched string" do
|
10
|
+
@s.scan(/\w+/).should == "This"
|
11
|
+
@s.scan(/.../).should == " is"
|
12
|
+
@s.scan(//).should == ""
|
13
|
+
@s.scan(/\s+/).should == " "
|
14
|
+
end
|
15
|
+
|
16
|
+
it "treats ^ as matching from the beginning of the current position" do
|
17
|
+
@s.scan(/\w+/).should == "This"
|
18
|
+
@s.scan(/^\d/).should be_nil
|
19
|
+
@s.scan(/^\s/).should == " "
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil if there's no match" do
|
23
|
+
@s.scan(/\d/).should == nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns nil when there is no more to scan" do
|
27
|
+
@s.scan(/[\w\s]+/).should == "This is a test"
|
28
|
+
@s.scan(/\w+/).should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns an empty string when the pattern matches empty" do
|
32
|
+
@s.scan(/.*/).should == "This is a test"
|
33
|
+
@s.scan(/.*/).should == ""
|
34
|
+
@s.scan(/./).should be_nil
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
#require 'forwardable'
|
3
|
+
|
4
|
+
#class ForwardableTest
|
5
|
+
#extend Forwardable
|
6
|
+
|
7
|
+
#def initialize
|
8
|
+
#@some_ivar = ['a', 'b', 'c']
|
9
|
+
#@blah = [1, 2, 3, 4, 5, 6]
|
10
|
+
#end
|
11
|
+
|
12
|
+
#def foo
|
13
|
+
#@some_ivar
|
14
|
+
#end
|
15
|
+
|
16
|
+
#def wizz
|
17
|
+
#@blah
|
18
|
+
#end
|
19
|
+
|
20
|
+
#def_instance_delegator :@some_ivar, :length
|
21
|
+
#def_instance_delegator :@blah, :length, :blah
|
22
|
+
|
23
|
+
#def_instance_delegator :foo, :reverse
|
24
|
+
#def_instance_delegator :wizz, :reverse, :fizz
|
25
|
+
#end
|
26
|
+
|
27
|
+
describe "Forwardable#def_instance_delegator" do
|
28
|
+
before do
|
29
|
+
@tester = ForwardableTest.new
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should define new instance methods" do
|
33
|
+
@tester.respond_to?(:length).should be_true
|
34
|
+
@tester.respond_to?(:blah).should be_true
|
35
|
+
|
36
|
+
@tester.respond_to?(:reverse).should be_true
|
37
|
+
@tester.respond_to?(:fizz).should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should forward method calls to given ivars" do
|
41
|
+
@tester.length.should == 3
|
42
|
+
@tester.blah.should == 6
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should forward method calls to given accessors" do
|
46
|
+
@tester.reverse.should == ['c', 'b', 'a']
|
47
|
+
@tester.fizz.should == [6, 5, 4, 3, 2, 1]
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.defined?" do
|
4
|
+
it "should return nil when given `undefined`" do
|
5
|
+
Opal.defined?(`undefined`).should be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return the type of object for anything else" do
|
9
|
+
Opal.defined?("wow").should == 'string'
|
10
|
+
Opal.defined?(42).should == 'number'
|
11
|
+
Opal.defined?(Object.new).should == 'object'
|
12
|
+
Opal.defined?(nil).should == 'object'
|
13
|
+
Opal.defined?(`null`).should == 'object'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.function?" do
|
4
|
+
it "returns true if the object is a function, false otherwise" do
|
5
|
+
Opal.function?(proc do; end).should be_true
|
6
|
+
Opal.function?(`function(){}`).should be_true
|
7
|
+
Opal.function?(nil).should be_false
|
8
|
+
Opal.function?(Object.new).should be_false
|
9
|
+
Opal.function?(Proc).should be_false
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.native?" do
|
4
|
+
it "returns true if the object is not a ruby object, false if it is" do
|
5
|
+
Opal.native?(`{}`).should be_true
|
6
|
+
Opal.native?(`new Object()`).should be_true
|
7
|
+
Opal.native?(`null`).should be_true
|
8
|
+
Opal.native?(`undefined`).should be_true
|
9
|
+
|
10
|
+
Opal.native?(Object.new).should be_false
|
11
|
+
Opal.native?([1, 2, 3]).should be_false
|
12
|
+
Opal.native?(true).should be_false
|
13
|
+
Opal.native?(false).should be_false
|
14
|
+
Opal.native?(nil).should be_false
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.null?" do
|
4
|
+
it "returns true if the given object is null, false otherwise" do
|
5
|
+
Opal.null?(`null`).should be_true
|
6
|
+
Opal.null?(`undefined`).should be_false
|
7
|
+
Opal.null?(nil).should be_false
|
8
|
+
Opal.null?(Object.new).should be_false
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.number?" do
|
4
|
+
it "returns true if the object is a number" do
|
5
|
+
Opal.number?(42).should be_true
|
6
|
+
Opal.number?(Object.new).should be_false
|
7
|
+
Opal.number?(nil).should be_false
|
8
|
+
Opal.number?(`null`).should be_false
|
9
|
+
Opal.number?(`undefined`).should be_false
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.object?" do
|
4
|
+
it "returns true if the object is a ruby object, false otherwise" do
|
5
|
+
Opal.object?(Object.new).should be_true
|
6
|
+
Opal.object?([1, 2, 3]).should be_true
|
7
|
+
Opal.object?(true).should be_true
|
8
|
+
Opal.object?(false).should be_true
|
9
|
+
Opal.object?(nil).should be_true
|
10
|
+
|
11
|
+
Opal.object?(`{}`).should be_false
|
12
|
+
Opal.object?(`new Object()`).should be_false
|
13
|
+
Opal.object?(`null`).should be_false
|
14
|
+
Opal.object?(`undefined`).should be_false
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.string?" do
|
4
|
+
it "returns true if the object is a string" do
|
5
|
+
Opal.string?("foo").should be_true
|
6
|
+
Opal.string?(Object.new).should be_false
|
7
|
+
Opal.string?(nil).should be_false
|
8
|
+
Opal.string?(`null`).should be_false
|
9
|
+
Opal.string?(`undefined`).should be_false
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.typeof" do
|
4
|
+
it "returns the javascript type of the object" do
|
5
|
+
Opal.typeof(`null`).should == 'object'
|
6
|
+
Opal.typeof(`undefined`).should == 'undefined'
|
7
|
+
Opal.typeof(nil).should == 'object'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Opal.undefined?" do
|
4
|
+
it "returns true if the arg is undefined, false otherwise" do
|
5
|
+
Opal.undefined?(`undefined`).should be_true
|
6
|
+
Opal.undefined?(Object.new).should be_false
|
7
|
+
Opal.undefined?(nil).should be_false
|
8
|
+
Opal.undefined?(`null`).should be_false
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "TrueClass#===" do
|
4
|
+
it "returns true when the given object is the literal 'true'" do
|
5
|
+
(TrueClass === true).should == true
|
6
|
+
(TrueClass === false).should == false
|
7
|
+
(TrueClass === nil).should == false
|
8
|
+
(TrueClass === "").should == false
|
9
|
+
(TrueClass === 'x').should == false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|