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
@@ -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 = "rubyspec/language/versions/#{lang_type}_1.9"
|
10
10
|
|
11
11
|
if File.exist?(target)
|
12
12
|
compiler.requires << target
|
@@ -3,6 +3,17 @@
|
|
3
3
|
*/
|
4
4
|
var args = phantom.args;
|
5
5
|
var page = require('webpage').create();
|
6
|
+
var url = args[0];
|
7
|
+
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Exit phantom instance "safely" see - https://github.com/ariya/phantomjs/issues/12697
|
11
|
+
* https://github.com/nobuoka/gulp-qunit/commit/d242aff9b79de7543d956e294b2ee36eda4bac6c
|
12
|
+
*/
|
13
|
+
function phantom_exit(code) {
|
14
|
+
page.close();
|
15
|
+
setTimeout(function () { phantom.exit(code); }, 0);
|
16
|
+
}
|
6
17
|
|
7
18
|
page.onConsoleMessage = function(msg) {
|
8
19
|
console.log(msg);
|
@@ -19,7 +30,7 @@ page.onCallback = function(data) {
|
|
19
30
|
switch (data[0]) {
|
20
31
|
case 'exit':
|
21
32
|
var status = data[1] || 0;
|
22
|
-
|
33
|
+
phantom_exit(status);
|
23
34
|
case 'stdout':
|
24
35
|
system.stdout.write(data[1] || '');
|
25
36
|
break;
|
@@ -31,17 +42,17 @@ page.onCallback = function(data) {
|
|
31
42
|
}
|
32
43
|
};
|
33
44
|
|
34
|
-
page.open(
|
45
|
+
page.open(url, function(status) {
|
35
46
|
if (status !== 'success') {
|
36
|
-
console.error("Cannot load: " +
|
37
|
-
|
47
|
+
console.error("Cannot load: " + url);
|
48
|
+
phantom_exit(1);
|
38
49
|
} else {
|
39
50
|
var timeout = parseInt(args[1] || 60000, 10);
|
40
51
|
var start = Date.now();
|
41
52
|
var interval = setInterval(function() {
|
42
53
|
if (Date.now() > start + timeout) {
|
43
54
|
console.error("Specs timed out");
|
44
|
-
|
55
|
+
phantom_exit(124);
|
45
56
|
} else {
|
46
57
|
var code = page.evaluate(function() {
|
47
58
|
return window.OPAL_SPEC_CODE;
|
@@ -49,7 +60,7 @@ page.open(args[0], function(status) {
|
|
49
60
|
|
50
61
|
if (code === 0 || code === 1) {
|
51
62
|
clearInterval(interval);
|
52
|
-
|
63
|
+
phantom_exit(code);
|
53
64
|
}
|
54
65
|
}
|
55
66
|
}, 500);
|
@@ -0,0 +1,590 @@
|
|
1
|
+
# Copied from cruby and modified to skip unsupported syntaxes
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestKeywordArguments < Test::Unit::TestCase
|
5
|
+
def f1(str: "foo", num: 424242)
|
6
|
+
[str, num]
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_f1
|
10
|
+
skip %{TypeError: no implicit conversion of NilClass into String}
|
11
|
+
|
12
|
+
assert_equal(["foo", 424242], f1)
|
13
|
+
assert_equal(["bar", 424242], f1(str: "bar"))
|
14
|
+
assert_equal(["foo", 111111], f1(num: 111111))
|
15
|
+
assert_equal(["bar", 111111], f1(str: "bar", num: 111111))
|
16
|
+
assert_raise(ArgumentError) { f1(str: "bar", check: true) }
|
17
|
+
assert_raise(ArgumentError) { f1("string") }
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def f2(x, str: "foo", num: 424242)
|
22
|
+
[x, str, num]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_f2
|
26
|
+
assert_equal([:xyz, "foo", 424242], f2(:xyz))
|
27
|
+
assert_equal([{"bar"=>42}, "foo", 424242], f2("bar"=>42))
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def f3(str: "foo", num: 424242, **h)
|
32
|
+
[str, num, h]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_f3
|
36
|
+
assert_equal(["foo", 424242, {}], f3)
|
37
|
+
assert_equal(["bar", 424242, {}], f3(str: "bar"))
|
38
|
+
assert_equal(["foo", 111111, {}], f3(num: 111111))
|
39
|
+
assert_equal(["bar", 111111, {}], f3(str: "bar", num: 111111))
|
40
|
+
assert_equal(["bar", 424242, {:check=>true}], f3(str: "bar", check: true))
|
41
|
+
assert_raise(ArgumentError) { f3("string") }
|
42
|
+
end
|
43
|
+
|
44
|
+
# define_method(:f4) {|str: "foo", num: 424242| [str, num] }
|
45
|
+
#
|
46
|
+
# def test_f4
|
47
|
+
# assert_equal(["foo", 424242], f4)
|
48
|
+
# assert_equal(["bar", 424242], f4(str: "bar"))
|
49
|
+
# assert_equal(["foo", 111111], f4(num: 111111))
|
50
|
+
# assert_equal(["bar", 111111], f4(str: "bar", num: 111111))
|
51
|
+
# assert_raise(ArgumentError) { f4(str: "bar", check: true) }
|
52
|
+
# assert_raise(ArgumentError) { f4("string") }
|
53
|
+
# end
|
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
|
+
|
66
|
+
|
67
|
+
def f6(str: "foo", num: 424242, **h, &blk)
|
68
|
+
[str, num, h, blk]
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_f6 # [ruby-core:40518]
|
72
|
+
assert_equal(["foo", 424242, {}, nil], f6)
|
73
|
+
assert_equal(["bar", 424242, {}, nil], f6(str: "bar"))
|
74
|
+
assert_equal(["foo", 111111, {}, nil], f6(num: 111111))
|
75
|
+
assert_equal(["bar", 111111, {}, nil], f6(str: "bar", num: 111111))
|
76
|
+
assert_equal(["bar", 424242, {:check=>true}, nil], f6(str: "bar", check: true))
|
77
|
+
a = f6 {|x| x + 42 }
|
78
|
+
assert_equal(["foo", 424242, {}], a[0, 3])
|
79
|
+
assert_equal(43, a.last.call(1))
|
80
|
+
end
|
81
|
+
|
82
|
+
def f7(*r, str: "foo", num: 424242, **h)
|
83
|
+
[r, str, num, h]
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_f7 # [ruby-core:41772]
|
87
|
+
assert_equal([[], "foo", 424242, {}], f7)
|
88
|
+
assert_equal([[], "bar", 424242, {}], f7(str: "bar"))
|
89
|
+
assert_equal([[], "foo", 111111, {}], f7(num: 111111))
|
90
|
+
assert_equal([[], "bar", 111111, {}], f7(str: "bar", num: 111111))
|
91
|
+
assert_equal([[1], "foo", 424242, {}], f7(1))
|
92
|
+
assert_equal([[1, 2], "foo", 424242, {}], f7(1, 2))
|
93
|
+
assert_equal([[1, 2, 3], "foo", 424242, {}], f7(1, 2, 3))
|
94
|
+
assert_equal([[1], "bar", 424242, {}], f7(1, str: "bar"))
|
95
|
+
assert_equal([[1, 2], "bar", 424242, {}], f7(1, 2, str: "bar"))
|
96
|
+
assert_equal([[1, 2, 3], "bar", 424242, {}], f7(1, 2, 3, str: "bar"))
|
97
|
+
end
|
98
|
+
|
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
|
+
# def f9(r, o=42, *args, p, k: :key, **kw, &b)
|
110
|
+
# [r, o, args, p, k, kw, b]
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# def test_f9
|
114
|
+
# assert_equal([1, 42, [], 2, :key, {}, nil], f9(1, 2))
|
115
|
+
# assert_equal([1, 2, [], 3, :key, {}, nil], f9(1, 2, 3))
|
116
|
+
# assert_equal([1, 2, [3], 4, :key, {}, nil], f9(1, 2, 3, 4))
|
117
|
+
# assert_equal([1, 2, [3, 4], 5, :key, {str: "bar"}, nil], f9(1, 2, 3, 4, 5, str: "bar"))
|
118
|
+
# end
|
119
|
+
|
120
|
+
def f10(a: 1, **)
|
121
|
+
a
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_f10
|
125
|
+
assert_equal(42, f10(a: 42))
|
126
|
+
assert_equal(1, f10(b: 42))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_method_parameters
|
130
|
+
skip %{NoMethodError: undefined method `parameters' for #<Method: TestKeywordArguments#f1>}
|
131
|
+
|
132
|
+
assert_equal([[:key, :str], [:key, :num]], method(:f1).parameters);
|
133
|
+
assert_equal([[:req, :x], [:key, :str], [:key, :num]], method(:f2).parameters);
|
134
|
+
assert_equal([[:key, :str], [:key, :num], [:keyrest, :h]], method(:f3).parameters);
|
135
|
+
assert_equal([[:key, :str], [:key, :num]], method(:f4).parameters);
|
136
|
+
assert_equal([[:key, :str], [:key, :num], [:keyrest, :h]], method(:f5).parameters);
|
137
|
+
assert_equal([[:key, :str], [:key, :num], [:keyrest, :h], [:block, :blk]], method(:f6).parameters);
|
138
|
+
assert_equal([[:rest, :r], [:key, :str], [:key, :num], [:keyrest, :h]], method(:f7).parameters);
|
139
|
+
assert_equal([[:opt, :opt], [:rest, :rest], [:key, :key]], method(:f8).parameters) # [Bug #7540] [ruby-core:50735]
|
140
|
+
assert_equal([[:req, :r], [:opt, :o], [:rest, :args], [:req, :p], [:key, :k],
|
141
|
+
[:keyrest, :kw], [:block, :b]], method(:f9).parameters)
|
142
|
+
end
|
143
|
+
|
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
|
+
# def p1
|
154
|
+
# Proc.new do |str: "foo", num: 424242|
|
155
|
+
# [str, num]
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# def test_p1
|
160
|
+
# assert_equal(["foo", 424242], p1[])
|
161
|
+
# assert_equal(["bar", 424242], p1[str: "bar"])
|
162
|
+
# assert_equal(["foo", 111111], p1[num: 111111])
|
163
|
+
# assert_equal(["bar", 111111], p1[str: "bar", num: 111111])
|
164
|
+
# assert_raise(ArgumentError) { p1[str: "bar", check: true] }
|
165
|
+
# assert_equal(["foo", 424242], p1["string"] )
|
166
|
+
# end
|
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
|
+
# def p3
|
182
|
+
# Proc.new do |str: "foo", num: 424242, **h|
|
183
|
+
# [str, num, h]
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
#
|
187
|
+
# def test_p3
|
188
|
+
# assert_equal(["foo", 424242, {}], p3[])
|
189
|
+
# assert_equal(["bar", 424242, {}], p3[str: "bar"])
|
190
|
+
# assert_equal(["foo", 111111, {}], p3[num: 111111])
|
191
|
+
# assert_equal(["bar", 111111, {}], p3[str: "bar", num: 111111])
|
192
|
+
# assert_equal(["bar", 424242, {:check=>true}], p3[str: "bar", check: true])
|
193
|
+
# assert_equal(["foo", 424242, {}], p3["string"])
|
194
|
+
# end
|
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
|
+
# def p6
|
236
|
+
# Proc.new do |o1, o2=42, *args, p, k: :key, **kw, &b|
|
237
|
+
# [o1, o2, args, p, k, kw, b]
|
238
|
+
# end
|
239
|
+
# end
|
240
|
+
#
|
241
|
+
# def test_p6
|
242
|
+
# assert_equal([nil, 42, [], nil, :key, {}, nil], p6[])
|
243
|
+
# assert_equal([1, 42, [], 2, :key, {}, nil], p6[1, 2])
|
244
|
+
# assert_equal([1, 2, [], 3, :key, {}, nil], p6[1, 2, 3])
|
245
|
+
# assert_equal([1, 2, [3], 4, :key, {}, nil], p6[1, 2, 3, 4])
|
246
|
+
# assert_equal([1, 2, [3, 4], 5, :key, {str: "bar"}, nil], p6[1, 2, 3, 4, 5, str: "bar"])
|
247
|
+
# end
|
248
|
+
#
|
249
|
+
# def test_proc_parameters
|
250
|
+
# assert_equal([[:key, :str], [:key, :num]], p1.parameters);
|
251
|
+
# assert_equal([[:opt, :x], [:key, :str], [:key, :num]], p2.parameters);
|
252
|
+
# assert_equal([[:key, :str], [:key, :num], [:keyrest, :h]], p3.parameters);
|
253
|
+
# assert_equal([[:key, :str], [:key, :num], [:keyrest, :h], [:block, :blk]], p4.parameters);
|
254
|
+
# assert_equal([[:rest, :r], [:key, :str], [:key, :num], [:keyrest, :h]], p5.parameters);
|
255
|
+
# assert_equal([[:opt, :o1], [:opt, :o2], [:rest, :args], [:opt, :p], [:key, :k],
|
256
|
+
# [:keyrest, :kw], [:block, :b]], p6.parameters)
|
257
|
+
# end
|
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
|
+
# def rest_keyrest(*args, **opt)
|
272
|
+
# return *args, opt
|
273
|
+
# end
|
274
|
+
#
|
275
|
+
# def test_rest_keyrest
|
276
|
+
# bug7665 = '[ruby-core:51278]'
|
277
|
+
# bug8463 = '[ruby-core:55203] [Bug #8463]'
|
278
|
+
# expect = [*%w[foo bar], {zzz: 42}]
|
279
|
+
# assert_equal(expect, rest_keyrest(*expect), bug7665)
|
280
|
+
# pr = proc {|*args, **opt| next *args, opt}
|
281
|
+
# assert_equal(expect, pr.call(*expect), bug7665)
|
282
|
+
# assert_equal(expect, pr.call(expect), bug8463)
|
283
|
+
# pr = proc {|a, *b, **opt| next a, *b, opt}
|
284
|
+
# assert_equal(expect, pr.call(expect), bug8463)
|
285
|
+
# pr = proc {|a, **opt| next a, opt}
|
286
|
+
# assert_equal(expect.values_at(0, -1), pr.call(expect), bug8463)
|
287
|
+
# end
|
288
|
+
|
289
|
+
def test_bare_kwrest
|
290
|
+
skip "NoMethodError: undefined method `assert_valid_syntax' for TestKeywordArguments#test_bare_kwrest"
|
291
|
+
# valid syntax, but its semantics is undefined
|
292
|
+
assert_valid_syntax("def bug7662(**) end")
|
293
|
+
assert_valid_syntax("def bug7662(*, **) end")
|
294
|
+
assert_valid_syntax("def bug7662(a, **) end")
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_without_paren
|
298
|
+
skip %{NoMethodError: undefined method `assert_valid_syntax' for TestKeywordArguments#test_without_paren}
|
299
|
+
|
300
|
+
bug7942 = '[ruby-core:52820] [Bug #7942]'
|
301
|
+
assert_valid_syntax("def bug7942 a: 1; end")
|
302
|
+
assert_valid_syntax("def bug7942 a: 1, **; end")
|
303
|
+
|
304
|
+
o = Object.new
|
305
|
+
eval("def o.bug7942 a: 1; a; end", nil, __FILE__, __LINE__)
|
306
|
+
assert_equal(1, o.bug7942(), bug7942)
|
307
|
+
assert_equal(42, o.bug7942(a: 42), bug7942)
|
308
|
+
|
309
|
+
o = Object.new
|
310
|
+
eval("def o.bug7942 a: 1, **; a; end", nil, __FILE__, __LINE__)
|
311
|
+
assert_equal(1, o.bug7942(), bug7942)
|
312
|
+
assert_equal(42, o.bug7942(a: 42), bug7942)
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_required_keyword
|
316
|
+
skip %{ArgumentError: [TestKeywordArguments#eval] wrong number of arguments(3 for 1)}
|
317
|
+
|
318
|
+
feature7701 = '[ruby-core:51454] [Feature #7701] required keyword argument'
|
319
|
+
o = Object.new
|
320
|
+
assert_nothing_raised(SyntaxError, feature7701) do
|
321
|
+
eval("def o.foo(a:) a; end", nil, "xyzzy")
|
322
|
+
eval("def o.bar(a:,**b) [a, b]; end")
|
323
|
+
end
|
324
|
+
assert_raise_with_message(ArgumentError, /missing keyword/, feature7701) {o.foo}
|
325
|
+
assert_raise_with_message(ArgumentError, /unknown keyword/, feature7701) {o.foo(a:0, b:1)}
|
326
|
+
begin
|
327
|
+
o.foo(a: 0, b: 1)
|
328
|
+
rescue => e
|
329
|
+
assert_equal('xyzzy', e.backtrace_locations[0].path)
|
330
|
+
end
|
331
|
+
assert_equal(42, o.foo(a: 42), feature7701)
|
332
|
+
assert_equal([[:keyreq, :a]], o.method(:foo).parameters, feature7701)
|
333
|
+
|
334
|
+
bug8139 = '[ruby-core:53608] [Bug #8139] required keyword argument with rest hash'
|
335
|
+
assert_equal([42, {}], o.bar(a: 42), feature7701)
|
336
|
+
assert_equal([42, {c: feature7701}], o.bar(a: 42, c: feature7701), feature7701)
|
337
|
+
assert_equal([[:keyreq, :a], [:keyrest, :b]], o.method(:bar).parameters, feature7701)
|
338
|
+
assert_raise_with_message(ArgumentError, /missing keyword/, bug8139) {o.bar(c: bug8139)}
|
339
|
+
assert_raise_with_message(ArgumentError, /missing keyword/, bug8139) {o.bar}
|
340
|
+
end
|
341
|
+
|
342
|
+
# def test_required_keyword_with_newline
|
343
|
+
# bug9669 = '[ruby-core:61658] [Bug #9669]'
|
344
|
+
# assert_nothing_raised(SyntaxError, bug9669) do
|
345
|
+
# eval(<<-'end;', nil, __FILE__, __LINE__)
|
346
|
+
# def bug9669.foo a:
|
347
|
+
# return a
|
348
|
+
# end
|
349
|
+
# end;
|
350
|
+
# end
|
351
|
+
# assert_equal(42, bug9669.foo(a: 42))
|
352
|
+
# o = nil
|
353
|
+
# assert_nothing_raised(SyntaxError, bug9669) do
|
354
|
+
# eval(<<-'end;', nil, __FILE__, __LINE__)
|
355
|
+
# o = {
|
356
|
+
# a:
|
357
|
+
# 1
|
358
|
+
# }
|
359
|
+
# end;
|
360
|
+
# end
|
361
|
+
# assert_equal({a: 1}, o, bug9669)
|
362
|
+
# end
|
363
|
+
#
|
364
|
+
# def test_required_keyword_with_reserved
|
365
|
+
# bug10279 = '[ruby-core:65211] [Bug #10279]'
|
366
|
+
# h = nil
|
367
|
+
# assert_nothing_raised(SyntaxError, bug10279) do
|
368
|
+
# break eval(<<-'end;', nil, __FILE__, __LINE__)
|
369
|
+
# h = {a: if true then 42 end}
|
370
|
+
# end;
|
371
|
+
# end
|
372
|
+
# assert_equal({a: 42}, h, bug10279)
|
373
|
+
# end
|
374
|
+
|
375
|
+
def test_block_required_keyword
|
376
|
+
skip "ArgumentError: [TestKeywordArguments#eval] wrong number of arguments(4 for 1)"
|
377
|
+
|
378
|
+
feature7701 = '[ruby-core:51454] [Feature #7701] required keyword argument'
|
379
|
+
b = assert_nothing_raised(SyntaxError, feature7701) do
|
380
|
+
break eval("proc {|a:| a}", nil, 'xyzzy', __LINE__)
|
381
|
+
end
|
382
|
+
assert_raise_with_message(ArgumentError, /missing keyword/, feature7701) {b.call}
|
383
|
+
assert_raise_with_message(ArgumentError, /unknown keyword/, feature7701) {b.call(a:0, b:1)}
|
384
|
+
begin
|
385
|
+
b.call(a: 0, b: 1)
|
386
|
+
rescue => e
|
387
|
+
assert_equal('xyzzy', e.backtrace_locations[0].path)
|
388
|
+
end
|
389
|
+
|
390
|
+
assert_equal(42, b.call(a: 42), feature7701)
|
391
|
+
assert_equal([[:keyreq, :a]], b.parameters, feature7701)
|
392
|
+
|
393
|
+
bug8139 = '[ruby-core:53608] [Bug #8139] required keyword argument with rest hash'
|
394
|
+
b = assert_nothing_raised(SyntaxError, feature7701) do
|
395
|
+
break eval("proc {|a:, **bl| [a, bl]}", nil, __FILE__, __LINE__)
|
396
|
+
end
|
397
|
+
assert_equal([42, {}], b.call(a: 42), feature7701)
|
398
|
+
assert_equal([42, {c: feature7701}], b.call(a: 42, c: feature7701), feature7701)
|
399
|
+
assert_equal([[:keyreq, :a], [:keyrest, :bl]], b.parameters, feature7701)
|
400
|
+
assert_raise_with_message(ArgumentError, /missing keyword/, bug8139) {b.call(c: bug8139)}
|
401
|
+
assert_raise_with_message(ArgumentError, /missing keyword/, bug8139) {b.call}
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_super_with_keyword
|
405
|
+
skip %{NoMethodError: undefined method `encode' for "[42, {\"bar\"=>\"x\"}]":String}
|
406
|
+
bug8236 = '[ruby-core:54094] [Bug #8236]'
|
407
|
+
base = Class.new do
|
408
|
+
def foo(*args)
|
409
|
+
args
|
410
|
+
end
|
411
|
+
end
|
412
|
+
a = Class.new(base) do
|
413
|
+
def foo(arg, bar: 'x')
|
414
|
+
super
|
415
|
+
end
|
416
|
+
end
|
417
|
+
b = Class.new(base) do
|
418
|
+
def foo(*args, bar: 'x')
|
419
|
+
super
|
420
|
+
end
|
421
|
+
end
|
422
|
+
assert_equal([42, {:bar=>"x"}], a.new.foo(42), bug8236)
|
423
|
+
assert_equal([42, {:bar=>"x"}], b.new.foo(42), bug8236)
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_zsuper_only_named_kwrest
|
427
|
+
bug8416 = '[ruby-core:55033] [Bug #8416]'
|
428
|
+
base = Class.new do
|
429
|
+
def foo(**h)
|
430
|
+
h
|
431
|
+
end
|
432
|
+
end
|
433
|
+
a = Class.new(base) do
|
434
|
+
def foo(**h)
|
435
|
+
super
|
436
|
+
end
|
437
|
+
end
|
438
|
+
assert_equal({:bar=>"x"}, a.new.foo(bar: "x"), bug8416)
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_zsuper_only_anonymous_kwrest
|
442
|
+
bug8416 = '[ruby-core:55033] [Bug #8416]'
|
443
|
+
base = Class.new do
|
444
|
+
def foo(**h)
|
445
|
+
h
|
446
|
+
end
|
447
|
+
end
|
448
|
+
a = Class.new(base) do
|
449
|
+
def foo(**)
|
450
|
+
super
|
451
|
+
end
|
452
|
+
end
|
453
|
+
assert_equal({:bar=>"x"}, a.new.foo(bar: "x"), bug8416)
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_precedence_of_keyword_arguments
|
457
|
+
bug8040 = '[ruby-core:53199] [Bug #8040]'
|
458
|
+
a = Class.new do
|
459
|
+
def foo(x, **h)
|
460
|
+
[x, h]
|
461
|
+
end
|
462
|
+
end
|
463
|
+
assert_equal([{}, {}], a.new.foo({}))
|
464
|
+
assert_equal([{}, {:bar=>"x"}], a.new.foo({}, bar: "x"), bug8040)
|
465
|
+
end
|
466
|
+
|
467
|
+
# def test_precedence_of_keyword_arguments_with_post_argument
|
468
|
+
# bug8993 = '[ruby-core:57706] [Bug #8993]'
|
469
|
+
# a = Class.new do
|
470
|
+
# def foo(a, b, c=1, *d, e, f:2, **g)
|
471
|
+
# [a, b, c, d, e, f, g]
|
472
|
+
# end
|
473
|
+
# end
|
474
|
+
# assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993)
|
475
|
+
# end
|
476
|
+
#
|
477
|
+
# def test_splat_keyword_nondestructive
|
478
|
+
# bug9776 = '[ruby-core:62161] [Bug #9776]'
|
479
|
+
#
|
480
|
+
# h = {a: 1}
|
481
|
+
# assert_equal({a:1, b:2}, {**h, b:2})
|
482
|
+
# assert_equal({a:1}, h, bug9776)
|
483
|
+
#
|
484
|
+
# pr = proc {|**opt| next opt}
|
485
|
+
# assert_equal({a: 1}, pr.call(**h))
|
486
|
+
# assert_equal({a: 1, b: 2}, pr.call(**h, b: 2))
|
487
|
+
# assert_equal({a: 1}, h, bug9776)
|
488
|
+
# end
|
489
|
+
#
|
490
|
+
# def test_splat_hash_conversion
|
491
|
+
# bug9898 = '[ruby-core:62921] [Bug #9898]'
|
492
|
+
#
|
493
|
+
# o = Object.new
|
494
|
+
# def o.to_hash() { a: 1 } end
|
495
|
+
# assert_equal({a: 1}, m1(**o) {|x| break x}, bug9898)
|
496
|
+
# o2 = Object.new
|
497
|
+
# def o2.to_hash() { b: 2 } end
|
498
|
+
# assert_equal({a: 1, b: 2}, m1(**o, **o2) {|x| break x}, bug9898)
|
499
|
+
# end
|
500
|
+
#
|
501
|
+
# def test_implicit_hash_conversion
|
502
|
+
# bug10016 = '[ruby-core:63593] [Bug #10016]'
|
503
|
+
#
|
504
|
+
# o = Object.new
|
505
|
+
# def o.to_hash() { k: 9 } end
|
506
|
+
# assert_equal([1, 42, [], o, :key, {}, nil], f9(1, o))
|
507
|
+
# assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016)
|
508
|
+
# assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016)
|
509
|
+
# end
|
510
|
+
#
|
511
|
+
# def test_gced_object_in_stack
|
512
|
+
# bug8964 = '[ruby-dev:47729] [Bug #8964]'
|
513
|
+
# assert_normal_exit %q{
|
514
|
+
# def m(a: [])
|
515
|
+
# end
|
516
|
+
# GC.stress = true
|
517
|
+
# tap { m }
|
518
|
+
# GC.start
|
519
|
+
# tap { m }
|
520
|
+
# }, bug8964
|
521
|
+
# assert_normal_exit %q{
|
522
|
+
# prc = Proc.new {|a: []|}
|
523
|
+
# GC.stress = true
|
524
|
+
# tap { prc.call }
|
525
|
+
# GC.start
|
526
|
+
# tap { prc.call }
|
527
|
+
# }, bug8964
|
528
|
+
# end
|
529
|
+
#
|
530
|
+
# def test_dynamic_symbol_keyword
|
531
|
+
# bug10266 = '[ruby-dev:48564] [Bug #10266]'
|
532
|
+
# assert_separately(['-', bug10266], <<-'end;') # do
|
533
|
+
# bug = ARGV.shift
|
534
|
+
# "hoge".to_sym
|
535
|
+
# assert_nothing_raised(bug) {eval("def a(hoge:); end")}
|
536
|
+
# end;
|
537
|
+
# end
|
538
|
+
#
|
539
|
+
# def test_unknown_keyword_with_block
|
540
|
+
# bug10413 = '[ruby-core:65837] [Bug #10413]'
|
541
|
+
# class << (o = Object.new)
|
542
|
+
# def bar(k2: 'v2')
|
543
|
+
# end
|
544
|
+
#
|
545
|
+
# def foo
|
546
|
+
# bar(k1: 1)
|
547
|
+
# end
|
548
|
+
# end
|
549
|
+
# assert_raise_with_message(ArgumentError, /unknown keyword: k1/, bug10413) {
|
550
|
+
# o.foo {raise "unreachable"}
|
551
|
+
# }
|
552
|
+
# end
|
553
|
+
#
|
554
|
+
# def test_super_with_anon_restkeywords
|
555
|
+
# bug10659 = '[ruby-core:67157] [Bug #10659]'
|
556
|
+
#
|
557
|
+
# foo = Class.new do
|
558
|
+
# def foo(**h)
|
559
|
+
# h
|
560
|
+
# end
|
561
|
+
# end
|
562
|
+
#
|
563
|
+
# class << (obj = foo.new)
|
564
|
+
# def foo(bar: "bar", **)
|
565
|
+
# super
|
566
|
+
# end
|
567
|
+
# end
|
568
|
+
#
|
569
|
+
# assert_nothing_raised(TypeError, bug10659) {
|
570
|
+
# assert_equal({:bar => "bar"}, obj.foo, bug10659)
|
571
|
+
# }
|
572
|
+
# end
|
573
|
+
#
|
574
|
+
# def m(a) yield a end
|
575
|
+
#
|
576
|
+
# def test_nonsymbol_key
|
577
|
+
# result = m(["a" => 10]) { |a = nil, **b| [a, b] }
|
578
|
+
# assert_equal([{"a" => 10}, {}], result)
|
579
|
+
# end
|
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
|
+
end
|