File: encoding_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 (62 lines) | stat: -rw-r--r-- 1,995 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
# -*- encoding: utf-8 -*-
require File.expand_path('../../../spec_helper', __FILE__)

ruby_version_is "1.9" do
  describe "Regexp#encoding" do

    it "returns an Encoding object" do
      /glar/.encoding.should be_an_instance_of(Encoding)
    end

    it "defaults to US-ASCII if the Regexp contains only US-ASCII character" do
      /ASCII/.encoding.should == Encoding::US_ASCII
    end

    it "returns US_ASCII if the 'n' modifier is supplied and only US-ASCII characters are present" do
      /ASCII/n.encoding.should == Encoding::US_ASCII
    end

    it "returns ASCII-8BIT if the 'n' modifier is supplied and non-US-ASCII characters are present" do
      /#{}\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
    end

    it "defaults to UTF-8 if \\u escapes appear" do
      /\u{9879}/.encoding.should == Encoding::UTF_8
    end

    it "defaults to UTF-8 if a literal UTF-8 character appears" do
      /¥/.encoding.should == Encoding::UTF_8
    end

    it "returns UTF-8 if the 'u' modifier is supplied" do
      /ASCII/u.encoding.should == Encoding::UTF_8
    end

    it "returns Windows-31J if the 's' modifier is supplied" do
      /ASCII/s.encoding.should == Encoding::Windows_31J
    end

    it "returns EUC_JP if the 'e' modifier is supplied" do
      /ASCII/e.encoding.should == Encoding::EUC_JP
    end

    it "upgrades the encoding to that of an embedded String" do
      str = "文字化け".encode('euc-jp')
      /#{str}/.encoding.should == Encoding::EUC_JP
    end

    it "ignores the encoding and uses US-ASCII if the string has only ASCII characters" do
      str = "abc".encode('euc-jp')
      str.encoding.should == Encoding::EUC_JP
      /#{str}/.encoding.should == Encoding::US_ASCII
    end

    it "ignores the default_internal encoding" do
      old_internal = Encoding.default_internal
      Encoding.default_internal = Encoding::EUC_JP
      /foo/.encoding.should_not == Encoding::EUC_JP
      Encoding.default_internal = old_internal
    end

  end
end