diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-27 12:30:05 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-06-27 12:30:05 +0000 |
commit | 9dc121cc577ae7a010bca7efedb79088e3cf7331 (patch) | |
tree | c11a153c7eac91a1e19ed058d5c28f0f7d583622 /spec/ruby/core/kernel | |
parent | fc1f3f14d386b557281ff9a8f19da060befe182e (diff) | |
download | ruby-9dc121cc577ae7a010bca7efedb79088e3cf7331.tar.gz |
Update to ruby/spec@a454137
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/kernel')
-rw-r--r-- | spec/ruby/core/kernel/eql_spec.rb | 1 | ||||
-rw-r--r-- | spec/ruby/core/kernel/eval_spec.rb | 128 | ||||
-rw-r--r-- | spec/ruby/core/kernel/lambda_spec.rb | 1 | ||||
-rw-r--r-- | spec/ruby/core/kernel/printf_spec.rb | 1 |
4 files changed, 128 insertions, 3 deletions
diff --git a/spec/ruby/core/kernel/eql_spec.rb b/spec/ruby/core/kernel/eql_spec.rb index 83185b824a..e62a601a79 100644 --- a/spec/ruby/core/kernel/eql_spec.rb +++ b/spec/ruby/core/kernel/eql_spec.rb @@ -8,4 +8,3 @@ describe "Kernel#eql?" do it_behaves_like :object_equal, :eql? end - diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb index ad06af7b05..fbae8ff3c7 100644 --- a/spec/ruby/core/kernel/eval_spec.rb +++ b/spec/ruby/core/kernel/eval_spec.rb @@ -213,4 +213,132 @@ describe "Kernel#eval" do code = fixture __FILE__, "eval_return_without_lambda.rb" ruby_exe(code).chomp.should == "a,b,c,e,LocalJumpError,f" end + + describe "with a magic encoding comment" do + it "uses the magic comment encoding for the encoding of literal strings" do + code = "# encoding: UTF-8\n'é'.encoding".b + code.encoding.should == Encoding::BINARY + eval(code).should == Encoding::UTF_8 + end + + it "uses the magic comment encoding for parsing constants" do + code = <<CODE.b +# encoding: UTF-8 +class EvalSpecs + Vπ = 3.14 +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπ") + EvalSpecs::Vπ.should == 3.14 + end + + it "allows an emacs-style magic comment encoding" do + code = <<CODE.b +# -*- encoding: UTF-8 -*- +class EvalSpecs +Vπemacs = 3.14 +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπemacs") + EvalSpecs::Vπemacs.should == 3.14 + end + + it "allows spaces before the magic encoding comment" do + code = <<CODE.b +\t \t # encoding: UTF-8 +class EvalSpecs + Vπspaces = 3.14 +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπspaces") + EvalSpecs::Vπspaces.should == 3.14 + end + + it "allows a shebang line before the magic encoding comment" do + code = <<CODE.b +#!/usr/bin/env ruby +# encoding: UTF-8 +class EvalSpecs + Vπshebang = 3.14 +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπshebang") + EvalSpecs::Vπshebang.should == 3.14 + end + + it "allows a shebang line and some spaces before the magic encoding comment" do + code = <<CODE.b +#!/usr/bin/env ruby + # encoding: UTF-8 +class EvalSpecs + Vπshebang_spaces = 3.14 +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπshebang_spaces") + EvalSpecs::Vπshebang_spaces.should == 3.14 + end + + it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do + # Make sure frozen_string_literal is not default true + eval("'foo'".b).frozen?.should be_false + + code = <<CODE.b +# encoding: UTF-8 +# frozen_string_literal: true +class EvalSpecs + Vπstring = "frozen" +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπstring") + EvalSpecs::Vπstring.should == "frozen" + EvalSpecs::Vπstring.encoding.should == Encoding::UTF_8 + EvalSpecs::Vπstring.frozen?.should be_true + end + + it "allows a magic encoding comment and a frozen_string_literal magic comment on the same line in emacs style" do + code = <<CODE.b +# -*- encoding: UTF-8; frozen_string_literal: true -*- +class EvalSpecs +Vπsame_line = "frozen" +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should include(:"Vπsame_line") + EvalSpecs::Vπsame_line.should == "frozen" + EvalSpecs::Vπsame_line.encoding.should == Encoding::UTF_8 + EvalSpecs::Vπsame_line.frozen?.should be_true + end + + it "ignores the magic encoding comment if it is after a frozen_string_literal magic comment" do + code = <<CODE.b +# frozen_string_literal: true +# encoding: UTF-8 +class EvalSpecs + Vπfrozen_first = "frozen" +end +CODE + code.encoding.should == Encoding::BINARY + eval(code) + EvalSpecs.constants(false).should_not include(:"Vπfrozen_first") + binary_constant = "Vπfrozen_first".b.to_sym + EvalSpecs.constants(false).should include(binary_constant) + value = EvalSpecs.const_get(binary_constant) + value.should == "frozen" + value.encoding.should == Encoding::BINARY + value.frozen?.should be_true + end + end end diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb index b27a88e85a..52f340dde5 100644 --- a/spec/ruby/core/kernel/lambda_spec.rb +++ b/spec/ruby/core/kernel/lambda_spec.rb @@ -83,4 +83,3 @@ describe "Kernel.lambda" do KernelSpecs::Lambda.new.outer.should == :good end end - diff --git a/spec/ruby/core/kernel/printf_spec.rb b/spec/ruby/core/kernel/printf_spec.rb index 53ee6419c6..ca88082694 100644 --- a/spec/ruby/core/kernel/printf_spec.rb +++ b/spec/ruby/core/kernel/printf_spec.rb @@ -58,4 +58,3 @@ describe "Kernel.printf" do end end end - |