opal 0.9.4 → 0.10.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.gitignore +2 -3
- data/.gitmodules +5 -2
- data/.jshintrc +1 -8
- data/.rspec +1 -1
- data/.travis.yml +15 -23
- data/CHANGELOG.md +511 -326
- data/CODE_OF_CONDUCT.md +13 -15
- data/CONTRIBUTING.md +26 -216
- data/Gemfile +20 -12
- data/Guardfile +2 -2
- data/HACKING.md +230 -0
- data/README.md +6 -7
- data/bin/opal-mspec +1 -1
- data/config.ru +2 -2
- data/docs/faq.md +1 -1
- data/docs/source_maps.md +1 -1
- data/lib/opal.rb +1 -0
- data/lib/opal/builder.rb +1 -1
- data/lib/opal/cli.rb +30 -28
- data/lib/opal/cli_options.rb +3 -0
- data/lib/opal/cli_runners.rb +14 -1
- data/lib/opal/cli_runners/{apple_script.rb → applescript.rb} +3 -3
- data/lib/opal/cli_runners/nashorn.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +2 -2
- data/lib/opal/cli_runners/phantom.js +24 -0
- data/lib/opal/cli_runners/phantomjs.rb +10 -10
- data/lib/opal/cli_runners/server.rb +3 -3
- data/lib/opal/compiler.rb +43 -4
- data/lib/opal/config.rb +3 -1
- data/lib/opal/errors.rb +13 -0
- data/lib/opal/fragment.rb +0 -13
- data/lib/opal/nodes.rb +10 -0
- data/lib/opal/nodes/args/initialize_kwargs.rb +28 -0
- data/lib/opal/nodes/args/kwarg.rb +29 -0
- data/lib/opal/nodes/args/kwoptarg.rb +29 -0
- data/lib/opal/nodes/args/kwrestarg.rb +39 -0
- data/lib/opal/nodes/args/mlhsarg.rb +79 -0
- data/lib/opal/nodes/args/normarg.rb +26 -0
- data/lib/opal/nodes/args/optarg.rb +27 -0
- data/lib/opal/nodes/args/post_args.rb +200 -0
- data/lib/opal/nodes/args/post_kwargs.rb +31 -0
- data/lib/opal/nodes/args/restarg.rb +33 -0
- data/lib/opal/nodes/base.rb +12 -0
- data/lib/opal/nodes/call.rb +92 -33
- data/lib/opal/nodes/def.rb +26 -169
- data/lib/opal/nodes/hash.rb +10 -4
- data/lib/opal/nodes/helpers.rb +6 -3
- data/lib/opal/nodes/inline_args.rb +61 -0
- data/lib/opal/nodes/iter.rb +73 -82
- data/lib/opal/nodes/logic.rb +12 -2
- data/lib/opal/nodes/masgn.rb +1 -2
- data/lib/opal/nodes/node_with_args.rb +141 -0
- data/lib/opal/nodes/rescue.rb +121 -43
- data/lib/opal/nodes/scope.rb +24 -5
- data/lib/opal/nodes/super.rb +122 -54
- data/lib/opal/nodes/top.rb +0 -12
- data/lib/opal/nodes/yield.rb +2 -13
- data/lib/opal/parser.rb +67 -39
- data/lib/opal/parser/grammar.rb +3319 -2961
- data/lib/opal/parser/grammar.y +234 -46
- data/lib/opal/parser/lexer.rb +105 -17
- data/lib/opal/parser/sexp.rb +4 -0
- data/lib/opal/paths.rb +4 -0
- data/lib/opal/regexp_anchors.rb +19 -1
- data/lib/opal/sprockets.rb +21 -18
- data/lib/opal/sprockets/environment.rb +0 -8
- data/lib/opal/sprockets/processor.rb +13 -16
- data/lib/opal/sprockets/server.rb +6 -12
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +1 -0
- data/opal/corelib/array.rb +209 -131
- data/opal/corelib/basic_object.rb +7 -3
- data/opal/corelib/class.rb +11 -17
- data/opal/corelib/constants.rb +2 -2
- data/opal/corelib/enumerable.rb +178 -355
- data/opal/corelib/enumerator.rb +3 -46
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +13 -1
- data/opal/corelib/hash.rb +26 -56
- data/opal/corelib/helpers.rb +10 -0
- data/opal/corelib/kernel.rb +6 -3
- data/opal/corelib/module.rb +62 -31
- data/opal/corelib/number.rb +7 -16
- data/opal/corelib/proc.rb +24 -9
- data/opal/corelib/range.rb +4 -13
- data/opal/corelib/runtime.js +515 -378
- data/opal/corelib/string.rb +21 -49
- data/opal/corelib/struct.rb +50 -35
- data/opal/corelib/unsupported.rb +18 -30
- data/opal/opal.rb +0 -1
- data/opal/opal/mini.rb +1 -0
- data/spec/README.md +6 -4
- data/spec/filters/bugs/array.rb +0 -42
- data/spec/filters/bugs/basicobject.rb +0 -2
- data/spec/filters/bugs/bigdecimal.rb +160 -0
- data/spec/filters/bugs/class.rb +0 -5
- data/spec/filters/bugs/date.rb +1 -48
- data/spec/filters/bugs/enumerable.rb +4 -12
- data/spec/filters/bugs/enumerator.rb +0 -1
- data/spec/filters/bugs/exception.rb +4 -3
- data/spec/filters/bugs/float.rb +4 -2
- data/spec/filters/bugs/kernel.rb +25 -10
- data/spec/filters/bugs/language.rb +119 -68
- data/spec/filters/bugs/method.rb +135 -0
- data/spec/filters/bugs/module.rb +13 -28
- data/spec/filters/bugs/proc.rb +18 -8
- data/spec/filters/bugs/range.rb +0 -3
- data/spec/filters/bugs/rational.rb +4 -0
- data/spec/filters/bugs/regexp.rb +68 -36
- data/spec/filters/bugs/string.rb +1 -1
- data/spec/filters/bugs/struct.rb +0 -12
- data/spec/filters/bugs/time.rb +1 -0
- data/spec/filters/bugs/unboundmethod.rb +2 -1
- data/spec/filters/unsupported/freeze.rb +3 -1
- data/spec/filters/unsupported/language.rb +0 -7
- data/spec/filters/unsupported/privacy.rb +7 -6
- data/spec/filters/unsupported/string.rb +10 -0
- data/spec/filters/unsupported/struct.rb +3 -0
- data/spec/filters/unsupported/symbol.rb +9 -0
- data/spec/filters/unsupported/taint.rb +0 -3
- data/spec/filters/unsupported/thread.rb +1 -0
- data/spec/lib/cli_runners/phantomjs_spec.rb +39 -0
- data/spec/lib/cli_spec.rb +42 -1
- data/spec/lib/compiler/call_spec.rb +700 -0
- data/spec/lib/compiler_spec.rb +46 -28
- data/spec/lib/config_spec.rb +13 -0
- data/spec/lib/parser/call_spec.rb +18 -0
- data/spec/lib/parser/def_spec.rb +29 -0
- data/spec/lib/parser/iter_spec.rb +15 -15
- data/spec/lib/parser/lambda_spec.rb +153 -12
- data/spec/lib/parser/string_spec.rb +5 -0
- data/spec/lib/parser/undef_spec.rb +1 -1
- data/spec/lib/parser/variables_spec.rb +24 -0
- data/spec/lib/paths_spec.rb +12 -5
- data/spec/lib/spec_helper.rb +5 -0
- data/spec/lib/sprockets/processor_spec.rb +6 -5
- data/spec/lib/sprockets_spec.rb +8 -0
- data/spec/mspec-opal/formatters.rb +188 -0
- data/spec/mspec-opal/runner.rb +193 -0
- data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
- data/spec/opal/core/kernel/define_singleton_method_spec.rb +1 -1
- data/spec/opal/core/kernel/instance_variables_spec.rb +14 -0
- data/spec/opal/core/kernel/loop_spec.rb +1 -1
- data/spec/opal/core/kernel/raise_spec.rb +1 -1
- data/spec/opal/core/language/heredoc_spec.rb +42 -0
- data/spec/opal/core/language/rescue_spec.rb +18 -0
- data/spec/opal/core/language_spec.rb +22 -0
- data/spec/opal/core/module/const_defined_spec.rb +1 -2
- data/spec/opal/core/module/name_spec.rb +6 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +14 -2
- data/spec/opal/core/runtime/rescue_spec.rb +12 -2
- data/spec/opal/core/runtime/super_spec.rb +1 -0
- data/spec/opal/core/string_spec.rb +21 -0
- data/spec/opal/stdlib/js_spec.rb +1 -1
- data/spec/opal/stdlib/native/hash_spec.rb +7 -0
- data/spec/opal/stdlib/promise/always_spec.rb +24 -5
- data/spec/opal/stdlib/promise/rescue_spec.rb +15 -6
- data/spec/opal/stdlib/promise/then_spec.rb +13 -5
- data/spec/opal/stdlib/promise/trace_spec.rb +5 -6
- data/spec/opal/stdlib/strscan/scan_spec.rb +1 -1
- data/spec/ruby_specs +122 -0
- data/spec/spec_helper.rb +3 -15
- data/stdlib/base64.rb +51 -121
- data/stdlib/bigdecimal.rb +231 -0
- data/stdlib/bigdecimal/bignumber.js.rb +11 -0
- data/stdlib/bigdecimal/kernel.rb +5 -0
- data/stdlib/date.rb +252 -10
- data/stdlib/native.rb +38 -38
- data/stdlib/nodejs/dir.rb +8 -6
- data/stdlib/nodejs/file.rb +28 -3
- data/stdlib/nodejs/node_modules/.bin/js-yaml +1 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esparse +1 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esvalidate +1 -0
- data/stdlib/nodejs/require.rb +1 -1
- data/stdlib/nodejs/yaml.rb +3 -2
- data/stdlib/opal-parser.rb +7 -2
- data/stdlib/pathname.rb +23 -1
- data/stdlib/phantomjs.rb +10 -0
- data/stdlib/promise.rb +38 -23
- data/tasks/building.rake +3 -3
- data/tasks/testing.rake +27 -14
- data/tasks/testing/mspec_special_calls.rb +1 -1
- data/tasks/testing/sprockets-phantomjs.js +4 -0
- data/test/opal/test_keyword.rb +110 -110
- data/test/opal/unsupported_and_bugs.rb +30 -0
- data/vendored-minitest/minitest/assertions.rb +1 -1
- metadata +65 -15
- data/.spectator +0 -2
- data/.spectator-mspec +0 -3
- data/opal/corelib/array/inheritance.rb +0 -127
- data/spec/rubyspecs +0 -139
data/stdlib/nodejs/dir.rb
CHANGED
@@ -2,12 +2,14 @@ class Dir
|
|
2
2
|
@__glob__ = node_require :glob
|
3
3
|
`var __glob__ = #{@__glob__}`
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
def [] glob
|
7
|
+
`__glob__.sync(#{glob})`
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def pwd
|
11
|
+
`process.cwd()`
|
12
|
+
end
|
13
|
+
alias getwd pwd
|
11
14
|
end
|
12
|
-
alias getwd pwd
|
13
15
|
end
|
data/stdlib/nodejs/file.rb
CHANGED
@@ -17,6 +17,7 @@ class File < IO
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.exist? path
|
20
|
+
path = path.path if path.respond_to? :path
|
20
21
|
`__fs__.existsSync(#{path})`
|
21
22
|
end
|
22
23
|
|
@@ -74,13 +75,22 @@ class File < IO
|
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
77
|
-
|
78
|
-
|
78
|
+
def self.stat path
|
79
|
+
path = path.path if path.respond_to? :path
|
80
|
+
File::Stat.new(path)
|
81
|
+
end
|
79
82
|
|
80
83
|
# Instance Methods
|
81
84
|
|
82
85
|
def initialize(path, flags)
|
83
|
-
|
86
|
+
binary_flag_regexp = /b/
|
87
|
+
encoding_flag_regexp = /:(.*)/
|
88
|
+
# binary flag is unsupported
|
89
|
+
warn "Binary flag (b) is unsupported by Node.js openSync method, removing flag." if flags.match(binary_flag_regexp)
|
90
|
+
flags = flags.gsub(binary_flag_regexp, '')
|
91
|
+
# encoding flag is unsupported
|
92
|
+
warn "Encoding flag (:encoding) is unsupported by Node.js openSync method, removing flag." if flags.match(encoding_flag_regexp)
|
93
|
+
flags = flags.gsub(encoding_flag_regexp, '')
|
84
94
|
@path = path
|
85
95
|
@flags = flags
|
86
96
|
@fd = `__fs__.openSync(path, flags)`
|
@@ -101,3 +111,18 @@ class File < IO
|
|
101
111
|
end
|
102
112
|
end
|
103
113
|
|
114
|
+
class File::Stat
|
115
|
+
|
116
|
+
@__fs__ = node_require :fs
|
117
|
+
`var __fs__ = #{@__fs__}`
|
118
|
+
|
119
|
+
def initialize(path)
|
120
|
+
@path = path
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
def file?
|
125
|
+
`__fs__.statSync(#{@path}).isFile()`
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
../js-yaml/bin/js-yaml.js
|
@@ -0,0 +1 @@
|
|
1
|
+
../esprima/bin/esparse.js
|
@@ -0,0 +1 @@
|
|
1
|
+
../esprima/bin/esvalidate.js
|
data/stdlib/nodejs/require.rb
CHANGED
data/stdlib/nodejs/yaml.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'native'
|
2
2
|
|
3
3
|
module YAML
|
4
|
-
|
4
|
+
@__yaml__ = node_require 'js-yaml'
|
5
|
+
`var __yaml__ = #{@__yaml__}`
|
5
6
|
|
6
7
|
def self.load_path path
|
7
|
-
loaded = `__yaml__.
|
8
|
+
loaded = `__yaml__.safeLoad(#{File}.__fs__.readFileSync(#{path}, 'utf8'))`
|
8
9
|
loaded = Hash.new(loaded) if native?(loaded)
|
9
10
|
loaded
|
10
11
|
end
|
data/stdlib/opal-parser.rb
CHANGED
@@ -4,8 +4,13 @@ require 'opal/version'
|
|
4
4
|
|
5
5
|
module Kernel
|
6
6
|
def eval(str)
|
7
|
-
|
8
|
-
|
7
|
+
str = Opal.coerce_to!(str, String, :to_str)
|
8
|
+
code = Opal.compile str, file: '(eval)', eval: true
|
9
|
+
%x{
|
10
|
+
return (function(self) {
|
11
|
+
return eval(#{code});
|
12
|
+
})(self)
|
13
|
+
}
|
9
14
|
end
|
10
15
|
|
11
16
|
def require_remote url
|
data/stdlib/pathname.rb
CHANGED
@@ -33,7 +33,7 @@ class Pathname
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def cleanpath
|
36
|
-
`return Opal.
|
36
|
+
`return Opal.normalize(#@path)`
|
37
37
|
end
|
38
38
|
|
39
39
|
def to_path
|
@@ -44,6 +44,28 @@ class Pathname
|
|
44
44
|
@path
|
45
45
|
end
|
46
46
|
|
47
|
+
def expand_path
|
48
|
+
File.expand_path @path
|
49
|
+
end
|
50
|
+
|
51
|
+
def +(other)
|
52
|
+
other = Pathname.new(other) unless Pathname === other
|
53
|
+
Pathname.new(File.join(@path, other.to_path))
|
54
|
+
end
|
55
|
+
|
56
|
+
def join(*args)
|
57
|
+
args.unshift self
|
58
|
+
result = args.pop
|
59
|
+
result = Pathname.new(result) unless Pathname === result
|
60
|
+
return result if result.absolute?
|
61
|
+
args.reverse_each {|arg|
|
62
|
+
arg = Pathname.new(arg) unless Pathname === arg
|
63
|
+
result = arg + result
|
64
|
+
return result if result.absolute?
|
65
|
+
}
|
66
|
+
result
|
67
|
+
end
|
68
|
+
|
47
69
|
alias :to_str :to_path
|
48
70
|
alias :to_s :to_path
|
49
71
|
end
|
data/stdlib/phantomjs.rb
CHANGED
@@ -5,3 +5,13 @@ STDERR.write_proc = `function(str){callPhantom(['stderr', str])}`
|
|
5
5
|
|
6
6
|
STDOUT.tty = true
|
7
7
|
STDERR.tty = true
|
8
|
+
|
9
|
+
ARGV += `JSON.parse(callPhantom(['argv']))`
|
10
|
+
|
11
|
+
%x{
|
12
|
+
var env = JSON.parse(callPhantom(['env']));
|
13
|
+
|
14
|
+
Object.keys(env).forEach(function(key) {
|
15
|
+
#{ENV[`key`] = `env[key]`}
|
16
|
+
});
|
17
|
+
}
|
data/stdlib/promise.rb
CHANGED
@@ -122,7 +122,7 @@ class Promise
|
|
122
122
|
@delayed = false
|
123
123
|
|
124
124
|
@prev = nil
|
125
|
-
@next =
|
125
|
+
@next = []
|
126
126
|
end
|
127
127
|
|
128
128
|
def value
|
@@ -171,7 +171,7 @@ class Promise
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def >>(promise)
|
174
|
-
@next
|
174
|
+
@next << promise
|
175
175
|
|
176
176
|
if exception?
|
177
177
|
promise.reject(@delayed[0])
|
@@ -214,8 +214,8 @@ class Promise
|
|
214
214
|
@realized = :resolve
|
215
215
|
@value = value
|
216
216
|
|
217
|
-
if @next
|
218
|
-
@next.resolve(value)
|
217
|
+
if @next.any?
|
218
|
+
@next.each { |p| p.resolve(value) }
|
219
219
|
else
|
220
220
|
@delayed = [value]
|
221
221
|
end
|
@@ -251,8 +251,8 @@ class Promise
|
|
251
251
|
@realized = :reject
|
252
252
|
@error = value
|
253
253
|
|
254
|
-
if @next
|
255
|
-
@next.reject(value)
|
254
|
+
if @next.any?
|
255
|
+
@next.each { |p| p.reject(value) }
|
256
256
|
else
|
257
257
|
@delayed = [value]
|
258
258
|
end
|
@@ -265,49 +265,64 @@ class Promise
|
|
265
265
|
end
|
266
266
|
|
267
267
|
def then(&block)
|
268
|
-
if @next
|
269
|
-
raise ArgumentError, 'a promise has already been chained'
|
270
|
-
end
|
271
|
-
|
272
268
|
self ^ Promise.new(success: block)
|
273
269
|
end
|
274
270
|
|
271
|
+
def then!(&block)
|
272
|
+
there_can_be_only_one!
|
273
|
+
self.then(&block)
|
274
|
+
end
|
275
|
+
|
275
276
|
alias do then
|
277
|
+
alias do! then!
|
276
278
|
|
277
279
|
def fail(&block)
|
278
|
-
if @next
|
279
|
-
raise ArgumentError, 'a promise has already been chained'
|
280
|
-
end
|
281
|
-
|
282
280
|
self ^ Promise.new(failure: block)
|
283
281
|
end
|
284
282
|
|
283
|
+
def fail!(&block)
|
284
|
+
there_can_be_only_one!
|
285
|
+
fail(&block)
|
286
|
+
end
|
287
|
+
|
285
288
|
alias rescue fail
|
286
289
|
alias catch fail
|
290
|
+
alias rescue! fail!
|
291
|
+
alias catch! fail!
|
287
292
|
|
288
293
|
def always(&block)
|
289
|
-
if @next
|
290
|
-
raise ArgumentError, 'a promise has already been chained'
|
291
|
-
end
|
292
|
-
|
293
294
|
self ^ Promise.new(always: block)
|
294
295
|
end
|
295
296
|
|
297
|
+
def always!(&block)
|
298
|
+
there_can_be_only_one!
|
299
|
+
always(&block)
|
300
|
+
end
|
301
|
+
|
296
302
|
alias finally always
|
297
303
|
alias ensure always
|
304
|
+
alias finally! always!
|
305
|
+
alias ensure! always!
|
298
306
|
|
299
307
|
def trace(depth = nil, &block)
|
300
|
-
|
308
|
+
self ^ Trace.new(depth, block)
|
309
|
+
end
|
310
|
+
|
311
|
+
def trace!(*args, &block)
|
312
|
+
there_can_be_only_one!
|
313
|
+
trace(*args, &block)
|
314
|
+
end
|
315
|
+
|
316
|
+
def there_can_be_only_one!
|
317
|
+
if @next.any?
|
301
318
|
raise ArgumentError, 'a promise has already been chained'
|
302
319
|
end
|
303
|
-
|
304
|
-
self ^ Trace.new(depth, block)
|
305
320
|
end
|
306
321
|
|
307
322
|
def inspect
|
308
323
|
result = "#<#{self.class}(#{object_id})"
|
309
324
|
|
310
|
-
if @next
|
325
|
+
if @next.any?
|
311
326
|
result += " >> #{@next.inspect}"
|
312
327
|
end
|
313
328
|
|
@@ -400,7 +415,7 @@ class Promise
|
|
400
415
|
@wait << promise
|
401
416
|
|
402
417
|
promise.always {
|
403
|
-
try if @next
|
418
|
+
try if @next.any?
|
404
419
|
}
|
405
420
|
|
406
421
|
self
|
data/tasks/building.rake
CHANGED
@@ -14,9 +14,9 @@ task :dist do
|
|
14
14
|
require 'opal/util'
|
15
15
|
require 'opal/sprockets/environment'
|
16
16
|
|
17
|
-
Opal::
|
18
|
-
Opal::
|
19
|
-
Opal::
|
17
|
+
Opal::Config.arity_check_enabled = false
|
18
|
+
Opal::Config.const_missing_enabled = false
|
19
|
+
Opal::Config.dynamic_require_severity = :warning
|
20
20
|
env = Opal::Environment.new
|
21
21
|
|
22
22
|
build_dir = ENV['DIR'] || 'build'
|
data/tasks/testing.rake
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# Remove when we drop support for 1.9.3
|
2
|
+
__dir__ = defined?(Kernel.__dir__) ? Kernel.__dir__ : File.dirname(File.realpath(__FILE__))
|
3
|
+
|
4
|
+
require "#{__dir__}/testing/mspec_special_calls"
|
2
5
|
|
3
6
|
require 'rspec/core/rake_task'
|
4
7
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
@@ -24,7 +27,7 @@ module Testing
|
|
24
27
|
whitelist_pattern = !!env['RUBYSPECS']
|
25
28
|
|
26
29
|
excepting = []
|
27
|
-
rubyspecs = File.read('spec/
|
30
|
+
rubyspecs = File.read('spec/ruby_specs').lines.reject do |l|
|
28
31
|
l.strip!
|
29
32
|
l.start_with?('#') || l.empty? || (l.start_with?('!') && excepting.push(l.sub('!', 'spec/') + '.rb'))
|
30
33
|
end.flat_map do |path|
|
@@ -37,7 +40,14 @@ module Testing
|
|
37
40
|
userspecs &= rubyspecs if whitelist_pattern
|
38
41
|
|
39
42
|
opalspec_filters = Dir['spec/filters/**/*_opal.rb']
|
40
|
-
|
43
|
+
|
44
|
+
if ENV['INVERT_RUNNING_MODE']
|
45
|
+
# When we run an inverted test suite we should run only 'bugs'.
|
46
|
+
# Unsupported features are not supported anyway
|
47
|
+
rubyspec_filters = Dir['spec/filters/bugs/*.rb'] - opalspec_filters
|
48
|
+
else
|
49
|
+
rubyspec_filters = Dir['spec/filters/**/*.rb'] - opalspec_filters
|
50
|
+
end
|
41
51
|
|
42
52
|
specs = []
|
43
53
|
add_specs = ->(name, new_specs) do
|
@@ -53,12 +63,12 @@ module Testing
|
|
53
63
|
add_specs["PATTERN=#{pattern}", userspecs]
|
54
64
|
elsif suite == 'opal'
|
55
65
|
add_specs['spec/opal', opalspecs]
|
56
|
-
elsif suite == '
|
57
|
-
add_specs['spec/
|
66
|
+
elsif suite == 'ruby'
|
67
|
+
add_specs['spec/ruby', rubyspecs]
|
58
68
|
else
|
59
69
|
warn 'Please provide at lease one of the following environment variables:'
|
60
|
-
warn 'PATTERN # e.g. PATTERN=spec/
|
61
|
-
warn 'SUITE # can be either SUITE=opal or SUITE=
|
70
|
+
warn 'PATTERN # e.g. PATTERN=spec/ruby/core/numeric/**_spec.rb'
|
71
|
+
warn 'SUITE # can be either SUITE=opal or SUITE=ruby'
|
62
72
|
exit 1
|
63
73
|
end
|
64
74
|
|
@@ -75,6 +85,7 @@ module Testing
|
|
75
85
|
File.write filename, <<-RUBY
|
76
86
|
require 'spec_helper'
|
77
87
|
require 'opal/platform'
|
88
|
+
OSpecRunner.main.will_start
|
78
89
|
#{enter_benchmarking_mode}
|
79
90
|
#{requires.join("\n ")}
|
80
91
|
OSpecFilter.main.unused_filters_message(list: #{!!ENV['LIST_UNUSED_FILTERS']})
|
@@ -98,12 +109,12 @@ pattern_usage = <<-DESC
|
|
98
109
|
Use PATTERN environment variable to manually set the glob for specs:
|
99
110
|
|
100
111
|
# Will run all specs matching the specified pattern.
|
101
|
-
# (Note: the
|
102
|
-
bundle exec rake mspec_node PATTERN=spec/
|
103
|
-
bundle exec rake mspec_node PATTERN=spec/
|
112
|
+
# (Note: the ruby_specs filters will still apply)
|
113
|
+
bundle exec rake mspec_node PATTERN=spec/ruby/core/module/class_variable*_spec.rb
|
114
|
+
bundle exec rake mspec_node PATTERN=spec/ruby/core/numeric/**_spec.rb
|
104
115
|
DESC
|
105
116
|
|
106
|
-
%w[
|
117
|
+
%w[ruby opal].each do |suite|
|
107
118
|
desc "Run the MSpec/#{suite} test suite on Opal::Sprockets/phantomjs" + pattern_usage
|
108
119
|
task :"mspec_#{suite}_sprockets_phantomjs" do
|
109
120
|
filename = File.expand_path('tmp/mspec_sprockets_phantomjs.rb')
|
@@ -160,9 +171,9 @@ DESC
|
|
160
171
|
end
|
161
172
|
end
|
162
173
|
|
163
|
-
task :mspec_phantomjs => [:mspec_opal_phantomjs, :
|
164
|
-
task :mspec_nodejs => [:mspec_opal_nodejs, :
|
165
|
-
task :mspec_sprockets_phantomjs => [:mspec_opal_sprockets_phantomjs, :
|
174
|
+
task :mspec_phantomjs => [:mspec_opal_phantomjs, :mspec_ruby_phantomjs]
|
175
|
+
task :mspec_nodejs => [:mspec_opal_nodejs, :mspec_ruby_nodejs]
|
176
|
+
task :mspec_sprockets_phantomjs => [:mspec_opal_sprockets_phantomjs, :mspec_ruby_sprockets_phantomjs]
|
166
177
|
|
167
178
|
task :jshint do
|
168
179
|
js_filename = 'tmp/jshint.js'
|
@@ -197,6 +208,8 @@ task :cruby_tests do
|
|
197
208
|
benchmark/test_benchmark.rb
|
198
209
|
ruby/test_call.rb
|
199
210
|
opal/test_keyword.rb
|
211
|
+
base64/test_base64.rb
|
212
|
+
opal/unsupported_and_bugs.rb
|
200
213
|
].flat_map do |path|
|
201
214
|
if path.end_with?('.rb')
|
202
215
|
path
|
@@ -6,7 +6,7 @@ class Opal::Nodes::CallNode
|
|
6
6
|
add_special :language_version do
|
7
7
|
if scope.top?
|
8
8
|
lang_type = arglist[2][1]
|
9
|
-
target = "
|
9
|
+
target = "ruby/language/versions/#{lang_type}_1.9"
|
10
10
|
|
11
11
|
if File.exist?(target)
|
12
12
|
compiler.requires << target
|
@@ -37,6 +37,10 @@ page.onCallback = function(data) {
|
|
37
37
|
case 'stderr':
|
38
38
|
system.stderr.write(data[1] || '');
|
39
39
|
break;
|
40
|
+
case 'env':
|
41
|
+
return JSON.stringify(system.env);
|
42
|
+
case 'argv':
|
43
|
+
return JSON.stringify(system.args.slice(1));
|
40
44
|
default:
|
41
45
|
console.error('Unknown callback data: ', data);
|
42
46
|
}
|
data/test/opal/test_keyword.rb
CHANGED
@@ -51,17 +51,17 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
51
51
|
# assert_raise(ArgumentError) { f4(str: "bar", check: true) }
|
52
52
|
# assert_raise(ArgumentError) { f4("string") }
|
53
53
|
# end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
|
55
|
+
define_method(:f5) {|str: "foo", num: 424242, **h| [str, num, h] }
|
56
|
+
|
57
|
+
def test_f5
|
58
|
+
assert_equal(["foo", 424242, {}], f5)
|
59
|
+
assert_equal(["bar", 424242, {}], f5(str: "bar"))
|
60
|
+
assert_equal(["foo", 111111, {}], f5(num: 111111))
|
61
|
+
assert_equal(["bar", 111111, {}], f5(str: "bar", num: 111111))
|
62
|
+
assert_equal(["bar", 424242, {:check=>true}], f5(str: "bar", check: true))
|
63
|
+
assert_raise(ArgumentError) { f5("string") }
|
64
|
+
end
|
65
65
|
|
66
66
|
|
67
67
|
def f6(str: "foo", num: 424242, **h, &blk)
|
@@ -96,16 +96,16 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
96
96
|
assert_equal([[1, 2, 3], "bar", 424242, {}], f7(1, 2, 3, str: "bar"))
|
97
97
|
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
99
|
+
define_method(:f8) { |opt = :ion, *rest, key: :word|
|
100
|
+
[opt, rest, key]
|
101
|
+
}
|
102
|
+
|
103
|
+
def test_f8
|
104
|
+
assert_equal([:ion, [], :word], f8)
|
105
|
+
assert_equal([1, [], :word], f8(1))
|
106
|
+
assert_equal([1, [2], :word], f8(1, 2))
|
107
|
+
end
|
108
|
+
|
109
109
|
# def f9(r, o=42, *args, p, k: :key, **kw, &b)
|
110
110
|
# [r, o, args, p, k, kw, b]
|
111
111
|
# end
|
@@ -141,15 +141,15 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
141
141
|
[:keyrest, :kw], [:block, :b]], method(:f9).parameters)
|
142
142
|
end
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
144
|
+
def test_lambda
|
145
|
+
f = ->(str: "foo", num: 424242) { [str, num] }
|
146
|
+
assert_equal(["foo", 424242], f[])
|
147
|
+
assert_equal(["bar", 424242], f[str: "bar"])
|
148
|
+
assert_equal(["foo", 111111], f[num: 111111])
|
149
|
+
assert_equal(["bar", 111111], f[str: "bar", num: 111111])
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
153
|
# def p1
|
154
154
|
# Proc.new do |str: "foo", num: 424242|
|
155
155
|
# [str, num]
|
@@ -164,20 +164,20 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
164
164
|
# assert_raise(ArgumentError) { p1[str: "bar", check: true] }
|
165
165
|
# assert_equal(["foo", 424242], p1["string"] )
|
166
166
|
# end
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
167
|
+
|
168
|
+
|
169
|
+
def p2
|
170
|
+
Proc.new do |x, str: "foo", num: 424242|
|
171
|
+
[x, str, num]
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_p2
|
176
|
+
assert_equal([nil, "foo", 424242], p2[])
|
177
|
+
assert_equal([:xyz, "foo", 424242], p2[:xyz])
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
181
|
# def p3
|
182
182
|
# Proc.new do |str: "foo", num: 424242, **h|
|
183
183
|
# [str, num, h]
|
@@ -192,46 +192,46 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
192
192
|
# assert_equal(["bar", 424242, {:check=>true}], p3[str: "bar", check: true])
|
193
193
|
# assert_equal(["foo", 424242, {}], p3["string"])
|
194
194
|
# end
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
195
|
+
|
196
|
+
|
197
|
+
def p4
|
198
|
+
Proc.new do |str: "foo", num: 424242, **h, &blk|
|
199
|
+
[str, num, h, blk]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_p4
|
204
|
+
assert_equal(["foo", 424242, {}, nil], p4[])
|
205
|
+
assert_equal(["bar", 424242, {}, nil], p4[str: "bar"])
|
206
|
+
assert_equal(["foo", 111111, {}, nil], p4[num: 111111])
|
207
|
+
assert_equal(["bar", 111111, {}, nil], p4[str: "bar", num: 111111])
|
208
|
+
assert_equal(["bar", 424242, {:check=>true}, nil], p4[str: "bar", check: true])
|
209
|
+
a = p4.call {|x| x + 42 }
|
210
|
+
assert_equal(["foo", 424242, {}], a[0, 3])
|
211
|
+
assert_equal(43, a.last.call(1))
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
def p5
|
216
|
+
Proc.new do |*r, str: "foo", num: 424242, **h|
|
217
|
+
[r, str, num, h]
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_p5
|
222
|
+
assert_equal([[], "foo", 424242, {}], p5[])
|
223
|
+
assert_equal([[], "bar", 424242, {}], p5[str: "bar"])
|
224
|
+
assert_equal([[], "foo", 111111, {}], p5[num: 111111])
|
225
|
+
assert_equal([[], "bar", 111111, {}], p5[str: "bar", num: 111111])
|
226
|
+
assert_equal([[1], "foo", 424242, {}], p5[1])
|
227
|
+
assert_equal([[1, 2], "foo", 424242, {}], p5[1, 2])
|
228
|
+
assert_equal([[1, 2, 3], "foo", 424242, {}], p5[1, 2, 3])
|
229
|
+
assert_equal([[1], "bar", 424242, {}], p5[1, str: "bar"])
|
230
|
+
assert_equal([[1, 2], "bar", 424242, {}], p5[1, 2, str: "bar"])
|
231
|
+
assert_equal([[1, 2, 3], "bar", 424242, {}], p5[1, 2, 3, str: "bar"])
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
235
|
# def p6
|
236
236
|
# Proc.new do |o1, o2=42, *args, p, k: :key, **kw, &b|
|
237
237
|
# [o1, o2, args, p, k, kw, b]
|
@@ -255,19 +255,19 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
255
255
|
# assert_equal([[:opt, :o1], [:opt, :o2], [:rest, :args], [:opt, :p], [:key, :k],
|
256
256
|
# [:keyrest, :kw], [:block, :b]], p6.parameters)
|
257
257
|
# end
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
258
|
+
|
259
|
+
def m1(*args)
|
260
|
+
yield(*args)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_block
|
264
|
+
blk = Proc.new {|str: "foo", num: 424242| [str, num] }
|
265
|
+
assert_equal(["foo", 424242], m1(&blk))
|
266
|
+
assert_equal(["bar", 424242], m1(str: "bar", &blk))
|
267
|
+
assert_equal(["foo", 111111], m1(num: 111111, &blk))
|
268
|
+
assert_equal(["bar", 111111], m1(str: "bar", num: 111111, &blk))
|
269
|
+
end
|
270
|
+
|
271
271
|
# def rest_keyrest(*args, **opt)
|
272
272
|
# return *args, opt
|
273
273
|
# end
|
@@ -570,21 +570,21 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|
570
570
|
# assert_equal({:bar => "bar"}, obj.foo, bug10659)
|
571
571
|
# }
|
572
572
|
# end
|
573
|
-
|
574
|
-
|
575
|
-
|
573
|
+
|
574
|
+
def m(a) yield a end
|
575
|
+
|
576
576
|
# def test_nonsymbol_key
|
577
577
|
# result = m(["a" => 10]) { |a = nil, **b| [a, b] }
|
578
578
|
# assert_equal([{"a" => 10}, {}], result)
|
579
579
|
# end
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
580
|
+
|
581
|
+
def method_for_test_to_hash_call_during_setup_complex_parameters k1:, k2:, **rest_kw
|
582
|
+
[k1, k2, rest_kw]
|
583
|
+
end
|
584
|
+
|
585
|
+
def test_to_hash_call_during_setup_complex_parameters
|
586
|
+
sym = "sym_#{Time.now}".to_sym
|
587
|
+
h = method_for_test_to_hash_call_during_setup_complex_parameters k1: "foo", k2: "bar", sym => "baz"
|
588
|
+
assert_equal ["foo", "bar", {sym => "baz"}], h, '[Bug #11027]'
|
589
|
+
end
|
590
590
|
end
|