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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# -*- encoding: US-ASCII -*-
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with encoding modifiers" do
# Note: The encoding implied by a given modifier is specified in
# core/regexp/encoding_spec.rb for 1.9
ruby_version_is ""..."1.9" do
not_compliant_on :macruby do
it "supports /e (EUC encoding)" do
match = /./e.match("\303\251")
match.to_a.should == ["\303\251"]
end
it "supports /e (EUC encoding) with interpolation" do
match = /#{/./}/e.match("\303\251")
match.to_a.should == ["\303\251"]
end
it "supports /e (EUC encoding) with interpolation and /o" do
match = /#{/./}/e.match("\303\251")
match.to_a.should == ["\303\251"]
end
it "supports /n (Normal encoding)" do
/./n.match("\303\251").to_a.should == ["\303"]
end
it "supports /n (Normal encoding) with interpolation" do
/#{/./}/n.match("\303\251").to_a.should == ["\303"]
end
it "supports /n (Normal encoding) with interpolation and /o" do
/#{/./}/no.match("\303\251").to_a.should == ["\303"]
end
it "supports /s (SJIS encoding)" do
/./s.match("\303\251").to_a.should == ["\303"]
end
it "supports /s (SJIS encoding) with interpolation" do
/#{/./}/s.match("\303\251").to_a.should == ["\303"]
end
it "supports /s (SJIS encoding) with interpolation and /o" do
/#{/./}/so.match("\303\251").to_a.should == ["\303"]
end
it "supports /u (UTF8 encoding)" do
/./u.match("\303\251").to_a.should == ["\303\251"]
end
it "supports /u (UTF8 encoding) with interpolation" do
/#{/./}/u.match("\303\251").to_a.should == ["\303\251"]
end
it "supports /u (UTF8 encoding) with interpolation and /o" do
/#{/./}/uo.match("\303\251").to_a.should == ["\303\251"]
end
it "selects last of multiple encoding specifiers" do
/foo/ensuensuens.should == /foo/s
end
end
end
ruby_version_is "1.9" do
it "supports /e (EUC encoding)" do
match = /./e.match("\303\251".force_encoding(Encoding::EUC_JP))
match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)]
end
it "supports /e (EUC encoding) with interpolation" do
match = /#{/./}/e.match("\303\251".force_encoding(Encoding::EUC_JP))
match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)]
end
it "supports /e (EUC encoding) with interpolation /o" do
match = /#{/./}/e.match("\303\251".force_encoding(Encoding::EUC_JP))
match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)]
end
it 'uses EUC-JP as /e encoding' do
/./e.encoding.should == Encoding::EUC_JP
end
it 'preserves EUC-JP as /e encoding through interpolation' do
/#{/./}/e.encoding.should == Encoding::EUC_JP
end
it "supports /n (No encoding)" do
/./n.match("\303\251").to_a.should == ["\303"]
end
it "supports /n (No encoding) with interpolation" do
/#{/./}/n.match("\303\251").to_a.should == ["\303"]
end
it "supports /n (No encoding) with interpolation /o" do
/#{/./}/n.match("\303\251").to_a.should == ["\303"]
end
it 'uses US-ASCII as /n encoding if all chars are 7-bit' do
/./n.encoding.should == Encoding::US_ASCII
end
it 'uses ASCII-8BIT as /n encoding if not all chars are 7-bit' do
/\xFF/n.encoding.should == Encoding::ASCII_8BIT
end
it 'preserves US-ASCII as /n encoding through interpolation if all chars are 7-bit' do
/.#{/./}/n.encoding.should == Encoding::US_ASCII
end
it 'preserves ASCII-8BIT as /n encoding through interpolation if all chars are 7-bit' do
/\xFF#{/./}/n.encoding.should == Encoding::ASCII_8BIT
end
it "supports /s (Windows_31J encoding)" do
match = /./s.match("\303\251".force_encoding(Encoding::Windows_31J))
match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)]
end
it "supports /s (Windows_31J encoding) with interpolation" do
match = /#{/./}/s.match("\303\251".force_encoding(Encoding::Windows_31J))
match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)]
end
it "supports /s (Windows_31J encoding) with interpolation and /o" do
match = /#{/./}/s.match("\303\251".force_encoding(Encoding::Windows_31J))
match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)]
end
it 'uses Windows-31J as /s encoding' do
/./s.encoding.should == Encoding::Windows_31J
end
it 'preserves Windows-31J as /s encoding through interpolation' do
/#{/./}/s.encoding.should == Encoding::Windows_31J
end
it "supports /u (UTF8 encoding)" do
/./u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"]
end
it "supports /u (UTF8 encoding) with interpolation" do
/#{/./}/u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"]
end
it "supports /u (UTF8 encoding) with interpolation and /o" do
/#{/./}/u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"]
end
it 'uses UTF-8 as /u encoding' do
/./u.encoding.should == Encoding::UTF_8
end
it 'preserves UTF-8 as /u encoding through interpolation' do
/#{/./}/u.encoding.should == Encoding::UTF_8
end
# Fails on 1.9; reported as bug #2052
it "selects last of multiple encoding specifiers" do
/foo/ensuensuens.should == /foo/s
end
end
end
|