File: default_external_spec.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (87 lines) | stat: -rw-r--r-- 2,633 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require File.expand_path('../../../spec_helper', __FILE__)

with_feature :encoding do
  describe "Encoding.default_external" do
    before(:all) do
      @original_encoding = Encoding.default_external
    end

    after(:all) do
      Encoding.default_external = @original_encoding
    end

    it "returns an Encoding object" do
      Encoding.default_external.should be_an_instance_of(Encoding)
    end

    it "returns the default external encoding" do
      Encoding.default_external = Encoding::UTF_8
      Encoding.default_external.should == Encoding::UTF_8
    end

    describe "with command line options" do
      before :each do
        @lc_all = ENV["LC_ALL"]
        ENV["LC_ALL"] = "C"

        @rbxopt = ENV["RBXOPT"]
        ENV["RBXOPT"] = (@rbxopt || "") + " -X19"
      end

      after :each do
        ENV["LC_ALL"] = @lc_all
        ENV["RBXOPT"] = @rbxopt
      end

      it "is not changed by the -U option" do
        result = ruby_exe("print Encoding.default_external", :options => '-U')
        result.should == "US-ASCII"
      end

      it "returns the encoding specified by '-E external'" do
        result = ruby_exe("print Encoding.default_external", :options => '-E euc-jp')
        result.should == "EUC-JP"
      end

      it "returns the encoding specified by '-E external:'" do
        result = ruby_exe("print Encoding.default_external", :options => '-E Shift_JIS:')
        result.should == "Shift_JIS"
      end
    end
  end

  describe "Encoding.default_external=" do
    before(:all) do
      @original_encoding = Encoding.default_external
    end

    after(:all) do
      Encoding.default_external = @original_encoding
    end

    it "sets the default external encoding" do
      Encoding.default_external = Encoding::UTF_8
      Encoding.default_external.should == Encoding::UTF_8
    end

    it "can accept a name of an encoding as a String" do
      Encoding.default_external = 'Shift_JIS'
      Encoding.default_external.should == Encoding::SHIFT_JIS
    end

    it "calls #to_s on arguments that are neither Strings nor Encodings" do
      string = mock('string')
      string.should_receive(:to_str).twice.and_return('US-ASCII')
      Encoding.default_external = string
      Encoding.default_external.should == Encoding::ASCII
    end

    it "raises a TypeError unless the argument is an Encoding or convertible to a String" do
      lambda { Encoding.default_external = [] }.should raise_error(TypeError)
    end

    it "raises an ArgumentError if the argument is nil" do
      lambda { Encoding.default_external = nil }.should raise_error(ArgumentError)
    end
  end
end