opal 1.0.3 → 1.1.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +13 -12
- data/.gitattributes +1 -1
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/build.yml +90 -0
- data/.jshintrc +1 -1
- data/.overcommit.yml +35 -0
- data/.rubocop.yml +44 -7
- data/{.rubocop_todo.yml → .rubocop/todo.yml} +4 -5
- data/CHANGELOG.md +152 -1
- data/Gemfile +2 -3
- data/HACKING.md +2 -9
- data/LICENSE +1 -1
- data/README.md +21 -18
- data/UNRELEASED.md +4 -2
- data/benchmark-ips/bm_array_pop_1.rb +8 -0
- data/benchmark-ips/bm_array_shift.rb +7 -0
- data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
- data/benchmark-ips/class_shovel_vs_singleton_class.rb +16 -0
- data/bin/build-browser-source-map-support +4 -0
- data/bin/format-filters +54 -0
- data/bin/git-submodule-fast-install +49 -0
- data/bin/remove-filters +39 -0
- data/bin/setup +4 -0
- data/bin/yarn +11 -0
- data/docs/releasing.md +18 -0
- data/docs/roda-sprockets.md +86 -0
- data/docs/sinatra.md +5 -12
- data/examples/rack/Gemfile +1 -0
- data/examples/rack/app/application.rb +3 -0
- data/examples/rack/config.ru +5 -4
- data/exe/opal-repl +2 -83
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +2 -10
- data/lib/opal/builder_processors.rb +1 -1
- data/lib/opal/cli.rb +4 -1
- data/lib/opal/cli_options.rb +11 -3
- data/lib/opal/cli_runners.rb +27 -37
- data/lib/opal/cli_runners/applescript.rb +5 -44
- data/lib/opal/cli_runners/chrome.js +7 -35
- data/lib/opal/cli_runners/chrome.rb +75 -17
- data/lib/opal/cli_runners/compiler.rb +17 -0
- data/lib/opal/cli_runners/nashorn.rb +9 -43
- data/lib/opal/cli_runners/nodejs.rb +18 -47
- data/lib/opal/cli_runners/server.rb +18 -6
- data/lib/opal/cli_runners/source-map-support-browser.js +6449 -0
- data/lib/opal/cli_runners/source-map-support-node.js +3704 -0
- data/lib/opal/cli_runners/source-map-support.js +639 -0
- data/lib/opal/cli_runners/system_runner.rb +45 -0
- data/lib/opal/compiler.rb +57 -29
- data/lib/opal/config.rb +0 -5
- data/lib/opal/erb.rb +1 -1
- data/lib/opal/magic_comments.rb +34 -0
- data/lib/opal/nodes/args/arity_check.rb +2 -1
- data/lib/opal/nodes/base.rb +1 -1
- data/lib/opal/nodes/call.rb +1 -4
- data/lib/opal/nodes/def.rb +2 -0
- data/lib/opal/nodes/iter.rb +1 -1
- data/lib/opal/nodes/literal.rb +19 -14
- data/lib/opal/nodes/logic.rb +5 -80
- data/lib/opal/nodes/masgn.rb +2 -0
- data/lib/opal/nodes/rescue.rb +1 -1
- data/lib/opal/nodes/super.rb +24 -10
- data/lib/opal/nodes/top.rb +5 -4
- data/lib/opal/parser/with_c_lexer.rb +2 -1
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/path_reader.rb +2 -2
- data/lib/opal/paths.rb +8 -5
- data/lib/opal/repl.rb +103 -0
- data/lib/opal/rewriter.rb +4 -0
- data/lib/opal/rewriters/for_rewriter.rb +1 -1
- data/lib/opal/rewriters/js_reserved_words.rb +7 -7
- data/lib/opal/rewriters/numblocks.rb +31 -0
- data/lib/opal/rewriters/returnable_logic.rb +33 -0
- data/lib/opal/util.rb +11 -48
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +26 -26
- data/opal/corelib/array.rb +160 -118
- data/opal/corelib/array/pack.rb +5 -3
- data/opal/corelib/basic_object.rb +4 -4
- data/opal/corelib/class.rb +2 -1
- data/opal/corelib/comparable.rb +49 -31
- data/opal/corelib/constants.rb +5 -5
- data/opal/corelib/enumerable.rb +108 -46
- data/opal/corelib/enumerator.rb +27 -12
- data/opal/corelib/file.rb +3 -1
- data/opal/corelib/hash.rb +6 -1
- data/opal/corelib/helpers.rb +8 -28
- data/opal/corelib/io.rb +12 -7
- data/opal/corelib/kernel.rb +45 -14
- data/opal/corelib/kernel/format.rb +3 -1
- data/opal/corelib/math.rb +8 -6
- data/opal/corelib/method.rb +8 -0
- data/opal/corelib/module.rb +17 -2
- data/opal/corelib/number.rb +3 -12
- data/opal/corelib/proc.rb +16 -0
- data/opal/corelib/random/mersenne_twister.rb +147 -0
- data/opal/corelib/range.rb +3 -13
- data/opal/corelib/regexp.rb +10 -6
- data/opal/corelib/runtime.js +208 -81
- data/opal/corelib/string.rb +55 -49
- data/opal/corelib/string/encoding.rb +109 -32
- data/opal/corelib/string/unpack.rb +2 -17
- data/opal/corelib/struct.rb +14 -1
- data/opal/corelib/time.rb +4 -0
- data/opal/opal.rb +1 -1
- data/opal/opal/mini.rb +1 -1
- data/package.json +16 -0
- data/spec/README.md +10 -0
- data/spec/filters/bugs/array.rb +76 -0
- data/spec/filters/bugs/base64.rb +10 -0
- data/spec/filters/bugs/basicobject.rb +12 -0
- data/spec/filters/bugs/bigdecimal.rb +248 -0
- data/spec/filters/bugs/class.rb +12 -0
- data/spec/filters/bugs/complex.rb +7 -0
- data/spec/filters/bugs/date.rb +104 -0
- data/spec/filters/bugs/encoding.rb +259 -0
- data/spec/filters/bugs/enumerable.rb +26 -0
- data/spec/filters/bugs/enumerator.rb +48 -0
- data/spec/filters/bugs/exception.rb +120 -0
- data/spec/filters/bugs/file.rb +48 -0
- data/spec/filters/bugs/float.rb +74 -0
- data/spec/filters/bugs/hash.rb +60 -0
- data/spec/filters/bugs/integer.rb +78 -0
- data/spec/filters/bugs/io.rb +9 -0
- data/spec/filters/bugs/kernel.rb +401 -0
- data/spec/filters/bugs/language.rb +451 -0
- data/spec/filters/bugs/marshal.rb +50 -0
- data/spec/filters/bugs/math.rb +4 -0
- data/spec/filters/bugs/method.rb +79 -0
- data/spec/filters/bugs/module.rb +281 -0
- data/spec/filters/bugs/nilclass.rb +4 -0
- data/spec/filters/bugs/numeric.rb +27 -0
- data/spec/filters/bugs/openstruct.rb +8 -0
- data/spec/filters/bugs/pack_unpack.rb +138 -0
- data/spec/filters/bugs/pathname.rb +9 -0
- data/spec/filters/bugs/proc.rb +80 -0
- data/spec/filters/bugs/random.rb +20 -0
- data/spec/filters/bugs/range.rb +139 -0
- data/spec/filters/bugs/rational.rb +12 -0
- data/spec/filters/bugs/regexp.rb +91 -0
- data/spec/filters/bugs/set.rb +51 -0
- data/spec/filters/bugs/singleton.rb +7 -0
- data/spec/filters/bugs/string.rb +341 -0
- data/spec/filters/bugs/stringscanner.rb +78 -0
- data/spec/filters/bugs/struct.rb +26 -0
- data/spec/filters/bugs/symbol.rb +7 -0
- data/spec/filters/bugs/time.rb +109 -0
- data/spec/filters/bugs/unboundmethod.rb +33 -0
- data/spec/filters/bugs/warnings.rb +30 -0
- data/spec/filters/unsupported/array.rb +168 -0
- data/spec/filters/unsupported/basicobject.rb +15 -0
- data/spec/filters/unsupported/bignum.rb +55 -0
- data/spec/filters/unsupported/class.rb +5 -0
- data/spec/filters/unsupported/delegator.rb +6 -0
- data/spec/filters/unsupported/enumerable.rb +12 -0
- data/spec/filters/unsupported/enumerator.rb +14 -0
- data/spec/filters/unsupported/file.rb +4 -0
- data/spec/filters/unsupported/fixnum.rb +15 -0
- data/spec/filters/unsupported/float.rb +47 -0
- data/spec/filters/unsupported/freeze.rb +259 -0
- data/spec/filters/unsupported/hash.rb +44 -0
- data/spec/filters/unsupported/integer.rb +101 -0
- data/spec/filters/unsupported/kernel.rb +35 -0
- data/spec/filters/unsupported/language.rb +25 -0
- data/spec/filters/unsupported/marshal.rb +44 -0
- data/spec/filters/unsupported/matchdata.rb +63 -0
- data/spec/filters/unsupported/math.rb +4 -0
- data/spec/filters/unsupported/pathname.rb +4 -0
- data/spec/filters/unsupported/privacy.rb +287 -0
- data/spec/filters/unsupported/proc.rb +4 -0
- data/spec/filters/unsupported/random.rb +5 -0
- data/spec/filters/unsupported/range.rb +8 -0
- data/spec/filters/unsupported/regexp.rb +70 -0
- data/spec/filters/unsupported/set.rb +5 -0
- data/spec/filters/unsupported/singleton.rb +7 -0
- data/spec/filters/unsupported/string.rb +687 -0
- data/spec/filters/unsupported/struct.rb +7 -0
- data/spec/filters/unsupported/symbol.rb +21 -0
- data/spec/filters/unsupported/taint.rb +162 -0
- data/spec/filters/unsupported/thread.rb +10 -0
- data/spec/filters/unsupported/time.rb +204 -0
- data/spec/filters/unsupported/usage_of_files.rb +262 -0
- data/spec/lib/builder_processors_spec.rb +44 -0
- data/spec/lib/builder_spec.rb +133 -0
- data/spec/lib/cli_runners/server_spec.rb +25 -0
- data/spec/lib/cli_runners_spec.rb +16 -0
- data/spec/lib/cli_spec.rb +256 -0
- data/spec/lib/compiler_spec.rb +693 -0
- data/spec/lib/config_spec.rb +112 -0
- data/spec/lib/dependency_resolver_spec.rb +43 -0
- data/spec/lib/deprecations_spec.rb +17 -0
- data/spec/lib/fixtures/complex_sprockets.js.rb.erb +4 -0
- data/spec/lib/fixtures/file_with_directives.js +2 -0
- data/spec/lib/fixtures/jst_file.js.jst +1 -0
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/lib/fixtures/opal_file.rb +2 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_file.js +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/lib/fixtures/source_location_test.rb +7 -0
- data/spec/lib/fixtures/source_map.rb +1 -0
- data/spec/lib/fixtures/source_map/subfolder/other_file.rb +1 -0
- data/spec/lib/fixtures/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/path_reader_spec.rb +47 -0
- data/spec/lib/paths_spec.rb +18 -0
- data/spec/lib/repl_spec.rb +28 -0
- data/spec/lib/rewriters/base_spec.rb +68 -0
- data/spec/lib/rewriters/binary_operator_assignment_spec.rb +153 -0
- data/spec/lib/rewriters/block_to_iter_spec.rb +28 -0
- data/spec/lib/rewriters/dot_js_syntax_spec.rb +108 -0
- data/spec/lib/rewriters/explicit_writer_return_spec.rb +186 -0
- data/spec/lib/rewriters/for_rewriter_spec.rb +92 -0
- data/spec/lib/rewriters/hashes/key_duplicates_rewriter_spec.rb +47 -0
- data/spec/lib/rewriters/js_reserved_words_spec.rb +119 -0
- data/spec/lib/rewriters/logical_operator_assignment_spec.rb +202 -0
- data/spec/lib/rewriters/opal_engine_check_spec.rb +84 -0
- data/spec/lib/rewriters/returnable_logic_spec.rb +52 -0
- data/spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb +59 -0
- data/spec/lib/simple_server_spec.rb +56 -0
- data/spec/lib/source_map/file_spec.rb +67 -0
- data/spec/lib/source_map/index_spec.rb +80 -0
- data/spec/lib/spec_helper.rb +105 -0
- data/spec/mspec-opal/formatters.rb +197 -0
- data/spec/mspec-opal/runner.rb +172 -0
- data/spec/opal/compiler/irb_spec.rb +44 -0
- data/spec/opal/compiler/unicode_spec.rb +10 -0
- data/spec/opal/core/array/dup_spec.rb +23 -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/class/inherited_spec.rb +18 -0
- data/spec/opal/core/enumerable/all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/any_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/collect_break_spec.rb +13 -0
- data/spec/opal/core/enumerable/count_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/detect_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/drop_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_slice_break_spec.rb +6 -0
- data/spec/opal/core/enumerable/each_with_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_with_object_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/grep_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/none_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/one_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/reduce_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/take_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
- data/spec/opal/core/exception_spec.rb +8 -0
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -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 +339 -0
- data/spec/opal/core/helpers_spec.rb +14 -0
- data/spec/opal/core/iterable_props_spec.rb +53 -0
- data/spec/opal/core/kernel/at_exit_spec.rb +70 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variables_spec.rb +110 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/public_methods_spec.rb +25 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +18 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +15 -0
- data/spec/opal/core/language/DATA/characters_support_spec.rb +9 -0
- data/spec/opal/core/language/DATA/empty___END___spec.rb +7 -0
- data/spec/opal/core/language/DATA/multiple___END___spec.rb +10 -0
- data/spec/opal/core/language/arguments/mlhs_arg_spec.rb +18 -0
- data/spec/opal/core/language/keyword_arguments_spec.rb +9 -0
- data/spec/opal/core/language/numblocks_spec.rb +16 -0
- data/spec/opal/core/language/safe_navigator_spec.rb +7 -0
- data/spec/opal/core/language/while_spec.rb +31 -0
- data/spec/opal/core/language_spec.rb +29 -0
- data/spec/opal/core/marshal/dump_spec.rb +81 -0
- data/spec/opal/core/marshal/load_spec.rb +13 -0
- data/spec/opal/core/module_spec.rb +27 -0
- data/spec/opal/core/object_id_spec.rb +56 -0
- data/spec/opal/core/regexp/interpolation_spec.rb +40 -0
- data/spec/opal/core/regexp/match_spec.rb +78 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +123 -0
- data/spec/opal/core/runtime/constants_spec.rb +16 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/exit_spec.rb +29 -0
- data/spec/opal/core/runtime/is_a_spec.rb +48 -0
- data/spec/opal/core/runtime/loaded_spec.rb +20 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +39 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +68 -0
- data/spec/opal/core/runtime/rescue_spec.rb +37 -0
- data/spec/opal/core/runtime/string_spec.rb +25 -0
- data/spec/opal/core/runtime/truthy_spec.rb +61 -0
- data/spec/opal/core/runtime_spec.rb +58 -0
- data/spec/opal/core/string/each_byte_spec.rb +19 -0
- data/spec/opal/core/string/gsub_spec.rb +35 -0
- data/spec/opal/core/string/to_sym_spec.rb +9 -0
- data/spec/opal/core/string_spec.rb +28 -0
- data/spec/opal/core/struct/dup_spec.rb +11 -0
- data/spec/opal/core/time_spec.rb +68 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +30 -0
- data/spec/opal/stdlib/erb/inline_block.opalerb +3 -0
- data/spec/opal/stdlib/erb/quoted.opalerb +1 -0
- data/spec/opal/stdlib/erb/simple.opalerb +1 -0
- data/spec/opal/stdlib/js_spec.rb +72 -0
- data/spec/opal/stdlib/json/ext_spec.rb +55 -0
- data/spec/opal/stdlib/json/parse_spec.rb +37 -0
- data/spec/opal/stdlib/logger/logger_spec.rb +308 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -0
- data/spec/opal/stdlib/native/array_spec.rb +11 -0
- data/spec/opal/stdlib/native/date_spec.rb +12 -0
- data/spec/opal/stdlib/native/deprecated_include_spec.rb +8 -0
- data/spec/opal/stdlib/native/each_spec.rb +13 -0
- data/spec/opal/stdlib/native/element_reference_spec.rb +16 -0
- data/spec/opal/stdlib/native/exposure_spec.rb +33 -0
- data/spec/opal/stdlib/native/ext_spec.rb +19 -0
- data/spec/opal/stdlib/native/hash_spec.rb +67 -0
- data/spec/opal/stdlib/native/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -0
- data/spec/opal/stdlib/native/native_alias_spec.rb +26 -0
- data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
- data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
- data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
- data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
- data/spec/opal/stdlib/native/new_spec.rb +92 -0
- data/spec/opal/stdlib/native/struct_spec.rb +12 -0
- data/spec/opal/stdlib/pp_spec.rb +5 -0
- data/spec/opal/stdlib/promise/always_spec.rb +49 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +53 -0
- data/spec/opal/stdlib/promise/then_spec.rb +79 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +51 -0
- data/spec/opal/stdlib/promise/value_spec.rb +15 -0
- data/spec/opal/stdlib/promise/when_spec.rb +34 -0
- data/spec/opal/stdlib/source_map_spec.rb +8 -0
- data/spec/opal/stdlib/strscan/scan_spec.rb +11 -0
- data/spec/opal/stdlib/template/paths_spec.rb +10 -0
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/ruby_specs +183 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/guard_platform.rb +4 -0
- data/spec/support/match_helpers.rb +57 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/rewriters_helper.rb +54 -0
- data/spec/support/source_map_helper.rb +190 -0
- data/stdlib/base64.rb +2 -2
- data/stdlib/bigdecimal.rb +15 -3
- data/stdlib/bigdecimal/bignumber.js.rb +1 -1
- data/stdlib/bigdecimal/util.rb +148 -0
- data/stdlib/delegate.rb +8 -0
- data/stdlib/nodejs/fileutils.rb +1 -1
- data/stdlib/nodejs/kernel.rb +0 -13
- data/stdlib/nodejs/stacktrace.rb +4 -179
- data/stdlib/ostruct.rb +5 -0
- data/stdlib/pp.rb +586 -19
- data/stdlib/prettyprint.rb +556 -0
- data/stdlib/rbconfig/sizeof.rb +2 -0
- data/stdlib/securerandom.rb +32 -0
- data/stdlib/set.rb +36 -0
- data/stdlib/strscan.rb +15 -0
- data/tasks/benchmarking.rake +1 -1
- data/tasks/linting.rake +3 -5
- data/tasks/releasing.rake +2 -5
- data/tasks/testing.rake +16 -11
- data/tasks/testing/mspec_special_calls.rb +1 -19
- data/test/nodejs/fixtures/cat.png +0 -0
- data/test/nodejs/fixtures/hello.rb +1 -0
- data/test/nodejs/fixtures/iso88591.txt +1 -0
- data/test/nodejs/fixtures/utf8.txt +1 -0
- data/test/nodejs/fixtures/win1258.txt +1 -0
- data/test/nodejs/test_dir.rb +39 -0
- data/test/nodejs/test_env.rb +62 -0
- data/test/nodejs/test_error.rb +29 -0
- data/test/nodejs/test_file.rb +206 -0
- data/test/nodejs/test_file_encoding.rb +20 -0
- data/test/nodejs/test_io.rb +18 -0
- data/test/nodejs/test_opal_builder.rb +12 -0
- data/test/nodejs/test_pathname.rb +16 -0
- data/test/opal/cat.png +0 -0
- data/test/opal/http_server.rb +52 -0
- data/test/opal/test_base64.rb +115 -0
- data/test/opal/test_keyword.rb +590 -0
- data/test/opal/test_matrix.rb +661 -0
- data/test/opal/test_openuri.rb +53 -0
- data/test/opal/unsupported_and_bugs.rb +39 -0
- data/yarn.lock +1355 -0
- metadata +905 -40
- data/.travis.yml +0 -109
- data/appveyor.yml +0 -35
- data/lib/opal/nodes/runtime_helpers.rb +0 -51
- data/opal/corelib/random/MersenneTwister.js +0 -137
- data/opal/corelib/random/mersenne_twister.js.rb +0 -13
- data/stdlib/bigdecimal/kernel.rb +0 -5
@@ -0,0 +1,206 @@
|
|
1
|
+
# Copied from cruby and modified to skip unsupported syntaxes
|
2
|
+
require 'test/unit'
|
3
|
+
require 'nodejs'
|
4
|
+
require 'nodejs/file'
|
5
|
+
|
6
|
+
class TestNodejsFile < Test::Unit::TestCase
|
7
|
+
def tmpdir
|
8
|
+
`require('os').tmpdir()`
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.windows_platform?
|
12
|
+
`process.platform`.start_with?('win')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_instantiate_without_open_mode
|
16
|
+
# By default the open mode is 'r' (read only)
|
17
|
+
File.write('tmp/quz', "world")
|
18
|
+
file = File.new('tmp/quz')
|
19
|
+
assert_equal('tmp/quz', file.path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_mtime
|
23
|
+
File.write('tmp/qix', "hello")
|
24
|
+
file = 'tmp/qix'
|
25
|
+
File.new(file, 'r')
|
26
|
+
|
27
|
+
t1 = File.mtime(file)
|
28
|
+
t2 = File.open(file) {|f| f.mtime}
|
29
|
+
assert_kind_of(Time, t1)
|
30
|
+
assert_kind_of(Time, t2)
|
31
|
+
assert_equal(t1, t2)
|
32
|
+
assert_raise(Errno::ENOENT) { File.mtime('nofile') }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_write_read
|
36
|
+
path = tmpdir + "/testing_nodejs_file_implementation_#{Time.now.to_i}"
|
37
|
+
contents = 'foobar'
|
38
|
+
assert !File.exist?(path)
|
39
|
+
File.write path, contents
|
40
|
+
|
41
|
+
assert_equal(contents, File.read(path))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_read_file
|
45
|
+
File.write('tmp/foo', 'bar')
|
46
|
+
assert_equal('bar', File.read('tmp/foo'))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_read_binary_image
|
50
|
+
assert_match(/^\u0089PNG\r\n\u001A\n\u0000\u0000\u0000\rIHDR.*/, File.open('./test/nodejs/fixtures/cat.png', 'rb') {|f| f.read })
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_read_binary_utf8_file
|
54
|
+
binary_text = ::File.open('./test/nodejs/fixtures/utf8.txt', 'rb') {|f| f.read}
|
55
|
+
assert_equal(binary_text.encoding, Encoding::UTF_8)
|
56
|
+
assert_match(/^\u00E7\u00E9\u00E0/, binary_text)
|
57
|
+
utf8_text = binary_text.force_encoding('utf-8')
|
58
|
+
assert_equal("çéà", utf8_text)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_read_binary_iso88591_file
|
62
|
+
binary_text = ::File.open('./test/nodejs/fixtures/iso88591.txt', 'rb') {|f| f.read}
|
63
|
+
assert_equal(binary_text.encoding, Encoding::UTF_8)
|
64
|
+
assert_match(/^\u00E7\u00E9\u00E0/, binary_text)
|
65
|
+
utf8_text = binary_text.force_encoding('utf-8')
|
66
|
+
assert_equal("çéà", utf8_text)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_read_binary_win1258_file
|
70
|
+
binary_text = ::File.open('./test/nodejs/fixtures/win1258.txt', 'rb') {|f| f.read}
|
71
|
+
assert_equal(binary_text.encoding, Encoding::UTF_8)
|
72
|
+
assert_match(/^\u00E7\u00E9\u00E0/, binary_text)
|
73
|
+
utf8_text = binary_text.force_encoding('utf-8')
|
74
|
+
assert_equal("çéà", utf8_text)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_read_each_line
|
78
|
+
File.write('tmp/bar', "one\ntwo")
|
79
|
+
file = File.new('tmp/bar', 'r')
|
80
|
+
lines = []
|
81
|
+
file.each_line do |line|
|
82
|
+
lines << line
|
83
|
+
end
|
84
|
+
assert_equal(2, lines.length)
|
85
|
+
assert_equal("one\n", lines[0])
|
86
|
+
assert_equal('two', lines[1])
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_readlines
|
90
|
+
File.write('tmp/quz', "one\ntwo")
|
91
|
+
file = File.new('tmp/quz', 'r')
|
92
|
+
lines = file.readlines
|
93
|
+
assert_equal(2, lines.length)
|
94
|
+
assert_equal("one\n", lines[0])
|
95
|
+
assert_equal('two', lines[1])
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_readlines_separator
|
99
|
+
File.write('tmp/qux', "one-two")
|
100
|
+
file = File.new('tmp/qux', 'r')
|
101
|
+
lines = file.readlines '-'
|
102
|
+
assert_equal(2, lines.length)
|
103
|
+
assert_equal('one-', lines[0])
|
104
|
+
assert_equal('two', lines[1])
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_read_noexistent_should_raise_io_error
|
108
|
+
assert_raise Errno::ENOENT do
|
109
|
+
File.read('tmp/nonexistent')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_mtime_noexistent_should_raise_io_error
|
114
|
+
assert_raise(Errno::ENOENT) { File.mtime('tmp/nonexistent') }
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_current_directory_should_be_a_directory
|
118
|
+
assert(File.directory?('.'))
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_current_directory_should_be_a_directory_using_pathname
|
122
|
+
current_dir = Pathname.new('.')
|
123
|
+
assert(current_dir.directory?)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_directory_check
|
127
|
+
refute(File.directory?('test/nodejs/fixtures/non-existent'), 'test/nodejs/fixtures/non-existent should not be a directory')
|
128
|
+
assert(File.directory?('test/nodejs/fixtures/'), 'test/nodejs/fixtures/ should be a directory')
|
129
|
+
assert(File.directory?('test/nodejs/fixtures'), 'test/nodejs/fixtures should be a directory')
|
130
|
+
refute(File.directory?('test/nodejs/fixtures/hello.rb'), 'test/nodejs/fixtures/hello.rb should not be a directory')
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_directory_check_with_symlinks
|
134
|
+
assert(File.directory?('test/nodejs/fixtures/symlink-to-directory'), 'test/nodejs/fixtures/symlink-to-directory should be a directory')
|
135
|
+
assert(File.directory?('test/nodejs/fixtures/symlink-to-directory/'), 'test/nodejs/fixtures/symlink-to-directory/ should be a directory')
|
136
|
+
refute(File.directory?('test/nodejs/fixtures/symlink-to-file'), 'test/nodejs/fixtures/symlink-to-file should not be a directory')
|
137
|
+
end unless windows_platform?
|
138
|
+
|
139
|
+
def test_file_check
|
140
|
+
refute(File.file?('test/nodejs/fixtures/non-existent'), 'test/nodejs/fixtures/non-existent should not be a file')
|
141
|
+
refute(File.file?('test/nodejs/fixtures/'), 'test/nodejs/fixtures/ should not be a file')
|
142
|
+
refute(File.file?('test/nodejs/fixtures'), 'test/nodejs/fixtures should not be a file')
|
143
|
+
assert(File.file?('test/nodejs/fixtures/hello.rb'), 'test/nodejs/fixtures/hello.rb should be a file')
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_file_check_with_symlinks
|
147
|
+
refute(File.file?('test/nodejs/fixtures/symlink-to-directory'), 'test/nodejs/fixtures/symlink-to-directory should not be a file')
|
148
|
+
refute(File.file?('test/nodejs/fixtures/symlink-to-directory/'), 'test/nodejs/fixtures/symlink-to-directory/ should not be a file')
|
149
|
+
assert(File.file?('test/nodejs/fixtures/symlink-to-file'), 'test/nodejs/fixtures/symlink-to-file should be a file')
|
150
|
+
end unless windows_platform?
|
151
|
+
|
152
|
+
def test_file_symlink?
|
153
|
+
assert(File.symlink?('test/nodejs/fixtures/symlink-to-file'))
|
154
|
+
assert(File.symlink?('test/nodejs/fixtures/symlink-to-directory'))
|
155
|
+
refute(File.symlink?('test/nodejs/fixtures'))
|
156
|
+
refute(File.symlink?('test/nodejs/fixtures/hello.rb'))
|
157
|
+
end unless windows_platform?
|
158
|
+
|
159
|
+
def test_file_readable
|
160
|
+
assert !File.readable?('tmp/nonexistent')
|
161
|
+
File.write('tmp/fuz', "hello")
|
162
|
+
assert File.readable?('tmp/fuz')
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_linux_separators
|
166
|
+
assert_equal('/', File::SEPARATOR)
|
167
|
+
assert_equal('/', File::Separator)
|
168
|
+
assert_equal(nil, File::ALT_SEPARATOR)
|
169
|
+
end unless windows_platform?
|
170
|
+
|
171
|
+
def test_windows_separators
|
172
|
+
assert_equal('/', File::SEPARATOR)
|
173
|
+
assert_equal('/', File::Separator)
|
174
|
+
assert_equal('\\', File::ALT_SEPARATOR)
|
175
|
+
end if windows_platform?
|
176
|
+
|
177
|
+
def test_windows_file_expand_path
|
178
|
+
drive_letter = Dir.pwd.slice(0, 2)
|
179
|
+
assert_equal(Dir.pwd + '/foo/bar.js', File.expand_path('./foo/bar.js'))
|
180
|
+
assert_equal(drive_letter + '/foo/bar.js', File.expand_path('/foo/bar.js'))
|
181
|
+
assert_equal('c:/foo/bar.js', File.expand_path('c:/foo/bar.js'))
|
182
|
+
assert_equal('c:/foo/bar.js', File.expand_path('c:\\foo\\bar.js'))
|
183
|
+
assert_equal('c:/foo/bar.js', File.expand_path('bar.js', 'c:\\foo'))
|
184
|
+
assert_equal('c:/baz/bar.js', File.expand_path('\\baz\\bar.js', 'c:\\foo'))
|
185
|
+
assert_equal('c:/bar.js', File.expand_path('\\..\\bar.js', 'c:\\foo\\baz'))
|
186
|
+
assert_equal('c:/bar.js', File.expand_path('\\..\\bar.js', 'c:\\foo\\baz\\'))
|
187
|
+
assert_equal('c:/foo/baz/bar.js', File.expand_path('baz\\bar.js', 'c:\\foo'))
|
188
|
+
assert_equal('c:/baz/bar.js', File.expand_path('baz\\bar.js', 'c:\\foo\\..'))
|
189
|
+
assert_equal('d:/', File.expand_path('d:'), 'should add a trailing slash when the path is d:')
|
190
|
+
assert_equal('d:/', File.expand_path('d:/'), 'should preserve the trailing slash when the path d:/')
|
191
|
+
assert_equal(Dir.pwd, File.expand_path(drive_letter), 'should expand to the current directory when the path is c: (and the current directory is located in the c drive)')
|
192
|
+
assert_equal(drive_letter + '/', drive_letter + '/', 'should return c:/ when the path is c:/ because the path is absolute')
|
193
|
+
end if windows_platform?
|
194
|
+
|
195
|
+
def test_linux_file_expand_path
|
196
|
+
assert_equal(Dir.pwd + '/foo/bar.js', File.expand_path('./foo/bar.js'))
|
197
|
+
assert_equal(Dir.home + '/foo/bar.js', File.expand_path('~/foo/bar.js'))
|
198
|
+
assert_equal(Dir.home + '/foo/bar.js', File.expand_path('~/foo/bar.js', '/base/dir'))
|
199
|
+
assert_equal('/base/dir/foo/bar.js', File.expand_path('./foo/bar.js', '/base/dir'))
|
200
|
+
assert_equal(Dir.home + '/workspace/foo/bar.js', File.expand_path('./foo/bar.js', '~/workspace'))
|
201
|
+
end unless windows_platform?
|
202
|
+
|
203
|
+
def test_join
|
204
|
+
assert_equal('usr/bin', File.join('usr', 'bin'))
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'nodejs'
|
3
|
+
require 'nodejs/file'
|
4
|
+
|
5
|
+
class TestNodejsFileEncoding < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_force_encoding_raw_text_to_utf8
|
8
|
+
raw_text = 'çéà'
|
9
|
+
assert_equal(raw_text.encoding, Encoding::UTF_8)
|
10
|
+
utf8_text = raw_text.force_encoding('utf-8')
|
11
|
+
assert_equal("çéà", utf8_text)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_force_encoding_from_binary_to_utf8
|
15
|
+
raw_text = "\xC3\xA7\xC3\xA9\xC3\xA0"
|
16
|
+
assert_equal(raw_text.encoding, Encoding::UTF_8)
|
17
|
+
utf8_text = raw_text.force_encoding('utf-8')
|
18
|
+
assert_equal("çéà", utf8_text)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copied from cruby and modified to skip unsupported syntaxes
|
2
|
+
require 'test/unit'
|
3
|
+
require 'nodejs'
|
4
|
+
require 'nodejs/io'
|
5
|
+
|
6
|
+
class TestNodejsIO < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_binread
|
9
|
+
File.write('tmp/foo', 'bar')
|
10
|
+
assert_equal("bar", IO.binread('tmp/foo'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_binread_noexistent_should_raise_io_error
|
14
|
+
assert_raise IOError do
|
15
|
+
IO.binread('tmp/nonexistent')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'nodejs'
|
3
|
+
require 'opal-builder'
|
4
|
+
|
5
|
+
class TestNodejsOpalBuilder < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_should_build_simple_ruby_file
|
8
|
+
builder = Opal::Builder.new
|
9
|
+
result = builder.build('test/nodejs/fixtures/hello.rb')
|
10
|
+
assert(/self\.\$puts\("Hello world"\)/.match(result.to_s))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'nodejs'
|
3
|
+
|
4
|
+
class TestNodejsPathname < Test::Unit::TestCase
|
5
|
+
def self.windows_platform?
|
6
|
+
`process.platform`.start_with?('win')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_windows_pathname_absolute
|
10
|
+
assert_equal(true, Pathname.new('c:/foo').absolute?)
|
11
|
+
assert_equal(true, Pathname.new('/foo').absolute?)
|
12
|
+
assert_equal(true, Pathname.new('\\foo').absolute?)
|
13
|
+
assert_equal(false, Pathname.new('.').absolute?)
|
14
|
+
assert_equal(false, Pathname.new('foo').absolute?)
|
15
|
+
end if windows_platform?
|
16
|
+
end
|
data/test/opal/cat.png
ADDED
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
|
3
|
+
cat_image = File.open(File.join(File.dirname(__FILE__), 'cat.png'), 'rb').read
|
4
|
+
|
5
|
+
get '/' do
|
6
|
+
'Ready!'
|
7
|
+
end
|
8
|
+
|
9
|
+
get '/plain_text' do
|
10
|
+
status 200
|
11
|
+
headers \
|
12
|
+
'Content-Type' => 'text/plain'
|
13
|
+
body 'plain text'
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
get '/no_header' do
|
18
|
+
status 200
|
19
|
+
headers \
|
20
|
+
'Content-Type' => ''
|
21
|
+
body 'no header'
|
22
|
+
end
|
23
|
+
|
24
|
+
get '/html' do
|
25
|
+
status 200
|
26
|
+
headers \
|
27
|
+
'Content-Type' => 'text/html; charset=utf-8'
|
28
|
+
body '<body>'
|
29
|
+
end
|
30
|
+
|
31
|
+
get '/png' do
|
32
|
+
status 200
|
33
|
+
headers \
|
34
|
+
'Content-Type' => 'image/png'
|
35
|
+
body cat_image
|
36
|
+
end
|
37
|
+
|
38
|
+
get '/404' do
|
39
|
+
status 404
|
40
|
+
end
|
41
|
+
|
42
|
+
get '/500' do
|
43
|
+
status 500
|
44
|
+
end
|
45
|
+
|
46
|
+
get '/last_modified' do
|
47
|
+
status 200
|
48
|
+
headers \
|
49
|
+
'Content-Type' => 'text/plain',
|
50
|
+
'Last-Modified' => 'Wed, 21 Oct 2015 07:28:00 GMT'
|
51
|
+
body 'Look Ma, I have a Last-Modified header'
|
52
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# coding: ascii-8bit
|
2
|
+
# frozen_string_literal: false
|
3
|
+
require "test/unit"
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
class TestBase64 < Test::Unit::TestCase
|
7
|
+
def test_sample
|
8
|
+
assert_equal("U2VuZCByZWluZm9yY2VtZW50cw==\n", Base64.encode64('Send reinforcements'))
|
9
|
+
assert_equal('Send reinforcements', Base64.decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n"))
|
10
|
+
assert_equal(
|
11
|
+
"Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n",
|
12
|
+
Base64.encode64("Now is the time for all good coders\nto learn Ruby"))
|
13
|
+
assert_equal(
|
14
|
+
"Now is the time for all good coders\nto learn Ruby",
|
15
|
+
Base64.decode64("Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n"))
|
16
|
+
assert_equal(
|
17
|
+
"VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGlu\nZSB0aHJlZQpBbmQgc28gb24uLi4K\n",
|
18
|
+
Base64.encode64("This is line one\nThis is line two\nThis is line three\nAnd so on...\n"))
|
19
|
+
assert_equal(
|
20
|
+
"This is line one\nThis is line two\nThis is line three\nAnd so on...\n",
|
21
|
+
Base64.decode64("VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGluZSB0aHJlZQpBbmQgc28gb24uLi4K"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_encode64
|
25
|
+
assert_equal("", Base64.encode64(""))
|
26
|
+
assert_equal("AA==\n", Base64.encode64("\0"))
|
27
|
+
assert_equal("AAA=\n", Base64.encode64("\0\0"))
|
28
|
+
assert_equal("AAAA\n", Base64.encode64("\0\0\0"))
|
29
|
+
assert_equal("/w==\n", Base64.encode64("\377"))
|
30
|
+
assert_equal("//8=\n", Base64.encode64("\377\377"))
|
31
|
+
assert_equal("////\n", Base64.encode64("\377\377\377"))
|
32
|
+
assert_equal("/+8=\n", Base64.encode64("\xff\xef"))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_decode64
|
36
|
+
assert_equal("", Base64.decode64(""))
|
37
|
+
assert_equal("\0", Base64.decode64("AA==\n"))
|
38
|
+
assert_equal("\0\0", Base64.decode64("AAA=\n"))
|
39
|
+
assert_equal("\0\0\0", Base64.decode64("AAAA\n"))
|
40
|
+
assert_equal("\377", Base64.decode64("/w==\n"))
|
41
|
+
assert_equal("\377\377", Base64.decode64("//8=\n"))
|
42
|
+
assert_equal("\377\377\377", Base64.decode64("////\n"))
|
43
|
+
assert_equal("\xff\xef", Base64.decode64("/+8=\n"))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_strict_encode64
|
47
|
+
assert_equal("", Base64.strict_encode64(""))
|
48
|
+
assert_equal("AA==", Base64.strict_encode64("\0"))
|
49
|
+
assert_equal("AAA=", Base64.strict_encode64("\0\0"))
|
50
|
+
assert_equal("AAAA", Base64.strict_encode64("\0\0\0"))
|
51
|
+
assert_equal("/w==", Base64.strict_encode64("\377"))
|
52
|
+
assert_equal("//8=", Base64.strict_encode64("\377\377"))
|
53
|
+
assert_equal("////", Base64.strict_encode64("\377\377\377"))
|
54
|
+
assert_equal("/+8=", Base64.strict_encode64("\xff\xef"))
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_strict_decode64
|
58
|
+
assert_equal("", Base64.strict_decode64(""))
|
59
|
+
assert_equal("\0", Base64.strict_decode64("AA=="))
|
60
|
+
assert_equal("\0\0", Base64.strict_decode64("AAA="))
|
61
|
+
assert_equal("\0\0\0", Base64.strict_decode64("AAAA"))
|
62
|
+
assert_equal("\377", Base64.strict_decode64("/w=="))
|
63
|
+
assert_equal("\377\377", Base64.strict_decode64("//8="))
|
64
|
+
assert_equal("\377\377\377", Base64.strict_decode64("////"))
|
65
|
+
assert_equal("\xff\xef", Base64.strict_decode64("/+8="))
|
66
|
+
|
67
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("^") }
|
68
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("A") }
|
69
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("A^") }
|
70
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AA") }
|
71
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AA=") }
|
72
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AA===") }
|
73
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AA=x") }
|
74
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AAA") }
|
75
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AAA^") }
|
76
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AB==") }
|
77
|
+
assert_raise(ArgumentError) { Base64.strict_decode64("AAB=") }
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_urlsafe_encode64
|
81
|
+
assert_equal("", Base64.urlsafe_encode64(""))
|
82
|
+
assert_equal("AA==", Base64.urlsafe_encode64("\0"))
|
83
|
+
assert_equal("AAA=", Base64.urlsafe_encode64("\0\0"))
|
84
|
+
assert_equal("AAAA", Base64.urlsafe_encode64("\0\0\0"))
|
85
|
+
assert_equal("_w==", Base64.urlsafe_encode64("\377"))
|
86
|
+
assert_equal("__8=", Base64.urlsafe_encode64("\377\377"))
|
87
|
+
assert_equal("____", Base64.urlsafe_encode64("\377\377\377"))
|
88
|
+
assert_equal("_-8=", Base64.urlsafe_encode64("\xff\xef"))
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_urlsafe_encode64_unpadded
|
92
|
+
assert_equal("", Base64.urlsafe_encode64("", padding: false))
|
93
|
+
assert_equal("AA", Base64.urlsafe_encode64("\0", padding: false))
|
94
|
+
assert_equal("AAA", Base64.urlsafe_encode64("\0\0", padding: false))
|
95
|
+
assert_equal("AAAA", Base64.urlsafe_encode64("\0\0\0", padding: false))
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_urlsafe_decode64
|
99
|
+
assert_equal("", Base64.urlsafe_decode64(""))
|
100
|
+
assert_equal("\0", Base64.urlsafe_decode64("AA=="))
|
101
|
+
assert_equal("\0\0", Base64.urlsafe_decode64("AAA="))
|
102
|
+
assert_equal("\0\0\0", Base64.urlsafe_decode64("AAAA"))
|
103
|
+
assert_equal("\377", Base64.urlsafe_decode64("_w=="))
|
104
|
+
assert_equal("\377\377", Base64.urlsafe_decode64("__8="))
|
105
|
+
assert_equal("\377\377\377", Base64.urlsafe_decode64("____"))
|
106
|
+
assert_equal("\xff\xef", Base64.urlsafe_decode64("_+8="))
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_urlsafe_decode64_unpadded
|
110
|
+
assert_equal("\0", Base64.urlsafe_decode64("AA"))
|
111
|
+
assert_equal("\0\0", Base64.urlsafe_decode64("AAA"))
|
112
|
+
assert_equal("\0\0\0", Base64.urlsafe_decode64("AAAA"))
|
113
|
+
assert_raise(ArgumentError) { Base64.urlsafe_decode64("AA=") }
|
114
|
+
end
|
115
|
+
end
|