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,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Encoding' do
|
4
|
+
it 'supports US-ASCII' do
|
5
|
+
"è".encoding.name.should == 'UTF-8'
|
6
|
+
"è".force_encoding('ASCII').should == "\xC3\xA8"
|
7
|
+
"è".force_encoding('ascii').should == "\xC3\xA8"
|
8
|
+
"è".force_encoding('US-ASCII').should == "\xC3\xA8"
|
9
|
+
"è".force_encoding('us-ascii').should == "\xC3\xA8"
|
10
|
+
"è".force_encoding('ASCII-8BIT').should == "\xC3\xA8"
|
11
|
+
"è".force_encoding('ascii-8bit').should == "\xC3\xA8"
|
12
|
+
"è".force_encoding('BINARY').should == "\xC3\xA8"
|
13
|
+
"è".force_encoding('binary').should == "\xC3\xA8"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.find' do
|
17
|
+
it 'finds the encoding regardless of the case' do
|
18
|
+
Encoding.find('ASCII').should == Encoding::ASCII
|
19
|
+
Encoding.find('ascii').should == Encoding::ASCII
|
20
|
+
Encoding.find('US-ASCII').should == Encoding::ASCII
|
21
|
+
Encoding.find('us-ascii').should == Encoding::ASCII
|
22
|
+
Encoding.find('ASCII-8BIT').should == Encoding::ASCII
|
23
|
+
Encoding.find('ascii-8bit').should == Encoding::ASCII
|
24
|
+
Encoding.find('BINARY').should == Encoding::ASCII
|
25
|
+
Encoding.find('binary').should == Encoding::ASCII
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
# rubyspec does not have specs for these listed methods
|
5
|
+
describe Time do
|
6
|
+
describe '<=>' do
|
7
|
+
it 'returns -1 when self is less than other' do
|
8
|
+
(Time.new(2015, 1, 1) <=> Time.new(2015, 1, 2)).should == -1
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns 0 when self is equal to other' do
|
12
|
+
(Time.new(2015, 1, 1) <=> Time.new(2015, 1, 1)).should == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns 1 when self is greater than other' do
|
16
|
+
(Time.new(2015, 1, 2) <=> Time.new(2015, 1, 1)).should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns nil when compared to non-Time objects' do
|
20
|
+
(Time.new <=> nil).should == nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#==" do
|
25
|
+
it "returns true if self is equal to other date" do
|
26
|
+
(Time.new(2013, 9, 13) == Time.new(2013, 9, 13)).should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns false if self is not equal to other date" do
|
30
|
+
(Time.new(2013, 10, 2) == Time.new(2013, 10, 11)).should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns false when compared to non-Time objects' do
|
34
|
+
(Time.new == nil).should == false
|
35
|
+
(Time.new == Object.new).should == false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#zone' do
|
40
|
+
context 'with different TZs on Tue Jun 20 20:50:08 UTC 2017' do
|
41
|
+
it 'zone is +12' do
|
42
|
+
time = Time.now
|
43
|
+
|
44
|
+
# export TZ="/usr/share/zoneinfo/Pacific/Fiji"; node -e 'console.log(new Date().toString())'
|
45
|
+
time.JS[:toString] = -> { 'Wed Jun 21 2017 08:42:01 GMT+1200 (+12)' }
|
46
|
+
time.zone.should == '+12'
|
47
|
+
|
48
|
+
# export TZ="/usr/share/zoneinfo/Europe/Rome"; node -e 'console.log(new Date().toString())'
|
49
|
+
time.JS[:toString] = -> { 'Tue Jun 20 2017 22:52:57 GMT+0200 (CEST)' }
|
50
|
+
time.zone.should == 'CEST'
|
51
|
+
|
52
|
+
# export TZ="/usr/share/zoneinfo/Europe/Rome"; node -e 'console.log(new Date().toString())'
|
53
|
+
time.JS[:toString] = -> { 'Tue Jun 20 2017 23:56:54 GMT+0300 (MSK)' }
|
54
|
+
time.zone.should == 'MSK'
|
55
|
+
|
56
|
+
# https://github.com/opal/opal/issues/403
|
57
|
+
time.JS[:toString] = -> { 'Wed May 07 2014 11:59:05 GMT+0300 (Финляндия (лето))' }
|
58
|
+
time.zone.should == 'Финляндия (лето)'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#utc_offset' do
|
64
|
+
it 'returns 0 if the date is UTC' do
|
65
|
+
Time.new.utc.utc_offset.should == 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require File.expand_path('../simple', __FILE__)
|
3
|
+
require File.expand_path('../quoted', __FILE__)
|
4
|
+
require File.expand_path('../inline_block', __FILE__)
|
5
|
+
|
6
|
+
describe "ERB files" do
|
7
|
+
before :each do
|
8
|
+
@simple = Template['opal/stdlib/erb/simple']
|
9
|
+
@quoted = Template['opal/stdlib/erb/quoted']
|
10
|
+
@inline_block = Template['opal/stdlib/erb/inline_block']
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be defined by their filename on Template namespace" do
|
14
|
+
@simple.should be_kind_of(Template)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "calling the block with a context should render the block" do
|
18
|
+
@some_data = "hello"
|
19
|
+
@simple.render(self).should == "<div>hello</div>\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should accept quotes in strings" do
|
23
|
+
@name = "adam"
|
24
|
+
@quoted.render(self).should == "<div class=\"foo\">hello there adam</div>\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to handle inline blocks" do
|
28
|
+
@inline_block.should be_kind_of(Template)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div class="foo">hello <%= "there" + " #{@name}" %></div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<div><%= @some_data %></div>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'js'
|
3
|
+
|
4
|
+
describe 'javascript operations using JS module' do
|
5
|
+
it 'JS.typeof uses typeof to return underlying javascript type' do
|
6
|
+
[1, `null`, `undefined`, Object.new, [], ""].each do |v|
|
7
|
+
JS.typeof(v).should == `typeof #{v}`
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'JS.new uses new to create new instance' do
|
12
|
+
f = `function(){}`
|
13
|
+
f.JS[:prototype].JS[:color] = 'black'
|
14
|
+
JS.new(f).JS[:color].should == 'black'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'JS.new handles blocks' do
|
18
|
+
f = `function(a){this.a = a}`
|
19
|
+
JS.new(f){1}.JS.a.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'JS.instanceof uses instanceof to check if value is an instance of a function' do
|
23
|
+
f = `function(){}`
|
24
|
+
JS.instanceof(JS.new(f), f).should == true
|
25
|
+
JS.instanceof(JS.new(f), `function(){}`).should == false
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'JS.delete uses delete to remove properties from objects' do
|
29
|
+
f = `{a:1}`
|
30
|
+
f.JS[:a].should == 1
|
31
|
+
JS.delete(f, :a)
|
32
|
+
`#{f.JS[:a]} === undefined`.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'JS.in uses in to check for properties in objects' do
|
36
|
+
f = `{a:1}`
|
37
|
+
JS.in(:a, f).should == true
|
38
|
+
JS.in(:b, f).should == false
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'JS.void returns undefined' do
|
42
|
+
f = 1
|
43
|
+
`#{JS.void(f += 1)} === undefined`.should == true
|
44
|
+
f.should == 2
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'JS.call calls global javascript methods' do
|
48
|
+
JS.call(:parseFloat, '1.0').should == 1
|
49
|
+
JS.call(:parseInt, '1').should == 1
|
50
|
+
JS.call(:eval, "({a:1})").JS[:a].should == 1
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'JS.method_missing calls global javascript methods' do
|
54
|
+
JS.parseFloat('1.0').should == 1
|
55
|
+
JS.parseInt('1').should == 1
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'JS.call calls global javascript methods with blocks' do
|
59
|
+
begin
|
60
|
+
JS.global.JS[:_test_global_function] = lambda{|pr| pr.call + 1}
|
61
|
+
JS._test_global_function{1}.should == 2
|
62
|
+
ensure
|
63
|
+
JS.delete(JS.global, :_test_global_function)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'JS.<METHOD> supports complex method calls' do
|
68
|
+
obj = `{ foo: function(){return "foo"} }`
|
69
|
+
args = [1,2,3]
|
70
|
+
obj.JS.foo(*args).should == :foo
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
describe "Hash#to_json" do
|
4
|
+
it "returns a string of all key and value pairs" do
|
5
|
+
{}.to_json.should == "{}"
|
6
|
+
{"a" => 1, "b" => 2}.to_json.should == '{"a":1, "b":2}'
|
7
|
+
|
8
|
+
hash = {"a" => 1, "b" => false, "c" => nil, "d" => true}
|
9
|
+
JSON.parse(hash.to_json).should == hash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Array#to_json" do
|
14
|
+
it "returns a string of all array elements converted to json" do
|
15
|
+
[].to_json.should == "[]"
|
16
|
+
[1, 2, 3].to_json.should == "[1, 2, 3]"
|
17
|
+
[true, nil, false, "3", 42].to_json.should == '[true, null, false, "3", 42]'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Boolean#to_json" do
|
22
|
+
it "returns 'true' when true" do
|
23
|
+
true.to_json.should == "true"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns 'false' when false" do
|
27
|
+
false.to_json.should == "false"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Kernel#to_json" do
|
32
|
+
it "returns an escaped #to_s of the receiver" do
|
33
|
+
self.to_json.should be_kind_of(String)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "NilClass#to_json" do
|
38
|
+
it "returns 'null'" do
|
39
|
+
nil.to_json.should == "null"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "String#to_json" do
|
44
|
+
it "returns an escaped string" do
|
45
|
+
"foo".to_json.should == "\"foo\""
|
46
|
+
"bar\nbaz".to_json.should == "\"bar\\nbaz\""
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "Numeric#to_json" do
|
51
|
+
it "returns a string representing the number" do
|
52
|
+
42.to_json.should == "42"
|
53
|
+
3.142.to_json.should == "3.142"
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
describe "JSON.parse" do
|
4
|
+
it "parses null into nil" do
|
5
|
+
JSON.parse("null").should be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "parses true into true" do
|
9
|
+
JSON.parse("true").should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "parses false into false" do
|
13
|
+
JSON.parse("false").should be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it "parses numbers into numbers" do
|
17
|
+
JSON.parse("42").should == 42
|
18
|
+
JSON.parse("3.142").should == 3.142
|
19
|
+
end
|
20
|
+
|
21
|
+
it "parses arrays into ruby arrays" do
|
22
|
+
JSON.parse("[]").should == []
|
23
|
+
JSON.parse("[1, 2, 3]").should == [1, 2, 3]
|
24
|
+
JSON.parse("[[1, 2, 3], [4, 5]]").should == [[1, 2, 3], [4, 5]]
|
25
|
+
JSON.parse("[null, true, false]").should == [nil, true, false]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "parses object literals into ruby hashes" do
|
29
|
+
JSON.parse("{}").should == {}
|
30
|
+
JSON.parse('{"a": "b"}').should == {"a" => "b"}
|
31
|
+
JSON.parse('{"a": null, "b": 10, "c": [true, false]}').should == {"a" => nil, "b" => 10, "c" => [true, false]}
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raises ParserError for invalid JSON" do
|
35
|
+
lambda { JSON.parse("invalid_json") }.should raise_error(JSON::ParserError)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
# Our implementation of Logger only supports StringIO pipes.
|
5
|
+
# Since we can't portably write a log file, nothing in rubyspec will run.
|
6
|
+
describe Logger do
|
7
|
+
before do
|
8
|
+
@pipe = StringIO.new
|
9
|
+
@logger = Logger.new @pipe
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "level" do
|
13
|
+
it "should set the level to DEBUG by default" do
|
14
|
+
@logger.level.should == Logger::Severity::DEBUG
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow the level to be changed using an integer of a known level" do
|
18
|
+
@logger.level = Logger::Severity::INFO
|
19
|
+
@logger.level.should == Logger::Severity::INFO
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow the level to be changed to an arbitrary integer value" do
|
23
|
+
@logger.level = 1000
|
24
|
+
@logger.level.should == 1000
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow the level to be set using a case-insensitive level name" do
|
28
|
+
@logger.level = 'WaRn'
|
29
|
+
@logger.level.should == Logger::Severity::WARN
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise an ArgumentError if the level is set to an unknown name" do
|
33
|
+
lambda { @logger.level = 'foobar' }.should raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should report when debug level is enabled" do
|
37
|
+
@logger.debug?.should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should report when debug level is not enabled" do
|
41
|
+
@logger.level = Logger::Severity::DEBUG + 1
|
42
|
+
@logger.debug?.should == false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should report when info level is enabled" do
|
46
|
+
@logger.level = Logger::Severity::INFO
|
47
|
+
@logger.info?.should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should report when debug level is not enabled" do
|
51
|
+
@logger.level = Logger::Severity::INFO + 1
|
52
|
+
@logger.info?.should == false
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should report when warn level is enabled" do
|
56
|
+
@logger.level = Logger::Severity::WARN
|
57
|
+
@logger.warn?.should == true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should report when warn level is not enabled" do
|
61
|
+
@logger.level = Logger::Severity::WARN + 1
|
62
|
+
@logger.warn?.should == false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should report when error level is enabled" do
|
66
|
+
@logger.level = Logger::Severity::ERROR
|
67
|
+
@logger.error?.should == true
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should report when error level is not enabled" do
|
71
|
+
@logger.level = Logger::Severity::ERROR + 1
|
72
|
+
@logger.error?.should == false
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should report when fatal level is enabled" do
|
76
|
+
@logger.level = Logger::Severity::FATAL
|
77
|
+
@logger.fatal?.should == true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should report when fatal level is not enabled" do
|
81
|
+
@logger.level = Logger::Severity::FATAL + 1
|
82
|
+
@logger.fatal?.should == false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "add" do
|
87
|
+
it "should not add a message to the log output if level is not enabled" do
|
88
|
+
@logger.level = Logger::Severity::INFO
|
89
|
+
@logger.add(Logger::Severity::DEBUG, 'message').should == true
|
90
|
+
@pipe.string.should == ''
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should add a message to the log output if level is enabled" do
|
94
|
+
@logger.add(Logger::Severity::DEBUG, 'message').should == true
|
95
|
+
@pipe.string.should_not == ''
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should coerce severity to UNKNOWN if falsy" do
|
99
|
+
@logger.level = Logger::Severity::UNKNOWN
|
100
|
+
@logger.add(nil, 'message').should == true
|
101
|
+
@pipe.string.should_not == ''
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should format message using default formatter" do
|
105
|
+
@logger.add(Logger::Severity::DEBUG, 'message', 'program').should == true
|
106
|
+
@pipe.string.should =~ /^D, \[.+?\] +DEBUG -- program: message\n/
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should log debug message if debug level is enabled" do
|
110
|
+
@logger.debug('message').should == true
|
111
|
+
@pipe.string.should =~ /^D, .*: message\n/
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not log debug message if debug level is not enabled" do
|
115
|
+
@logger.level = Logger::Severity::DEBUG + 1
|
116
|
+
@logger.debug('message').should == true
|
117
|
+
@pipe.string.should == ''
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should log info message if info level is enabled" do
|
121
|
+
@logger.level = Logger::Severity::INFO
|
122
|
+
@logger.info('message').should == true
|
123
|
+
@pipe.string.should =~ /^I, .*: message\n/
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should not log info message if info level is not enabled" do
|
127
|
+
@logger.level = Logger::Severity::INFO + 1
|
128
|
+
@logger.info('message').should == true
|
129
|
+
@pipe.string.should == ''
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should log error message if info level is enabled" do
|
133
|
+
@logger.level = Logger::Severity::ERROR
|
134
|
+
@logger.error('message').should == true
|
135
|
+
@pipe.string.should =~ /^E, .*: message\n/
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not log error message if error level is not enabled" do
|
139
|
+
@logger.level = Logger::Severity::ERROR + 1
|
140
|
+
@logger.error('message').should == true
|
141
|
+
@pipe.string.should == ''
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should log fatal message if fatal level is enabled" do
|
145
|
+
@logger.level = Logger::Severity::FATAL
|
146
|
+
@logger.fatal('message').should == true
|
147
|
+
@pipe.string.should =~ /^F, .*: message\n/
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should not log fatal message if fatal level is not enabled" do
|
151
|
+
@logger.level = Logger::Severity::FATAL + 1
|
152
|
+
@logger.fatal('message').should == true
|
153
|
+
@pipe.string.should == ''
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should log unknown message if unknown level is enabled" do
|
157
|
+
@logger.level = Logger::Severity::UNKNOWN
|
158
|
+
@logger.unknown('message').should == true
|
159
|
+
@pipe.string.should =~ /^U, .*: message\n/
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should not log unknown message if unknown level is not enabled" do
|
163
|
+
@logger.level = Logger::Severity::UNKNOWN + 1
|
164
|
+
@logger.unknown('message').should == true
|
165
|
+
@pipe.string.should == ''
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should use level name ANY in message if level is not known" do
|
169
|
+
@logger.add(1000, 'message', 'program').should == true
|
170
|
+
@pipe.string.should =~ /^A, \[.+?\] +ANY -- program: message\n/
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should use message from block passed to add if block is given" do
|
174
|
+
@logger.add(Logger::Severity::DEBUG, nil, 'program') { 'message' }.should == true
|
175
|
+
@pipe.string.should include(' -- program: message')
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should only require severity argument when calling add" do
|
179
|
+
@logger.add(Logger::Severity::DEBUG).should == true
|
180
|
+
@pipe.string.should include('DEBUG -- : nil')
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should not require any arguments when calling level method" do
|
184
|
+
@logger.debug.should == true
|
185
|
+
@pipe.string.should include('DEBUG -- : nil')
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "progname" do
|
190
|
+
it "should set progname to nil by default" do
|
191
|
+
@logger.progname.should be_nil
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should leave progname blank in message by default" do
|
195
|
+
@logger.add(Logger::Severity::DEBUG, 'message').should == true
|
196
|
+
@pipe.string.should include(' DEBUG -- : message')
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should allow the progname to be set" do
|
200
|
+
@logger.progname = 'program'
|
201
|
+
@logger.progname.should == 'program'
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should use the progname from the logger in the message" do
|
205
|
+
@logger.progname = 'program'
|
206
|
+
@logger.add(Logger::Severity::DEBUG, 'message').should == true
|
207
|
+
@pipe.string.should include(' DEBUG -- program: message')
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should allow the progname to be overridden when using add to log a message" do
|
211
|
+
@logger.progname = 'program'
|
212
|
+
@logger.add(Logger::Severity::DEBUG, 'message', 'app').should == true
|
213
|
+
@pipe.string.should include(' DEBUG -- app: message')
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should allow the progname to be overridden when using block form of debug method" do
|
217
|
+
@logger.progname = 'program'
|
218
|
+
@logger.debug('app') { 'message' }.should == true
|
219
|
+
@pipe.string.should include(' DEBUG -- app: message')
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should allow the progname to be overridden when using block form of info method" do
|
223
|
+
@logger.level = Logger::Severity::INFO
|
224
|
+
@logger.progname = 'program'
|
225
|
+
@logger.info('app') { 'message' }.should == true
|
226
|
+
@pipe.string.should include(' INFO -- app: message')
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should allow the progname to be overridden when using block form of warn method" do
|
230
|
+
@logger.level = Logger::Severity::WARN
|
231
|
+
@logger.progname = 'program'
|
232
|
+
@logger.warn('app') { 'message' }.should == true
|
233
|
+
@pipe.string.should include(' WARN -- app: message')
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should allow the progname to be overridden when using block form of error method" do
|
237
|
+
@logger.level = Logger::Severity::ERROR
|
238
|
+
@logger.progname = 'program'
|
239
|
+
@logger.error('app') { 'message' }.should == true
|
240
|
+
@pipe.string.should include(' ERROR -- app: message')
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should allow the progname to be overridden when using block form of fatal method" do
|
244
|
+
@logger.level = Logger::Severity::FATAL
|
245
|
+
@logger.progname = 'program'
|
246
|
+
@logger.fatal('app') { 'message' }.should == true
|
247
|
+
@pipe.string.should include(' FATAL -- app: message')
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should allow the progname to be overridden when using block form of unknown method" do
|
251
|
+
@logger.level = Logger::Severity::UNKNOWN
|
252
|
+
@logger.progname = 'program'
|
253
|
+
@logger.unknown('app') { 'message' }.should == true
|
254
|
+
@pipe.string.should include(' UNKNOWN -- app: message')
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "formatter" do
|
259
|
+
it "should use the default formatter by default" do
|
260
|
+
@logger.formatter.should_not be_nil
|
261
|
+
@logger.formatter.should be_kind_of(Logger::Formatter)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should allow the formatter to be changed" do
|
265
|
+
MyFormatter = Class.new
|
266
|
+
@logger.formatter = MyFormatter.new
|
267
|
+
@logger.formatter.should be_kind_of(MyFormatter)
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should invoke call method on the custom formatter to log a message" do
|
271
|
+
@logger.progname = 'app'
|
272
|
+
@logger.formatter = proc { |severity, time, progname, msg|
|
273
|
+
"#{severity} - #{time.to_i} - #{progname} - #{msg}\n"
|
274
|
+
}
|
275
|
+
@logger.debug('message').should == true
|
276
|
+
@pipe.string.should =~ /^DEBUG - \d+ - app - message\n$/
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "message types" do
|
281
|
+
it "should allow message to be specified as a Hash" do
|
282
|
+
@logger.debug(text: 'message', context: 'account').should == true
|
283
|
+
@pipe.string.should include({ text: 'message', context: 'account' }.inspect)
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should invoke inspect method to convert object message to string" do
|
287
|
+
message = { text: 'message', context: 'account' }
|
288
|
+
class << message
|
289
|
+
def inspect
|
290
|
+
"#{self[:text]} [#{self[:context]}]"
|
291
|
+
end
|
292
|
+
end
|
293
|
+
@logger.debug(message).should == true
|
294
|
+
@pipe.string.should include('message [account]')
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should convert exception message to string" do
|
298
|
+
message = nil
|
299
|
+
begin
|
300
|
+
raise ArgumentError, 'message'
|
301
|
+
rescue => e
|
302
|
+
message = e
|
303
|
+
end
|
304
|
+
@logger.debug(message).should == true
|
305
|
+
@pipe.string.should =~ / message \(ArgumentError\)\nArgumentError: message\n from /
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|