opal 0.3.19 → 0.3.20
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 +3 -1
- data/Gemfile +3 -2
- data/README.md +304 -48
- data/Rakefile +1 -2
- data/core/alpha.rb +2 -1
- data/core/array.rb +92 -96
- data/core/basic_object.rb +1 -10
- data/core/boolean.rb +6 -18
- data/core/class.rb +9 -10
- data/core/comparable.rb +1 -1
- data/core/enumerable.rb +11 -11
- data/core/enumerator.rb +2 -10
- data/core/error.rb +16 -31
- data/core/hash.rb +32 -36
- data/core/json.rb +50 -0
- data/core/kernel.rb +48 -57
- data/core/load_order +3 -5
- data/core/module.rb +37 -35
- data/core/nil_class.rb +4 -0
- data/core/numeric.rb +10 -30
- data/core/proc.rb +1 -1
- data/core/range.rb +3 -4
- data/core/regexp.rb +21 -6
- data/core/runtime.js +278 -370
- data/core/string.rb +21 -37
- data/core/struct.rb +11 -3
- data/core/time.rb +44 -37
- data/lib/opal.rb +3 -3
- data/lib/opal/builder.rb +48 -27
- data/lib/opal/builder_task.rb +3 -20
- data/lib/opal/grammar.rb +18 -13
- data/lib/opal/grammar.y +7 -4
- data/lib/opal/parser.rb +290 -199
- data/lib/opal/scope.rb +187 -176
- data/lib/opal/version.rb +1 -1
- data/test/core/kernel/define_singleton_method_spec.rb +21 -0
- data/test/core/time/at_spec.rb +7 -0
- data/test/core/time/day_spec.rb +5 -0
- data/test/core/time/friday_spec.rb +9 -0
- data/test/core/time/hour_spec.rb +5 -0
- data/test/core/time/min_spec.rb +5 -0
- data/test/core/time/monday_spec.rb +9 -0
- data/test/core/time/month_spec.rb +5 -0
- data/test/core/time/now_spec.rb +5 -0
- data/test/core/time/saturday_spec.rb +9 -0
- data/test/index.html +2 -1
- data/test/language/singleton_class_spec.rb +0 -16
- data/test/opal/array/to_json_spec.rb +7 -0
- data/test/opal/boolean/singleton_class_spec.rb +9 -0
- data/test/opal/boolean/to_json_spec.rb +9 -0
- data/test/opal/hash/to_json_spec.rb +9 -0
- data/test/opal/json/parse_spec.rb +31 -0
- data/test/opal/kernel/to_json_spec.rb +5 -0
- data/test/opal/nil/to_json_spec.rb +5 -0
- data/test/opal/numeric/to_json_spec.rb +6 -0
- data/test/opal/runtime/call_spec.rb +16 -0
- data/test/opal/runtime/defined_spec.rb +11 -0
- data/test/opal/runtime/super_spec.rb +16 -0
- data/test/opal/string/to_json_spec.rb +6 -0
- data/test/spec_helper.rb +1 -3
- metadata +48 -15
- data/core/dir.rb +0 -89
- data/core/file.rb +0 -85
- data/core/match_data.rb +0 -35
- data/core/rational.rb +0 -16
- data/test/core/file/expand_path_spec.rb +0 -20
data/test/index.html
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
<!doctype html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title
|
4
|
+
<title>Opal corelib and runtime specs</title>
|
5
5
|
</head>
|
6
6
|
<body>
|
7
7
|
<script type="text/javascript" src="../build/opal.js"></script>
|
8
|
+
<script type="text/javascript" src="../build/opal-dom.js"></script>
|
8
9
|
<script type="text/javascript" src="../build/opal-spec.js"></script>
|
9
10
|
<script type="text/javascript" src="../build/opal.specs.js"></script>
|
10
11
|
</body>
|
@@ -1,24 +1,8 @@
|
|
1
1
|
describe "A singleton class" do
|
2
|
-
it "is TrueClass for true" do
|
3
|
-
true.singleton_class.should == TrueClass
|
4
|
-
end
|
5
|
-
|
6
|
-
it "is FalseClass for false" do
|
7
|
-
false.singleton_class.should == FalseClass
|
8
|
-
end
|
9
|
-
|
10
2
|
it "is NilClass for nil" do
|
11
3
|
nil.singleton_class.should == NilClass
|
12
4
|
end
|
13
5
|
|
14
|
-
it "raises a TypeError for Fixnum's" do
|
15
|
-
lambda { 1.singleton_class }.should raise_error(TypeError)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "raises a TypeError for synbols" do
|
19
|
-
lambda { :symbol.singleton_class }.should raise_error(TypeError)
|
20
|
-
end
|
21
|
-
|
22
6
|
it "is a singleton Class instance" do
|
23
7
|
o = mock('x')
|
24
8
|
o.singleton_class.should be_kind_of(Class)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Hash#to_json" do
|
2
|
+
it "returns a string of all key and value pairs" do
|
3
|
+
{}.to_json.should == "{}"
|
4
|
+
{"a" => 1, "b" => 2}.to_json.should == '{"a": 1, "b": 2}'
|
5
|
+
|
6
|
+
hash = {"a" => 1, "b" => false, "c" => nil, "d" => true}
|
7
|
+
JSON.parse(hash.to_json).should == hash
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
describe "JSON.parse" do
|
2
|
+
it "parses null into nil" do
|
3
|
+
JSON.parse("null").should be_nil
|
4
|
+
end
|
5
|
+
|
6
|
+
it "parses true into true" do
|
7
|
+
JSON.parse("true").should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "parses false into false" do
|
11
|
+
JSON.parse("false").should be_false
|
12
|
+
end
|
13
|
+
|
14
|
+
it "parses numbers into numbers" do
|
15
|
+
JSON.parse("42").should == 42
|
16
|
+
JSON.parse("3.142").should == 3.142
|
17
|
+
end
|
18
|
+
|
19
|
+
it "parses arrays into ruby arrays" do
|
20
|
+
JSON.parse("[]").should == []
|
21
|
+
JSON.parse("[1, 2, 3]").should == [1, 2, 3]
|
22
|
+
JSON.parse("[[1, 2, 3], [4, 5]]").should == [[1, 2, 3], [4, 5]]
|
23
|
+
JSON.parse("[null, true, false]").should == [nil, true, false]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "parses object literals into ruby hashes" do
|
27
|
+
JSON.parse("{}").should == {}
|
28
|
+
JSON.parse('{"a": "b"}').should == {"a" => "b"}
|
29
|
+
JSON.parse('{"a": null, "b": 10, "c": [true, false]}').should == {"a" => nil, "b" => 10, "c" => [true, false]}
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class OpalMethodCallingSpec
|
2
|
+
def foo(a)
|
3
|
+
42 + a
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.bar
|
7
|
+
3.142
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Calling methods" do
|
12
|
+
it "should support '::' syntax" do
|
13
|
+
OpalMethodCallingSpec::bar.should == 3.142
|
14
|
+
OpalMethodCallingSpec.new.foo(10).should == 52
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
describe "The defined? keyword for x-strings" do
|
2
|
+
it "returns true for defined variables" do
|
3
|
+
`var SomeClass = {}`
|
4
|
+
defined?(`{}`).should be_true
|
5
|
+
defined?(`SomeClass`).should be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
it "retuens false for undefined variables" do
|
9
|
+
defined?(`SomeBadVar`).should be_false
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class OpalSuperDefineMethodSpec
|
2
|
+
def foo
|
3
|
+
"bar"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "Super keyword" do
|
8
|
+
it "works with methods defined with define_singleton_method" do
|
9
|
+
a = OpalSuperDefineMethodSpec.new
|
10
|
+
a.define_singleton_method(:foo) do
|
11
|
+
super + " baz"
|
12
|
+
end
|
13
|
+
|
14
|
+
a.foo.should == "bar baz"
|
15
|
+
end
|
16
|
+
end
|
data/test/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.20
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby runtime and core library for javascript.
|
15
15
|
email: adam@adambeynon.com
|
@@ -30,22 +30,19 @@ files:
|
|
30
30
|
- core/boolean.rb
|
31
31
|
- core/class.rb
|
32
32
|
- core/comparable.rb
|
33
|
-
- core/dir.rb
|
34
33
|
- core/enumerable.rb
|
35
34
|
- core/enumerator.rb
|
36
35
|
- core/error.rb
|
37
|
-
- core/file.rb
|
38
36
|
- core/hash.rb
|
37
|
+
- core/json.rb
|
39
38
|
- core/kernel.rb
|
40
39
|
- core/load_order
|
41
|
-
- core/match_data.rb
|
42
40
|
- core/module.rb
|
43
41
|
- core/nil_class.rb
|
44
42
|
- core/numeric.rb
|
45
43
|
- core/object.rb
|
46
44
|
- core/proc.rb
|
47
45
|
- core/range.rb
|
48
|
-
- core/rational.rb
|
49
46
|
- core/regexp.rb
|
50
47
|
- core/runtime.js
|
51
48
|
- core/string.rb
|
@@ -200,7 +197,6 @@ files:
|
|
200
197
|
- test/core/false/or_spec.rb
|
201
198
|
- test/core/false/to_s_spec.rb
|
202
199
|
- test/core/false/xor_spec.rb
|
203
|
-
- test/core/file/expand_path_spec.rb
|
204
200
|
- test/core/hash/allocate_spec.rb
|
205
201
|
- test/core/hash/assoc_spec.rb
|
206
202
|
- test/core/hash/clear_spec.rb
|
@@ -239,6 +235,7 @@ files:
|
|
239
235
|
- test/core/hash/value_spec.rb
|
240
236
|
- test/core/hash/values_at_spec.rb
|
241
237
|
- test/core/hash/values_spec.rb
|
238
|
+
- test/core/kernel/define_singleton_method_spec.rb
|
242
239
|
- test/core/kernel/eql_spec.rb
|
243
240
|
- test/core/kernel/equal_value_spec.rb
|
244
241
|
- test/core/kernel/loop_spec.rb
|
@@ -303,6 +300,15 @@ files:
|
|
303
300
|
- test/core/string/to_sym_spec.rb
|
304
301
|
- test/core/string/upcase_spec.rb
|
305
302
|
- test/core/symbol/to_proc_spec.rb
|
303
|
+
- test/core/time/at_spec.rb
|
304
|
+
- test/core/time/day_spec.rb
|
305
|
+
- test/core/time/friday_spec.rb
|
306
|
+
- test/core/time/hour_spec.rb
|
307
|
+
- test/core/time/min_spec.rb
|
308
|
+
- test/core/time/monday_spec.rb
|
309
|
+
- test/core/time/month_spec.rb
|
310
|
+
- test/core/time/now_spec.rb
|
311
|
+
- test/core/time/saturday_spec.rb
|
306
312
|
- test/core/true/and_spec.rb
|
307
313
|
- test/core/true/inspect_spec.rb
|
308
314
|
- test/core/true/or_spec.rb
|
@@ -338,12 +344,24 @@ files:
|
|
338
344
|
- test/language/while_spec.rb
|
339
345
|
- test/language/yield_spec.rb
|
340
346
|
- test/opal/array/subclassing_spec.rb
|
347
|
+
- test/opal/array/to_json_spec.rb
|
348
|
+
- test/opal/boolean/singleton_class_spec.rb
|
349
|
+
- test/opal/boolean/to_json_spec.rb
|
341
350
|
- test/opal/class/bridge_class_spec.rb
|
342
351
|
- test/opal/exception/subclassing_spec.rb
|
352
|
+
- test/opal/hash/to_json_spec.rb
|
353
|
+
- test/opal/json/parse_spec.rb
|
354
|
+
- test/opal/kernel/to_json_spec.rb
|
355
|
+
- test/opal/nil/to_json_spec.rb
|
356
|
+
- test/opal/numeric/to_json_spec.rb
|
343
357
|
- test/opal/runtime/_methods_spec.rb
|
358
|
+
- test/opal/runtime/call_spec.rb
|
344
359
|
- test/opal/runtime/class_hierarchy_spec.rb
|
345
360
|
- test/opal/runtime/def_spec.rb
|
361
|
+
- test/opal/runtime/defined_spec.rb
|
362
|
+
- test/opal/runtime/super_spec.rb
|
346
363
|
- test/opal/string/subclassing_spec.rb
|
364
|
+
- test/opal/string/to_json_spec.rb
|
347
365
|
- test/spec_helper.rb
|
348
366
|
homepage: http://opalrb.org
|
349
367
|
licenses: []
|
@@ -357,21 +375,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
357
375
|
- - ! '>='
|
358
376
|
- !ruby/object:Gem::Version
|
359
377
|
version: '0'
|
360
|
-
segments:
|
361
|
-
- 0
|
362
|
-
hash: 433748311557838667
|
363
378
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
364
379
|
none: false
|
365
380
|
requirements:
|
366
381
|
- - ! '>='
|
367
382
|
- !ruby/object:Gem::Version
|
368
383
|
version: '0'
|
369
|
-
segments:
|
370
|
-
- 0
|
371
|
-
hash: 433748311557838667
|
372
384
|
requirements: []
|
373
385
|
rubyforge_project:
|
374
|
-
rubygems_version: 1.8.
|
386
|
+
rubygems_version: 1.8.24
|
375
387
|
signing_key:
|
376
388
|
specification_version: 3
|
377
389
|
summary: Ruby runtime and core library for javascript
|
@@ -495,7 +507,6 @@ test_files:
|
|
495
507
|
- test/core/false/or_spec.rb
|
496
508
|
- test/core/false/to_s_spec.rb
|
497
509
|
- test/core/false/xor_spec.rb
|
498
|
-
- test/core/file/expand_path_spec.rb
|
499
510
|
- test/core/hash/allocate_spec.rb
|
500
511
|
- test/core/hash/assoc_spec.rb
|
501
512
|
- test/core/hash/clear_spec.rb
|
@@ -534,6 +545,7 @@ test_files:
|
|
534
545
|
- test/core/hash/value_spec.rb
|
535
546
|
- test/core/hash/values_at_spec.rb
|
536
547
|
- test/core/hash/values_spec.rb
|
548
|
+
- test/core/kernel/define_singleton_method_spec.rb
|
537
549
|
- test/core/kernel/eql_spec.rb
|
538
550
|
- test/core/kernel/equal_value_spec.rb
|
539
551
|
- test/core/kernel/loop_spec.rb
|
@@ -598,6 +610,15 @@ test_files:
|
|
598
610
|
- test/core/string/to_sym_spec.rb
|
599
611
|
- test/core/string/upcase_spec.rb
|
600
612
|
- test/core/symbol/to_proc_spec.rb
|
613
|
+
- test/core/time/at_spec.rb
|
614
|
+
- test/core/time/day_spec.rb
|
615
|
+
- test/core/time/friday_spec.rb
|
616
|
+
- test/core/time/hour_spec.rb
|
617
|
+
- test/core/time/min_spec.rb
|
618
|
+
- test/core/time/monday_spec.rb
|
619
|
+
- test/core/time/month_spec.rb
|
620
|
+
- test/core/time/now_spec.rb
|
621
|
+
- test/core/time/saturday_spec.rb
|
601
622
|
- test/core/true/and_spec.rb
|
602
623
|
- test/core/true/inspect_spec.rb
|
603
624
|
- test/core/true/or_spec.rb
|
@@ -633,10 +654,22 @@ test_files:
|
|
633
654
|
- test/language/while_spec.rb
|
634
655
|
- test/language/yield_spec.rb
|
635
656
|
- test/opal/array/subclassing_spec.rb
|
657
|
+
- test/opal/array/to_json_spec.rb
|
658
|
+
- test/opal/boolean/singleton_class_spec.rb
|
659
|
+
- test/opal/boolean/to_json_spec.rb
|
636
660
|
- test/opal/class/bridge_class_spec.rb
|
637
661
|
- test/opal/exception/subclassing_spec.rb
|
662
|
+
- test/opal/hash/to_json_spec.rb
|
663
|
+
- test/opal/json/parse_spec.rb
|
664
|
+
- test/opal/kernel/to_json_spec.rb
|
665
|
+
- test/opal/nil/to_json_spec.rb
|
666
|
+
- test/opal/numeric/to_json_spec.rb
|
638
667
|
- test/opal/runtime/_methods_spec.rb
|
668
|
+
- test/opal/runtime/call_spec.rb
|
639
669
|
- test/opal/runtime/class_hierarchy_spec.rb
|
640
670
|
- test/opal/runtime/def_spec.rb
|
671
|
+
- test/opal/runtime/defined_spec.rb
|
672
|
+
- test/opal/runtime/super_spec.rb
|
641
673
|
- test/opal/string/subclassing_spec.rb
|
674
|
+
- test/opal/string/to_json_spec.rb
|
642
675
|
- test/spec_helper.rb
|
data/core/dir.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
class Dir
|
2
|
-
def self.getwd
|
3
|
-
""
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.pwd
|
7
|
-
""
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.[](*globs)
|
11
|
-
%x{
|
12
|
-
var result = [], files = factories;
|
13
|
-
|
14
|
-
for (var i = 0, ii = globs.length; i < ii; i++) {
|
15
|
-
var glob = globs[i];
|
16
|
-
|
17
|
-
var re = fs_glob_to_regexp(#{ File.expand_path `glob` });
|
18
|
-
|
19
|
-
for (var file in files) {
|
20
|
-
if (re.exec(file)) {
|
21
|
-
result.push(file);
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
return result;
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
%x(
|
31
|
-
function fs_glob_to_regexp(glob) {
|
32
|
-
var parts = glob.split(''),
|
33
|
-
length = parts.length,
|
34
|
-
result = '';
|
35
|
-
|
36
|
-
var opt_group_stack = 0;
|
37
|
-
|
38
|
-
for (var i = 0; i < length; i++) {
|
39
|
-
var cur = parts[i];
|
40
|
-
|
41
|
-
switch (cur) {
|
42
|
-
case '*':
|
43
|
-
if (parts[i + 1] === '*' && parts[i + 2] === '/') {
|
44
|
-
result += '.*';
|
45
|
-
i += 2;
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
result += '[^/]*';
|
49
|
-
}
|
50
|
-
break;
|
51
|
-
|
52
|
-
case '.':
|
53
|
-
result += '\\\\';
|
54
|
-
result += cur;
|
55
|
-
break;
|
56
|
-
|
57
|
-
case ',':
|
58
|
-
if (opt_group_stack) {
|
59
|
-
result += '|';
|
60
|
-
}
|
61
|
-
else {
|
62
|
-
result += ',';
|
63
|
-
}
|
64
|
-
break;
|
65
|
-
|
66
|
-
case '{':
|
67
|
-
result += '(';
|
68
|
-
opt_group_stack++;
|
69
|
-
break;
|
70
|
-
|
71
|
-
case '}':
|
72
|
-
if (opt_group_stack) {
|
73
|
-
result += ')';
|
74
|
-
opt_group_stack--;
|
75
|
-
}
|
76
|
-
else {
|
77
|
-
result += '}'
|
78
|
-
}
|
79
|
-
break;
|
80
|
-
|
81
|
-
default:
|
82
|
-
result += cur;
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
return new RegExp('^' + result + '$');
|
87
|
-
}
|
88
|
-
)
|
89
|
-
end
|