opal 0.8.1 → 0.9.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/.gitmodules +3 -3
- data/.jshintrc +17 -20
- data/.travis.yml +22 -11
- data/CHANGELOG.md +51 -1
- data/CODE_OF_CONDUCT.md +15 -0
- data/CONTRIBUTING.md +125 -9
- data/Gemfile +1 -1
- data/Guardfile +2 -2
- data/README.md +95 -29
- data/Rakefile +1 -1
- data/benchmark/benchmarks +103 -0
- data/benchmark/bm_array_flatten.rb +9 -0
- data/benchmark/bm_array_intersection_numbers.rb +7 -0
- data/benchmark/bm_array_intersection_objects.rb +7 -0
- data/benchmark/bm_array_intersection_strings.rb +7 -0
- data/benchmark/bm_array_join_ary.rb +9 -0
- data/benchmark/bm_array_minus_numbers.rb +7 -0
- data/benchmark/bm_array_minus_objects.rb +7 -0
- data/benchmark/bm_array_minus_strings.rb +7 -0
- data/benchmark/bm_array_union_numbers.rb +7 -0
- data/benchmark/bm_array_union_objects.rb +7 -0
- data/benchmark/bm_array_union_strings.rb +7 -0
- data/benchmark/bm_array_uniq_bang_numbers.rb +5 -0
- data/benchmark/bm_array_uniq_bang_objects.rb +5 -0
- data/benchmark/bm_array_uniq_bang_strings.rb +5 -0
- data/benchmark/bm_array_uniq_numbers.rb +5 -0
- data/benchmark/bm_array_uniq_objects.rb +5 -0
- data/benchmark/bm_array_uniq_strings.rb +5 -0
- data/benchmark/bm_dispatch_bind_table.rb +57 -0
- data/benchmark/bm_dispatch_code_gen.rb +65 -0
- data/benchmark/bm_dispatch_code_gen_if.rb +64 -0
- data/benchmark/bm_dispatch_hardcoded.rb +44 -0
- data/benchmark/bm_dispatch_send.rb +38 -0
- data/benchmark/bm_dispatch_send_table.rb +57 -0
- data/benchmark/bm_hash_assoc_object.rb +11 -0
- data/benchmark/bm_hash_assoc_string.rb +9 -0
- data/benchmark/bm_hash_clone_object.rb +9 -0
- data/benchmark/bm_hash_clone_string.rb +9 -0
- data/benchmark/bm_hash_delete_object.rb +11 -0
- data/benchmark/bm_hash_delete_string.rb +9 -0
- data/benchmark/bm_hash_each_key_object.rb +9 -0
- data/benchmark/bm_hash_each_key_string.rb +9 -0
- data/benchmark/bm_hash_each_object.rb +9 -0
- data/benchmark/bm_hash_each_string.rb +9 -0
- data/benchmark/bm_hash_each_value_object.rb +9 -0
- data/benchmark/bm_hash_each_value_string.rb +9 -0
- data/benchmark/bm_hash_element_reference_object.rb +11 -0
- data/benchmark/bm_hash_element_reference_string.rb +9 -0
- data/benchmark/bm_hash_element_set_object.rb +5 -0
- data/benchmark/bm_hash_element_set_string.rb +5 -0
- data/benchmark/bm_hash_equal_value_object.rb +14 -0
- data/benchmark/bm_hash_equal_value_string.rb +11 -0
- data/benchmark/bm_hash_fetch_object.rb +11 -0
- data/benchmark/bm_hash_fetch_string.rb +9 -0
- data/benchmark/bm_hash_flatten_object.rb +9 -0
- data/benchmark/bm_hash_flatten_string.rb +9 -0
- data/benchmark/bm_hash_has_key_object.rb +11 -0
- data/benchmark/bm_hash_has_key_string.rb +9 -0
- data/benchmark/bm_hash_has_value_object.rb +9 -0
- data/benchmark/bm_hash_has_value_string.rb +9 -0
- data/benchmark/bm_hash_hash_object.rb +9 -0
- data/benchmark/bm_hash_hash_string.rb +9 -0
- data/benchmark/bm_hash_inspect_object.rb +9 -0
- data/benchmark/bm_hash_inspect_string.rb +9 -0
- data/benchmark/bm_hash_invert_object.rb +9 -0
- data/benchmark/bm_hash_invert_string.rb +9 -0
- data/benchmark/bm_hash_keep_if_object.rb +9 -0
- data/benchmark/bm_hash_keep_if_string.rb +9 -0
- data/benchmark/bm_hash_key_object.rb +9 -0
- data/benchmark/bm_hash_key_string.rb +9 -0
- data/benchmark/bm_hash_keys_object.rb +9 -0
- data/benchmark/bm_hash_keys_string.rb +9 -0
- data/benchmark/bm_hash_literal_mixed_large.rb +3 -0
- data/benchmark/bm_hash_literal_mixed_small.rb +3 -0
- data/benchmark/bm_hash_literal_object_large.rb +4 -0
- data/benchmark/bm_hash_literal_object_small.rb +3 -0
- data/benchmark/bm_hash_literal_string_large.rb +4 -0
- data/benchmark/bm_hash_literal_string_small.rb +3 -0
- data/benchmark/bm_hash_merge_object.rb +22 -0
- data/benchmark/bm_hash_merge_string.rb +18 -0
- data/benchmark/bm_hash_rassoc_object.rb +9 -0
- data/benchmark/bm_hash_rassoc_string.rb +9 -0
- data/benchmark/bm_hash_rehash_object.rb +9 -0
- data/benchmark/bm_hash_rehash_string.rb +9 -0
- data/benchmark/bm_hash_reject_bang_object.rb +9 -0
- data/benchmark/bm_hash_reject_bang_string.rb +9 -0
- data/benchmark/bm_hash_reject_object.rb +9 -0
- data/benchmark/bm_hash_reject_string.rb +9 -0
- data/benchmark/bm_hash_replace_object.rb +18 -0
- data/benchmark/bm_hash_replace_string.rb +14 -0
- data/benchmark/bm_hash_select_bang_object.rb +9 -0
- data/benchmark/bm_hash_select_bang_string.rb +9 -0
- data/benchmark/bm_hash_select_object.rb +9 -0
- data/benchmark/bm_hash_select_string.rb +9 -0
- data/benchmark/bm_hash_shift_object.rb +10 -0
- data/benchmark/bm_hash_shift_string.rb +10 -0
- data/benchmark/bm_hash_to_a_object.rb +9 -0
- data/benchmark/bm_hash_to_a_string.rb +9 -0
- data/benchmark/bm_hash_to_h_object.rb +10 -0
- data/benchmark/bm_hash_to_h_string.rb +10 -0
- data/benchmark/bm_hash_values_object.rb +9 -0
- data/benchmark/bm_hash_values_string.rb +9 -0
- data/benchmark/run.rb +48 -0
- data/bin/opal-mspec +1 -1
- data/bin/opal-repl +4 -4
- data/docs/compiled_ruby.md +214 -56
- data/docs/configuring_gems.md +2 -2
- data/docs/faq.md +2 -2
- data/docs/getting_started.md +19 -2
- data/docs/jquery.md +5 -5
- data/docs/opal_parser.md +53 -0
- data/docs/unsupported_features.md +2 -2
- data/docs/upgrading.md +22 -0
- data/docs/using_sprockets.md +15 -0
- data/examples/rack/config.ru +13 -0
- data/examples/sinatra/config.ru +4 -5
- data/lib/mspec/opal/runner.rb +54 -11
- data/lib/opal.rb +1 -1
- data/lib/opal/builder.rb +1 -1
- data/lib/opal/builder_processors.rb +1 -1
- data/lib/opal/cli.rb +17 -13
- data/lib/opal/cli_options.rb +1 -1
- data/lib/opal/compiler.rb +12 -0
- data/lib/opal/config.rb +4 -0
- data/lib/opal/nodes/arglist.rb +5 -7
- data/lib/opal/nodes/call.rb +6 -1
- data/lib/opal/nodes/call_special.rb +74 -0
- data/lib/opal/nodes/def.rb +35 -28
- data/lib/opal/nodes/definitions.rb +3 -5
- data/lib/opal/nodes/for.rb +13 -0
- data/lib/opal/nodes/helpers.rb +15 -1
- data/lib/opal/nodes/if.rb +5 -5
- data/lib/opal/nodes/iter.rb +6 -1
- data/lib/opal/nodes/literal.rb +1 -1
- data/lib/opal/nodes/logic.rb +2 -2
- data/lib/opal/nodes/masgn.rb +1 -2
- data/lib/opal/nodes/module.rb +2 -1
- data/lib/opal/nodes/rescue.rb +10 -1
- data/lib/opal/nodes/scope.rb +8 -2
- data/lib/opal/nodes/singleton_class.rb +1 -1
- data/lib/opal/nodes/top.rb +11 -0
- data/lib/opal/nodes/variables.rb +4 -4
- data/lib/opal/parser.rb +21 -3
- data/lib/opal/parser/grammar.rb +3115 -2961
- data/lib/opal/parser/grammar.y +29 -6
- data/lib/opal/parser/lexer.rb +18 -8
- data/lib/opal/sprockets.rb +85 -0
- data/lib/opal/sprockets/processor.rb +11 -35
- data/lib/opal/sprockets/server.rb +3 -15
- data/lib/opal/version.rb +2 -2
- data/opal.gemspec +4 -4
- data/opal/README.md +9 -0
- data/opal/corelib/array.rb +433 -181
- data/opal/corelib/basic_object.rb +48 -4
- data/opal/corelib/boolean.rb +15 -6
- data/opal/corelib/class.rb +6 -5
- data/opal/corelib/comparable.rb +12 -0
- data/opal/corelib/complex.rb +282 -0
- data/opal/corelib/constants.rb +9 -0
- data/opal/corelib/enumerable.rb +83 -34
- data/opal/corelib/enumerator.rb +3 -1
- data/opal/corelib/error.rb +49 -10
- data/opal/corelib/file.rb +1 -0
- data/opal/corelib/hash.rb +353 -577
- data/opal/corelib/helpers.rb +20 -0
- data/opal/corelib/kernel.rb +114 -59
- data/opal/corelib/math.rb +470 -0
- data/opal/corelib/method.rb +11 -2
- data/opal/corelib/module.rb +96 -96
- data/opal/corelib/{nil_class.rb → nil.rb} +20 -1
- data/opal/corelib/number.rb +751 -0
- data/opal/corelib/numeric.rb +77 -437
- data/opal/corelib/proc.rb +81 -1
- data/opal/corelib/process.rb +27 -0
- data/opal/corelib/rational.rb +358 -0
- data/opal/corelib/regexp.rb +156 -27
- data/opal/corelib/runtime.js +724 -335
- data/opal/corelib/string.rb +93 -104
- data/opal/corelib/string/encoding.rb +177 -0
- data/opal/corelib/string/inheritance.rb +2 -0
- data/opal/corelib/struct.rb +105 -18
- data/opal/corelib/time.rb +267 -146
- data/opal/corelib/unsupported.rb +216 -0
- data/opal/corelib/variables.rb +0 -6
- data/opal/opal.rb +8 -22
- data/opal/opal/base.rb +9 -0
- data/opal/opal/mini.rb +17 -0
- data/spec/README.md +1 -1
- data/spec/filters/bugs/array.rb +38 -136
- data/spec/filters/bugs/{basic_object.rb → basicobject.rb} +14 -15
- data/spec/filters/bugs/class.rb +6 -12
- data/spec/filters/bugs/complex.rb +3 -0
- data/spec/filters/bugs/date.rb +162 -10
- data/spec/filters/bugs/enumerable.rb +31 -58
- data/spec/filters/bugs/enumerator.rb +42 -0
- data/spec/filters/bugs/exception.rb +66 -10
- data/spec/filters/bugs/float.rb +17 -0
- data/spec/filters/bugs/hash.rb +11 -97
- data/spec/filters/bugs/inheritance.rb +5 -0
- data/spec/filters/bugs/integer.rb +28 -0
- data/spec/filters/bugs/kernel.rb +304 -12
- data/spec/filters/bugs/language.rb +133 -399
- data/spec/filters/bugs/language_opal.rb +88 -0
- data/spec/filters/bugs/module.rb +203 -62
- data/spec/filters/bugs/numeric.rb +32 -0
- data/spec/filters/bugs/proc.rb +39 -0
- data/spec/filters/bugs/range.rb +148 -0
- data/spec/filters/bugs/regexp.rb +168 -0
- data/spec/filters/bugs/set.rb +46 -3
- data/spec/filters/bugs/singleton.rb +1 -2
- data/spec/filters/bugs/string.rb +59 -90
- data/spec/filters/bugs/strscan.rb +80 -0
- data/spec/filters/bugs/struct.rb +10 -20
- data/spec/filters/bugs/time.rb +17 -184
- data/spec/filters/bugs/unboundmethod.rb +22 -0
- data/spec/filters/unsupported/array.rb +163 -0
- data/spec/filters/unsupported/basicobject.rb +14 -0
- data/spec/filters/unsupported/bignum.rb +46 -0
- data/spec/filters/unsupported/class.rb +4 -0
- data/spec/filters/unsupported/delegator.rb +5 -0
- data/spec/filters/unsupported/enumerable.rb +11 -0
- data/spec/filters/unsupported/enumerator.rb +8 -9
- data/spec/filters/unsupported/fixnum.rb +14 -0
- data/spec/filters/unsupported/float.rb +41 -7
- data/spec/filters/unsupported/freeze.rb +45 -0
- data/spec/filters/unsupported/hash.rb +50 -0
- data/spec/filters/unsupported/integer.rb +3 -0
- data/spec/filters/unsupported/kernel.rb +31 -0
- data/spec/filters/unsupported/language.rb +17 -0
- data/spec/filters/unsupported/matchdata.rb +30 -0
- data/spec/filters/unsupported/math.rb +3 -0
- data/spec/filters/unsupported/module.rb +5 -3
- data/spec/filters/unsupported/pathname.rb +3 -0
- data/spec/filters/unsupported/privacy.rb +136 -0
- data/spec/filters/unsupported/proc.rb +3 -0
- data/spec/filters/unsupported/regexp.rb +59 -0
- data/spec/filters/unsupported/set.rb +4 -0
- data/spec/filters/unsupported/{marshal.rb → singleton.rb} +4 -2
- data/spec/filters/unsupported/{mutable_strings.rb → string.rb} +456 -336
- data/spec/filters/unsupported/struct.rb +3 -0
- data/spec/filters/unsupported/symbol.rb +5 -0
- data/spec/filters/unsupported/taint.rb +16 -0
- data/spec/filters/unsupported/thread.rb +5 -0
- data/spec/filters/unsupported/time.rb +197 -16
- data/spec/lib/cli_spec.rb +14 -4
- data/spec/lib/compiler_spec.rb +9 -1
- data/spec/lib/parser/call_spec.rb +18 -0
- data/spec/lib/parser/not_spec.rb +2 -8
- data/spec/lib/sprockets_spec.rb +24 -0
- data/spec/opal/core/array/intersection_spec.rb +38 -0
- data/spec/opal/core/array/minus_spec.rb +38 -0
- data/spec/opal/core/array/union_spec.rb +38 -0
- data/spec/opal/core/array/uniq_spec.rb +49 -0
- data/spec/opal/core/exception_spec.rb +7 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
- data/spec/opal/core/hash/internals_spec.rb +332 -0
- data/spec/opal/core/helpers_spec.rb +14 -0
- data/spec/opal/core/kernel/freeze_spec.rb +1 -1
- data/spec/opal/core/kernel/raise_spec.rb +13 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +9 -0
- data/spec/opal/core/language/class_spec.rb +55 -0
- data/spec/opal/core/language/fixtures/send.rb +1 -0
- data/spec/opal/core/language/keyword_arguments_spec.rb +11 -0
- data/spec/opal/core/language/send_spec.rb +5 -0
- data/spec/opal/core/method/to_proc_spec.rb +28 -0
- data/spec/opal/core/module/name_spec.rb +0 -17
- data/spec/opal/core/runtime/bridged_classes_spec.rb +2 -2
- data/spec/opal/core/runtime/eval_spec.rb +1 -1
- data/spec/opal/core/runtime/method_missing_spec.rb +6 -0
- data/spec/opal/core/runtime_spec.rb +51 -0
- data/spec/opal/stdlib/js_spec.rb +66 -0
- data/spec/opal/stdlib/native/hash_spec.rb +36 -0
- data/spec/rubyspecs +152 -273
- data/spec/spec_helper.rb +10 -11
- data/stdlib/base64.rb +9 -9
- data/stdlib/benchmark.rb +551 -4
- data/stdlib/console.rb +94 -0
- data/stdlib/date.rb +1 -1
- data/stdlib/encoding.rb +1 -170
- data/stdlib/js.rb +56 -0
- data/stdlib/json.rb +9 -14
- data/stdlib/math.rb +1 -370
- data/stdlib/native.rb +133 -63
- data/stdlib/nodejs/file.rb +5 -0
- data/stdlib/nodejs/fileutils.rb +13 -6
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +1 -1
- data/stdlib/opal-parser.rb +1 -2
- data/stdlib/ostruct.rb +65 -6
- data/stdlib/pp.rb +2 -4
- data/stdlib/rbconfig.rb +1 -3
- data/stdlib/strscan.rb +164 -28
- data/tasks/benchmarking.rake +88 -0
- data/tasks/testing.rake +181 -55
- data/{lib/mspec/opal/special_calls.rb → tasks/testing/mspec_special_calls.rb} +1 -1
- data/{lib/mspec/opal/sprockets.js → tasks/testing/phantomjs1-sprockets.js} +17 -6
- data/test/opal/test_keyword.rb +590 -0
- data/vendored-minitest/minitest.rb +2 -2
- data/vendored-minitest/test/unit.rb +5 -0
- metadata +229 -62
- data/benchmarks/operators.rb +0 -11
- data/benchmarks/prova.js.rb +0 -13
- data/docs/libraries.md +0 -36
- data/lib/mspec/opal/new.html.erb +0 -1
- data/lib/mspec/opal/rake_task.rb +0 -248
- data/opal/corelib/match_data.rb +0 -128
- data/spec/filters/bugs/math.rb +0 -95
- data/spec/filters/bugs/nil.rb +0 -7
- data/spec/filters/bugs/opal.rb +0 -9
- data/spec/filters/bugs/regular_expressions.rb +0 -41
- data/spec/filters/bugs/stringscanner.rb +0 -33
- data/spec/filters/unsupported/encoding.rb +0 -102
- data/spec/filters/unsupported/frozen.rb +0 -92
- data/spec/filters/unsupported/hash_compare_by_identity.rb +0 -16
- data/spec/filters/unsupported/integer_size.rb +0 -59
- data/spec/filters/unsupported/method_added.rb +0 -10
- data/spec/filters/unsupported/private_constants.rb +0 -30
- data/spec/filters/unsupported/private_methods.rb +0 -55
- data/spec/filters/unsupported/random.rb +0 -4
- data/spec/filters/unsupported/rational_numbers.rb +0 -4
- data/spec/filters/unsupported/regular_expressions.rb +0 -137
- data/spec/filters/unsupported/ruby_exe.rb +0 -5
- data/spec/filters/unsupported/symbols.rb +0 -17
- data/spec/filters/unsupported/tainted.rb +0 -180
- data/spec/filters/unsupported/trusted.rb +0 -88
- data/stdlib/process.rb +0 -10
- data/tasks/documenting.rake +0 -37
data/stdlib/pp.rb
CHANGED
@@ -19,10 +19,8 @@ class PP
|
|
19
19
|
p(*args)
|
20
20
|
end
|
21
21
|
else
|
22
|
-
def pp(obj, out
|
23
|
-
if
|
24
|
-
`console.log(obj)`
|
25
|
-
elsif String === out
|
22
|
+
def pp(obj, out=$stdout, width=79)
|
23
|
+
if String === out
|
26
24
|
out + obj.inspect + "\n"
|
27
25
|
else
|
28
26
|
out << obj.inspect + "\n"
|
data/stdlib/rbconfig.rb
CHANGED
data/stdlib/strscan.rb
CHANGED
@@ -7,7 +7,7 @@ class StringScanner
|
|
7
7
|
@pos = 0
|
8
8
|
@matched = nil
|
9
9
|
@working = string
|
10
|
-
@match
|
10
|
+
@match = []
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_reader :string
|
@@ -15,15 +15,17 @@ class StringScanner
|
|
15
15
|
def beginning_of_line?
|
16
16
|
`#@pos === 0 || #@string.charAt(#@pos - 1) === "\n"`
|
17
17
|
end
|
18
|
+
|
18
19
|
alias bol? beginning_of_line?
|
19
20
|
|
20
|
-
def scan(
|
21
|
+
def scan(pattern)
|
22
|
+
pattern = anchor(pattern)
|
23
|
+
|
21
24
|
%x{
|
22
|
-
var
|
23
|
-
result = regex.exec(#@working);
|
25
|
+
var result = pattern.exec(#@working);
|
24
26
|
|
25
27
|
if (result == null) {
|
26
|
-
return
|
28
|
+
return #@matched = nil;
|
27
29
|
}
|
28
30
|
else if (typeof(result) === 'object') {
|
29
31
|
#@prev_pos = #@pos;
|
@@ -46,6 +48,38 @@ class StringScanner
|
|
46
48
|
}
|
47
49
|
end
|
48
50
|
|
51
|
+
def scan_until(pattern)
|
52
|
+
pattern = anchor(pattern)
|
53
|
+
|
54
|
+
%x{
|
55
|
+
var pos = #@pos,
|
56
|
+
working = #@working,
|
57
|
+
result;
|
58
|
+
|
59
|
+
while (true) {
|
60
|
+
result = pattern.exec(working);
|
61
|
+
pos += 1;
|
62
|
+
working = working.substr(1);
|
63
|
+
|
64
|
+
if (result == null) {
|
65
|
+
if (working.length === 0) {
|
66
|
+
return #@matched = nil;
|
67
|
+
}
|
68
|
+
|
69
|
+
continue;
|
70
|
+
}
|
71
|
+
|
72
|
+
#@matched = #@string.substr(#@pos, pos - #@pos - 1 + result[0].length);
|
73
|
+
#@prev_pos = pos - 1;
|
74
|
+
#@pos = pos;
|
75
|
+
#@working = working.substr(result[0].length);
|
76
|
+
|
77
|
+
return #@matched;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
|
49
83
|
def [](idx)
|
50
84
|
%x{
|
51
85
|
var match = #@match;
|
@@ -66,16 +100,36 @@ class StringScanner
|
|
66
100
|
}
|
67
101
|
end
|
68
102
|
|
69
|
-
def check(
|
103
|
+
def check(pattern)
|
104
|
+
pattern = anchor(pattern)
|
105
|
+
|
70
106
|
%x{
|
71
|
-
var
|
72
|
-
result = regexp.exec(#@working);
|
107
|
+
var result = pattern.exec(#@working);
|
73
108
|
|
74
109
|
if (result == null) {
|
75
|
-
return
|
110
|
+
return #@matched = nil;
|
111
|
+
}
|
112
|
+
|
113
|
+
return #@matched = result[0];
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_until(pattern)
|
118
|
+
%x{
|
119
|
+
var prev_pos = #@prev_pos,
|
120
|
+
pos = #@pos;
|
121
|
+
|
122
|
+
var result = #{scan_until(pattern)};
|
123
|
+
|
124
|
+
if (result !== nil) {
|
125
|
+
#@matched = result.substr(-1);
|
126
|
+
#@working = #@string.substr(pos);
|
76
127
|
}
|
77
128
|
|
78
|
-
|
129
|
+
#@prev_pos = prev_pos;
|
130
|
+
#@pos = pos;
|
131
|
+
|
132
|
+
return result;
|
79
133
|
}
|
80
134
|
end
|
81
135
|
|
@@ -87,37 +141,72 @@ class StringScanner
|
|
87
141
|
`#@working.length === 0`
|
88
142
|
end
|
89
143
|
|
90
|
-
def
|
144
|
+
def exist?(pattern)
|
91
145
|
%x{
|
92
|
-
|
93
|
-
var result = re.exec(#@working);
|
146
|
+
var result = pattern.exec(#@working);
|
94
147
|
|
95
148
|
if (result == null) {
|
96
|
-
return
|
149
|
+
return nil;
|
150
|
+
}
|
151
|
+
else if (result.index == 0) {
|
152
|
+
return 0;
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
return result.index + 1;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
def skip(pattern)
|
161
|
+
pattern = anchor(pattern)
|
162
|
+
|
163
|
+
%x{
|
164
|
+
var result = pattern.exec(#@working);
|
165
|
+
|
166
|
+
if (result == null) {
|
167
|
+
return #@matched = nil;
|
97
168
|
}
|
98
169
|
else {
|
99
170
|
var match_str = result[0];
|
100
171
|
var match_len = match_str.length;
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
172
|
+
|
173
|
+
#@matched = match_str;
|
174
|
+
#@prev_pos = #@pos;
|
175
|
+
#@pos += match_len;
|
176
|
+
#@working = #@working.substring(match_len);
|
177
|
+
|
105
178
|
return match_len;
|
106
179
|
}
|
107
180
|
}
|
108
181
|
end
|
109
182
|
|
110
|
-
def
|
183
|
+
def skip_until(pattern)
|
184
|
+
%x{
|
185
|
+
var result = #{scan_until(pattern)};
|
186
|
+
|
187
|
+
if (result === nil) {
|
188
|
+
return nil;
|
189
|
+
}
|
190
|
+
else {
|
191
|
+
#@matched = result.substr(-1);
|
192
|
+
|
193
|
+
return result.length;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
def get_byte
|
111
199
|
%x{
|
112
200
|
var result = nil;
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
201
|
+
|
202
|
+
if (#@pos < #@string.length) {
|
203
|
+
#@prev_pos = #@pos;
|
204
|
+
#@pos += 1;
|
205
|
+
result = #@matched = #@working.substring(0, 1);
|
206
|
+
#@working = #@working.substring(1);
|
118
207
|
}
|
119
208
|
else {
|
120
|
-
|
209
|
+
#@matched = nil;
|
121
210
|
}
|
122
211
|
|
123
212
|
return result;
|
@@ -127,6 +216,23 @@ class StringScanner
|
|
127
216
|
# not exactly, but for now...
|
128
217
|
alias getch get_byte
|
129
218
|
|
219
|
+
def match?(pattern)
|
220
|
+
pattern = anchor(pattern)
|
221
|
+
|
222
|
+
%x{
|
223
|
+
var result = pattern.exec(#@working);
|
224
|
+
|
225
|
+
if (result == null) {
|
226
|
+
return nil;
|
227
|
+
}
|
228
|
+
else {
|
229
|
+
#@prev_pos = #@pos;
|
230
|
+
|
231
|
+
return result[0].length;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
end
|
235
|
+
|
130
236
|
def pos=(pos)
|
131
237
|
%x{
|
132
238
|
if (pos < 0) {
|
@@ -134,10 +240,30 @@ class StringScanner
|
|
134
240
|
}
|
135
241
|
}
|
136
242
|
|
137
|
-
@pos
|
243
|
+
@pos = pos
|
138
244
|
@working = `#{@string}.slice(pos)`
|
139
245
|
end
|
140
246
|
|
247
|
+
def post_match
|
248
|
+
%x{
|
249
|
+
if (#@matched === nil) {
|
250
|
+
return nil;
|
251
|
+
}
|
252
|
+
|
253
|
+
return #@string.substr(#@pos);
|
254
|
+
}
|
255
|
+
end
|
256
|
+
|
257
|
+
def pre_match
|
258
|
+
%x{
|
259
|
+
if (#@matched === nil) {
|
260
|
+
return nil;
|
261
|
+
}
|
262
|
+
|
263
|
+
return #@string.substr(0, #@prev_pos);
|
264
|
+
}
|
265
|
+
end
|
266
|
+
|
141
267
|
def reset
|
142
268
|
@working = @string
|
143
269
|
@matched = nil
|
@@ -152,15 +278,25 @@ class StringScanner
|
|
152
278
|
`#@working.length !== 0`
|
153
279
|
end
|
154
280
|
|
281
|
+
def rest_size
|
282
|
+
rest.size
|
283
|
+
end
|
284
|
+
|
155
285
|
def terminate
|
156
286
|
@match = nil
|
157
287
|
self.pos = @string.length
|
158
288
|
end
|
159
289
|
|
160
290
|
def unscan
|
161
|
-
@pos
|
291
|
+
@pos = @prev_pos
|
162
292
|
@prev_pos = nil
|
163
|
-
@match
|
293
|
+
@match = nil
|
294
|
+
|
164
295
|
self
|
165
296
|
end
|
297
|
+
|
298
|
+
private
|
299
|
+
def anchor(pattern)
|
300
|
+
`new RegExp('^' + pattern.toString().substr(1, pattern.toString().length - 2))`
|
301
|
+
end
|
166
302
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
namespace :bench do
|
2
|
+
directory "tmp/bench"
|
3
|
+
|
4
|
+
desc "Benchmark Opal"
|
5
|
+
task :opal => "tmp/bench" do |t, args|
|
6
|
+
files = Array(args[:files]) + args.extras
|
7
|
+
index = 0
|
8
|
+
begin
|
9
|
+
index += 1
|
10
|
+
report = "tmp/bench/Opal#{index}"
|
11
|
+
end while File.exist?(report)
|
12
|
+
sh "bundle exec opal benchmark/run.rb #{files.join(" ")} | tee #{report}"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Benchmark Ruby"
|
16
|
+
task :ruby => "tmp/bench" do |t, args|
|
17
|
+
files = Array(args[:files]) + args.extras
|
18
|
+
index = 0
|
19
|
+
begin
|
20
|
+
index += 1
|
21
|
+
report = "tmp/bench/Ruby#{index}"
|
22
|
+
end while File.exist?(report)
|
23
|
+
sh "bundle exec ruby benchmark/run.rb #{files.join(" ")} | tee #{report}"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Delete all benchmark results"
|
27
|
+
task :clear do
|
28
|
+
sh "rm tmp/bench/*"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Combined report of all benchmark results"
|
32
|
+
task :report do |t, args|
|
33
|
+
files = Array(args[:files]) + args.extras
|
34
|
+
if files.empty?
|
35
|
+
files = Dir["tmp/bench/*"]
|
36
|
+
else
|
37
|
+
files = files.map{|file| "tmp/bench/#{ file }"}
|
38
|
+
end
|
39
|
+
reports = []
|
40
|
+
benchmark_names = []
|
41
|
+
|
42
|
+
files.each do |file|
|
43
|
+
report_name = File.basename(file, File.extname(file))
|
44
|
+
report_results = {}
|
45
|
+
File.read(file).each_line do |line|
|
46
|
+
benchmark_name, benchmark_result = line.split(" ")
|
47
|
+
report_results[benchmark_name] = benchmark_result
|
48
|
+
benchmark_names << benchmark_name
|
49
|
+
end
|
50
|
+
reports << [report_name, report_results]
|
51
|
+
end
|
52
|
+
|
53
|
+
benchmark_names.uniq!
|
54
|
+
|
55
|
+
header = ["Benchmark"]
|
56
|
+
reports.each do |report_name, _|
|
57
|
+
header << report_name
|
58
|
+
end
|
59
|
+
|
60
|
+
table = [header]
|
61
|
+
benchmark_names.each do |benchmark_name|
|
62
|
+
row = [benchmark_name]
|
63
|
+
reports.each do |_, report_results|
|
64
|
+
if report_results[benchmark_name]
|
65
|
+
row << format("%0.3f", report_results[benchmark_name])
|
66
|
+
else
|
67
|
+
row << ""
|
68
|
+
end
|
69
|
+
end
|
70
|
+
table << row
|
71
|
+
end
|
72
|
+
|
73
|
+
fmt = ""
|
74
|
+
table.transpose.each_with_index do |column, index|
|
75
|
+
column_width = column.max_by{|string| string.length}.length
|
76
|
+
if index.zero?
|
77
|
+
fmt << "%-#{ column_width }s"
|
78
|
+
else
|
79
|
+
fmt << " %#{ column_width }s"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
fmt << "\n"
|
83
|
+
|
84
|
+
table.each do |row|
|
85
|
+
printf fmt, *row
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/tasks/testing.rake
CHANGED
@@ -1,70 +1,181 @@
|
|
1
|
+
require_relative './testing/mspec_special_calls'
|
2
|
+
|
1
3
|
require 'rspec/core/rake_task'
|
2
4
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
3
5
|
t.pattern = 'spec/lib/**/*_spec.rb'
|
4
6
|
end
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Testing
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def stubs
|
12
|
+
%w[
|
13
|
+
mspec/helpers/tmp
|
14
|
+
mspec/helpers/environment
|
15
|
+
mspec/guards/block_device
|
16
|
+
mspec/guards/endian
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def specs(env = ENV)
|
21
|
+
suite = env['SUITE']
|
22
|
+
pattern = env['PATTERN']
|
23
|
+
whitelist_pattern = !!env['RUBYSPECS']
|
24
|
+
|
25
|
+
excepting = []
|
26
|
+
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
|
27
|
+
l.strip!
|
28
|
+
l.start_with?('#') || l.empty? || (l.start_with?('!') && excepting.push(l.sub('!', 'spec/') + '.rb'))
|
29
|
+
end.flat_map do |path|
|
30
|
+
path = "spec/#{path}"
|
31
|
+
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
|
32
|
+
end - excepting
|
33
|
+
|
34
|
+
opalspecs = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']
|
35
|
+
userspecs = Dir[pattern] if pattern
|
36
|
+
userspecs &= rubyspecs if whitelist_pattern
|
37
|
+
|
38
|
+
opalspec_filters = Dir['spec/filters/**/*_opal.rb']
|
39
|
+
rubyspec_filters = Dir['spec/filters/**/*.rb'] - opalspec_filters
|
40
|
+
|
41
|
+
specs = []
|
42
|
+
add_specs = ->(name, new_specs) do
|
43
|
+
puts "Adding #{new_specs.size.to_s.rjust(3)} files (#{name})"
|
44
|
+
specs += new_specs
|
45
|
+
end
|
46
|
+
|
47
|
+
# Filters must be added first
|
48
|
+
suite_filters = suite == 'opal' ? opalspec_filters : rubyspec_filters
|
49
|
+
add_specs["#{suite} filters", suite_filters]
|
50
|
+
|
51
|
+
if pattern
|
52
|
+
add_specs["PATTERN=#{pattern}", userspecs]
|
53
|
+
elsif suite == 'opal'
|
54
|
+
add_specs['spec/opal', opalspecs]
|
55
|
+
elsif suite == 'rubyspec'
|
56
|
+
add_specs['spec/rubyspec', rubyspecs]
|
57
|
+
else
|
58
|
+
warn 'Please provide at lease one of the following ENV vars:'
|
59
|
+
warn 'PATTERN # e.g. env PATTERN="spec/rubyspec/core/numeric/**_spec.rb"'
|
60
|
+
warn 'SUITE # can be either SUITE=opal or SUITE=rubyspec'
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
|
64
|
+
specs
|
65
|
+
end
|
11
66
|
|
12
|
-
|
13
|
-
|
67
|
+
def write_file(filename, specs, bm_filepath = nil)
|
68
|
+
requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}
|
14
69
|
|
70
|
+
if bm_filepath
|
71
|
+
enter_benchmarking_mode = "OSpecRunner.main.bm!(#{Integer(ENV['BM'])}, '#{bm_filepath}')"
|
72
|
+
end
|
73
|
+
|
74
|
+
File.write filename, <<-RUBY
|
75
|
+
require 'spec_helper'
|
76
|
+
#{enter_benchmarking_mode}
|
77
|
+
#{requires.join("\n ")}
|
78
|
+
OSpecFilter.main.unused_filters_message(list: #{!!ENV['LIST_UNUSED_FILTERS']})
|
79
|
+
OSpecRunner.main.did_finish
|
80
|
+
RUBY
|
81
|
+
end
|
82
|
+
|
83
|
+
def bm_filepath
|
84
|
+
mkdir_p 'tmp/bench'
|
85
|
+
index = 0
|
86
|
+
begin
|
87
|
+
index += 1
|
88
|
+
bm_filepath = "tmp/bench/Spec#{index}"
|
89
|
+
end while File.exist?(bm_filepath)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
pattern_usage = <<-DESC
|
15
94
|
Use PATTERN and env var to manually set the glob for specs:
|
16
95
|
|
17
96
|
# Will run all specs matching the specified pattern.
|
18
97
|
# (Note: the rubyspecs filters will still apply)
|
19
|
-
|
98
|
+
env PATTERN="spec/rubyspec/core/module/class_variable*_spec.rb" rake mspec_node
|
99
|
+
env PATTERN="spec/rubyspec/core/numeric/**_spec.rb" rake mspec_node
|
20
100
|
DESC
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
101
|
+
|
102
|
+
%w[rubyspec opal].each do |suite|
|
103
|
+
desc "Run the MSpec/#{suite} test suite on Phantom.js" + pattern_usage
|
104
|
+
task :"mspec_#{suite}_phantom" do
|
105
|
+
filename = File.expand_path('tmp/mspec_phantom.rb')
|
106
|
+
runner = "#{__dir__}/testing/phantomjs1-sprockets.js"
|
107
|
+
port = 9999
|
108
|
+
url = "http://localhost:#{port}/"
|
109
|
+
|
110
|
+
mkdir_p File.dirname(filename)
|
111
|
+
Testing.write_file filename, Testing.specs(ENV.to_hash.merge 'SUITE' => suite)
|
112
|
+
|
113
|
+
Testing.stubs.each {|s| ::Opal::Processor.stub_file s }
|
114
|
+
|
115
|
+
Opal::Config.arity_check_enabled = true
|
116
|
+
Opal::Config.freezing_stubs_enabled = false
|
117
|
+
Opal::Config.tainting_stubs_enabled = false
|
118
|
+
Opal::Config.dynamic_require_severity = :error
|
119
|
+
|
120
|
+
Opal.use_gem 'mspec'
|
121
|
+
Opal.append_path 'spec'
|
122
|
+
Opal.append_path 'lib'
|
123
|
+
Opal.append_path File.dirname(filename)
|
124
|
+
|
125
|
+
app = Opal::Server.new { |s| s.main = File.basename(filename) }
|
126
|
+
server = Thread.new { Rack::Server.start(app: app, Port: port) }
|
127
|
+
sleep 1
|
128
|
+
|
129
|
+
begin
|
130
|
+
sh 'phantomjs', runner, url
|
131
|
+
ensure
|
132
|
+
server.kill if server.alive?
|
133
|
+
end
|
47
134
|
end
|
48
135
|
|
49
|
-
|
50
|
-
|
136
|
+
desc "Run the MSpec test suite on Node.js" + pattern_usage
|
137
|
+
task :"mspec_#{suite}_node" do
|
138
|
+
include_paths = '-Ispec -Ilib'
|
51
139
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
#{
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
140
|
+
filename = 'tmp/mspec_node.rb'
|
141
|
+
js_filename = 'tmp/mspec_node.js'
|
142
|
+
mkdir_p File.dirname(filename)
|
143
|
+
bm_filepath = Testing.bm_filepath if ENV['BM']
|
144
|
+
Testing.write_file filename, Testing.specs(ENV.to_hash.merge 'SUITE' => suite), bm_filepath
|
145
|
+
|
146
|
+
stubs = Testing.stubs.map{|s| "-s#{s}"}.join(' ')
|
147
|
+
|
148
|
+
sh "ruby -rbundler/setup -r#{__dir__}/testing/mspec_special_calls "\
|
149
|
+
"bin/opal -gmspec #{include_paths} #{stubs} -rnodejs/io -rnodejs/kernel -Dwarning -A #{filename} -c > #{js_filename}"
|
150
|
+
sh "NODE_PATH=stdlib/nodejs/node_modules node #{js_filename}"
|
151
|
+
|
152
|
+
if bm_filepath
|
153
|
+
puts "Benchmark results have been written to #{bm_filepath}"
|
154
|
+
puts "To view the results, run bundle exec rake bench:report"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
task :jshint do
|
160
|
+
js_filename = 'tmp/jshint.js'
|
161
|
+
mkdir_p 'tmp'
|
162
|
+
|
163
|
+
if ENV['SUITE'] == 'core'
|
164
|
+
sh "ruby -rbundler/setup bin/opal -ce '23' > #{js_filename}"
|
165
|
+
sh "jshint --verbose #{js_filename}"
|
166
|
+
elsif ENV['SUITE'] == 'stdlib'
|
167
|
+
sh "rake dist"
|
168
|
+
|
169
|
+
Dir["build/*.js"].each {|path|
|
170
|
+
unless path =~ /(opal.*js)|.min.js/
|
171
|
+
sh "jshint --verbose #{path}"
|
172
|
+
end
|
173
|
+
}
|
174
|
+
else
|
175
|
+
warn 'Please provide at lease one of the following ENV vars:'
|
176
|
+
warn 'SUITE # can be either SUITE=core or SUITE=stdlib'
|
177
|
+
exit 1
|
178
|
+
end
|
68
179
|
end
|
69
180
|
|
70
181
|
task :cruby_tests do
|
@@ -72,10 +183,12 @@ task :cruby_tests do
|
|
72
183
|
files = Dir[ENV['FILES'] || 'test/test_*.rb']
|
73
184
|
include_paths = '-Itest -I. -Itmp -Ilib'
|
74
185
|
else
|
75
|
-
include_paths = '-Itest/cruby/test'
|
186
|
+
include_paths = '-Itest/cruby/test -Itest'
|
76
187
|
test_dir = Pathname("#{__dir__}/../test/cruby/test")
|
77
188
|
files = %w[
|
189
|
+
benchmark/test_benchmark.rb
|
78
190
|
ruby/test_call.rb
|
191
|
+
opal/test_keyword.rb
|
79
192
|
].flat_map do |path|
|
80
193
|
if path.end_with?('.rb')
|
81
194
|
path
|
@@ -99,10 +212,23 @@ task :cruby_tests do
|
|
99
212
|
puts "== Running: #{files.join ", "}"
|
100
213
|
|
101
214
|
sh "ruby -rbundler/setup "\
|
102
|
-
"bin/opal #{include_paths} #{stubs} -rnodejs -Dwarning -A #{filename} -c > #{js_filename}"
|
215
|
+
"bin/opal #{include_paths} #{stubs} -rnodejs -ropal-parser -Dwarning -A #{filename} -c > #{js_filename}"
|
103
216
|
sh "NODE_PATH=stdlib/nodejs/node_modules node #{js_filename}"
|
104
217
|
end
|
105
218
|
|
106
|
-
task :mspec => [:
|
219
|
+
task :mspec => [:mspec_rubyspec_node, :mspec_rubyspec_phantom, :mspec_opal_node, :mspec_opal_phantom]
|
107
220
|
task :minitest => [:cruby_tests]
|
108
221
|
task :test_all => [:rspec, :mspec, :minitest]
|
222
|
+
|
223
|
+
|
224
|
+
if (current_suite = ENV['SUITE'])
|
225
|
+
# Legacy tasks, only if ENV['SUITE'] is set
|
226
|
+
desc "Deprecated: use mspec_rubyspec_phantom or mspec_opal_phantom instead"
|
227
|
+
task :mspec_phantom => :"mspec_#{current_suite}_phantom"
|
228
|
+
|
229
|
+
desc "Deprecated: use mspec_rubyspec_node or mspec_opal_node instead"
|
230
|
+
task :mspec_node => :"mspec_#{current_suite}_node"
|
231
|
+
else
|
232
|
+
task :mspec_phantom => [:mspec_opal_phantom, :mspec_rubyspec_phantom]
|
233
|
+
task :mspec_node => [:mspec_opal_node, :mspec_rubyspec_node]
|
234
|
+
end
|