File: frozen_strings_spec.rb

package info (click to toggle)
jruby 9.4.8.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 89,244 kB
  • sloc: ruby: 548,574; java: 276,189; yacc: 25,873; ansic: 6,178; xml: 6,111; sh: 1,855; sed: 94; makefile: 78; jsp: 48; tcl: 40; exp: 12
file content (65 lines) | stat: -rw-r--r-- 2,765 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require_relative '../spec_helper'

describe "The --enable-frozen-string-literal flag causes string literals to" do

  it "produce the same object each time" do
    ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
  end

  it "produce the same object for literals with the same content" do
    ruby_exe(fixture(__FILE__, "freeze_flag_two_literals.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
  end

  it "produce the same object for literals with the same content in different files" do
    ruby_exe(fixture(__FILE__, "freeze_flag_across_files.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
  end

  it "produce different objects for literals with the same content in different files if they have different encodings" do
    ruby_exe(fixture(__FILE__, "freeze_flag_across_files_diff_enc.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
  end
end

describe "The --disable-frozen-string-literal flag causes string literals to" do

  it "produce a different object each time" do
    ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--disable-frozen-string-literal").chomp.should == "false"
  end

end

describe "With neither --enable-frozen-string-literal nor --disable-frozen-string-literal flag set" do
  before do
    # disable --enable-frozen-string-literal and --disable-frozen-string-literal passed in $RUBYOPT
    @rubyopt = ENV["RUBYOPT"]
    ENV["RUBYOPT"] = ""
  end

  after do
    ENV["RUBYOPT"] = @rubyopt
  end

  it "produce a different object each time" do
    ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
  end

  it "if file has no frozen_string_literal comment produce different mutable strings each time" do
    ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
  end

  it "if file has frozen_string_literal:true comment produce same frozen strings each time" do
    ruby_exe(fixture(__FILE__, "string_literal_frozen_comment.rb")).chomp.should == "frozen:true interned:true"
  end

  it "if file has frozen_string_literal:false comment produce different mutable strings each time" do
    ruby_exe(fixture(__FILE__, "string_literal_mutable_comment.rb")).chomp.should == "frozen:false interned:false"
  end
end

describe "The --debug flag produces" do
  it "debugging info on attempted frozen string modification" do
    error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug',  args: "2>&1")
    error_str.should include("can't modify frozen String")
    error_str.should include("created at")
    error_str.should include("command_line/fixtures/debug_info.rb:2")
  end
end