summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-20 09:10:17 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-20 09:10:17 +0000
commitf685b401293e05c3a7543ede6b0803c9062c1b19 (patch)
treeefab878f7adf18150e8df7b31c6cda11d103542e
parent42bf89945890b04ee11e5128d2db34cb3dd0b5a4 (diff)
rename a() to b() and define a() for US-ASCII
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_m17n_comb.rb99
1 files changed, 50 insertions, 49 deletions
diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb
index 8069885793..1fa3d7d481 100644
--- a/test/ruby/test_m17n_comb.rb
+++ b/test/ruby/test_m17n_comb.rb
@@ -7,10 +7,11 @@ class TestM17NComb < Test::Unit::TestCase
end
module AESU
- def a(str) str.dup.force_encoding("ASCII-8BIT") end
- def e(str) str.dup.force_encoding("EUC-JP") end
- def s(str) str.dup.force_encoding("Shift_JIS") end
- def u(str) str.dup.force_encoding("UTF-8") end
+ def a(str) str.dup.force_encoding(Encoding::US_ASCII) end
+ def b(str) str.b end
+ def e(str) str.dup.force_encoding(Encoding::EUC_JP) end
+ def s(str) str.dup.force_encoding(Encoding::SJIS) end
+ def u(str) str.dup.force_encoding(Encoding::UTF_8) end
end
include AESU
extend AESU
@@ -19,16 +20,16 @@ class TestM17NComb < Test::Unit::TestCase
assert_instance_of(String, actual, message)
enc = Encoding.find(enc) if String === enc
assert_equal(enc, actual.encoding, message)
- assert_equal(a(bytes), a(actual), message)
+ assert_equal(b(bytes), b(actual), message)
end
STRINGS = [
- a(""), e(""), s(""), u(""),
- a("a"), e("a"), s("a"), u("a"),
- a("."), e("."), s("."), u("."),
+ b(""), e(""), s(""), u(""),
+ b("a"), e("a"), s("a"), u("a"),
+ b("."), e("."), s("."), u("."),
# single character
- a("\x80"), a("\xff"),
+ b("\x80"), b("\xff"),
e("\xa1\xa1"), e("\xfe\xfe"),
e("\x8e\xa1"), e("\x8e\xfe"),
e("\x8f\xa1\xa1"), e("\x8f\xfe\xfe"),
@@ -37,7 +38,7 @@ class TestM17NComb < Test::Unit::TestCase
u("\xc2\x80"), u("\xf4\x8f\xbf\xbf"),
# same byte sequence
- a("\xc2\xa1"), e("\xc2\xa1"), s("\xc2\xa1"), u("\xc2\xa1"),
+ b("\xc2\xa1"), e("\xc2\xa1"), s("\xc2\xa1"), u("\xc2\xa1"),
s("\x81A"), # mutibyte character which contains "A"
s("\x81a"), # mutibyte character which contains "a"
@@ -49,7 +50,7 @@ class TestM17NComb < Test::Unit::TestCase
# for transitivity test
u("\xe0\xa0\xa1"), e("\xe0\xa0\xa1"), s("\xe0\xa0\xa1"), # [ruby-dev:32693]
- e("\xa1\xa1"), a("\xa1\xa1"), s("\xa1\xa1"), # [ruby-dev:36484]
+ e("\xa1\xa1"), b("\xa1\xa1"), s("\xa1\xa1"), # [ruby-dev:36484]
]
WSTRINGS = [
@@ -200,7 +201,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_new
STRINGS.each {|s|
t = String.new(s)
- assert_strenc(a(s), s.encoding, t)
+ assert_strenc(b(s), s.encoding, t)
}
end
@@ -211,7 +212,7 @@ class TestM17NComb < Test::Unit::TestCase
else
t = enccall(s1, :+, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert_equal(a(s1) + a(s2), a(t))
+ assert_equal(b(s1) + b(s2), b(t))
assert_str_enc_propagation(t, s1, s2)
end
}
@@ -222,17 +223,17 @@ class TestM17NComb < Test::Unit::TestCase
[0,1,2].each {|n|
t = s * n
assert(t.valid_encoding?) if s.valid_encoding?
- assert_strenc(a(s) * n, s.encoding, t)
+ assert_strenc(b(s) * n, s.encoding, t)
}
}
end
def test_sprintf_s
STRINGS.each {|s|
- assert_strenc(a(s), s.encoding, "%s".force_encoding(s.encoding) % s)
+ assert_strenc(b(s), s.encoding, "%s".force_encoding(s.encoding) % s)
if !s.empty? # xxx
- t = enccall(a("%s"), :%, s)
- assert_strenc(a(s), (a('')+s).encoding, t)
+ t = enccall(b("%s"), :%, s)
+ assert_strenc(b(s), (b('')+s).encoding, t)
end
}
end
@@ -264,7 +265,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_eq
combination(STRINGS, STRINGS) {|s1, s2|
desc_eq = "#{encdump s1} == #{encdump s2}"
- if a(s1) == a(s2) and
+ if b(s1) == b(s2) and
(s1.ascii_only? && s2.ascii_only? or
s1.encoding == s2.encoding) then
assert(s1 == s2, desc_eq)
@@ -286,7 +287,7 @@ class TestM17NComb < Test::Unit::TestCase
if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding
s << s2
assert(s.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert_equal(a(s), a(s1) + a(s2))
+ assert_equal(b(s), b(s1) + b(s2))
assert_str_enc_propagation(s, s1, s2)
else
assert_raise(Encoding::CompatibilityError) { s << s2 }
@@ -335,7 +336,7 @@ class TestM17NComb < Test::Unit::TestCase
if t != nil
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert_equal(s2, t)
- assert_match(/#{Regexp.escape(a(s2))}/, a(s1))
+ assert_match(/#{Regexp.escape(b(s2))}/, b(s1))
if s1.valid_encoding?
assert_match(/#{Regexp.escape(s2)}/, s1)
end
@@ -412,7 +413,7 @@ class TestM17NComb < Test::Unit::TestCase
else
t[i] = s2
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert(a(t).index(a(s2)))
+ assert(b(t).index(b(s2)))
if s1.valid_encoding? && s2.valid_encoding?
if i == s1.length && s2.empty?
assert_nil(t[i])
@@ -441,7 +442,7 @@ class TestM17NComb < Test::Unit::TestCase
else
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
t[i,len] = s2
- assert(a(t).index(a(s2)))
+ assert(b(t).index(b(s2)))
if s1.valid_encoding? && s2.valid_encoding?
if i == s1.length && s2.empty?
assert_nil(t[i])
@@ -500,7 +501,7 @@ class TestM17NComb < Test::Unit::TestCase
else
enccall(t, :[]=, first..last, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert(a(t).index(a(s2)))
+ assert(b(t).index(b(s2)))
if s1.valid_encoding? && s2.valid_encoding?
if first < 0
assert_equal(s2, t[s1.length+first, s2.length])
@@ -527,7 +528,7 @@ class TestM17NComb < Test::Unit::TestCase
else
enccall(t, :[]=, first...last, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert(a(t).index(a(s2)))
+ assert(b(t).index(b(s2)))
if s1.valid_encoding? && s2.valid_encoding?
if first < 0
assert_equal(s2, t[s1.length+first, s2.length])
@@ -571,7 +572,7 @@ class TestM17NComb < Test::Unit::TestCase
t2.capitalize!
assert_equal(t1, t2)
r = s.downcase
- r = enccall(r, :sub, /\A[a-z]/) {|ch| a(ch).upcase }
+ r = enccall(r, :sub, /\A[a-z]/) {|ch| b(ch).upcase }
assert_equal(r, t1)
}
end
@@ -588,7 +589,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_center
combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.center(width)
- assert(a(t).index(a(s1)))
+ assert(b(t).index(b(s1)))
}
combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2|
if s2.empty?
@@ -601,7 +602,7 @@ class TestM17NComb < Test::Unit::TestCase
end
t = enccall(s1, :center, width, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert(a(t).index(a(s1)))
+ assert(b(t).index(b(s1)))
assert_str_enc_propagation(t, s1, s2) if (t != s1)
}
end
@@ -609,7 +610,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_ljust
combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.ljust(width)
- assert(a(t).index(a(s1)))
+ assert(b(t).index(b(s1)))
}
combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2|
if s2.empty?
@@ -622,7 +623,7 @@ class TestM17NComb < Test::Unit::TestCase
end
t = enccall(s1, :ljust, width, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert(a(t).index(a(s1)))
+ assert(b(t).index(b(s1)))
assert_str_enc_propagation(t, s1, s2) if (t != s1)
}
end
@@ -630,7 +631,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_rjust
combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.rjust(width)
- assert(a(t).index(a(s1)))
+ assert(b(t).index(b(s1)))
}
combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2|
if s2.empty?
@@ -643,7 +644,7 @@ class TestM17NComb < Test::Unit::TestCase
end
t = enccall(s1, :rjust, width, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
- assert(a(t).index(a(s1)))
+ assert(b(t).index(b(s1)))
assert_str_enc_propagation(t, s1, s2) if (t != s1)
}
end
@@ -672,7 +673,7 @@ class TestM17NComb < Test::Unit::TestCase
t = nil
assert_nothing_raised(desc) { t = s.chop }
assert(t.valid_encoding?) if s.valid_encoding?
- assert(a(s).index(a(t)))
+ assert(b(s).index(b(t)))
t2 = s.dup
t2.chop!
assert_equal(t, t2)
@@ -693,7 +694,7 @@ class TestM17NComb < Test::Unit::TestCase
t = s.clone
assert_equal(s, t)
assert_equal(s.encoding, t.encoding)
- assert_equal(a(s), a(t))
+ assert_equal(b(s), b(t))
}
end
@@ -702,7 +703,7 @@ class TestM17NComb < Test::Unit::TestCase
t = s.dup
assert_equal(s, t)
assert_equal(s.encoding, t.encoding)
- assert_equal(a(s), a(t))
+ assert_equal(b(s), b(t))
}
end
@@ -717,7 +718,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
n = enccall(s1, :count, s2)
- n0 = a(s1).count(a(s2))
+ n0 = b(s1).count(b(s2))
assert_operator(n, :<=, n0)
}
end
@@ -735,12 +736,12 @@ class TestM17NComb < Test::Unit::TestCase
if strict_crypt
next unless salt.ascii_only? && /\A[0-9a-zA-Z.\/]+\z/ =~ salt
end
- if a(salt).length < 2
+ if b(salt).length < 2
assert_raise(ArgumentError) { str.crypt(salt) }
next
end
t = str.crypt(salt)
- assert_equal(a(str).crypt(a(salt)), t, "#{encdump(str)}.crypt(#{encdump(salt)})")
+ assert_equal(b(str).crypt(b(salt)), t, "#{encdump(str)}.crypt(#{encdump(salt)})")
assert_encoding('ASCII-8BIT', t.encoding)
}
end
@@ -791,7 +792,7 @@ class TestM17NComb < Test::Unit::TestCase
assert(t.valid_encoding?)
assert(t.ascii_only?)
u = eval(t)
- assert_equal(a(s), a(u))
+ assert_equal(b(s), b(u))
}
end
@@ -824,7 +825,7 @@ class TestM17NComb < Test::Unit::TestCase
s.each_byte {|b|
bytes << b
}
- a(s).split(//).each_with_index {|ch, i|
+ b(s).split(//).each_with_index {|ch, i|
assert_equal(ch.ord, bytes[i])
}
}
@@ -843,7 +844,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_hex
STRINGS.each {|s|
t = s.hex
- t2 = a(s)[/\A[0-9a-fA-Fx]*/].hex
+ t2 = b(s)[/\A[0-9a-fA-Fx]*/].hex
assert_equal(t2, t)
}
end
@@ -858,7 +859,7 @@ class TestM17NComb < Test::Unit::TestCase
end
t = enccall(s1, :include?, s2)
if t
- assert(a(s1).include?(a(s2)))
+ assert(b(s1).include?(b(s2)))
assert(s1.index(s2))
assert(s1.rindex(s2))
else
@@ -939,7 +940,7 @@ class TestM17NComb < Test::Unit::TestCase
end
if t
#puts "#{encdump s1}.rindex(#{encdump s2}, #{pos}) => #{t}"
- assert(a(s1).index(a(s2)))
+ assert(b(s1).index(b(s2)))
pos2 = pos
pos2 += s1.length if pos < 0
re = /\A(.{0,#{pos2}})#{Regexp.escape(s2)}/m
@@ -991,7 +992,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_intern
STRINGS.each {|s|
- if /\0/ =~ a(s)
+ if /\0/ =~ b(s)
assert_raise(ArgumentError) { s.intern }
elsif s.valid_encoding?
sym = s.intern
@@ -1012,7 +1013,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_oct
STRINGS.each {|s|
t = s.oct
- t2 = a(s)[/\A[0-9a-fA-FxX]*/].oct
+ t2 = b(s)[/\A[0-9a-fA-FxX]*/].oct
assert_equal(t2, t)
}
end
@@ -1120,10 +1121,10 @@ class TestM17NComb < Test::Unit::TestCase
end
t = enccall(s1, :split, s2)
t.each {|r|
- assert(a(s1).include?(a(r)))
+ assert(b(s1).include?(b(r)))
assert_equal(s1.encoding, r.encoding)
}
- assert(a(s1).include?(t.map {|u| a(u) }.join(a(s2))))
+ assert(b(s1).include?(t.map {|u| b(u) }.join(b(s2))))
if s1.valid_encoding? && s2.valid_encoding?
t.each {|r|
assert(r.valid_encoding?)
@@ -1177,7 +1178,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_sum
STRINGS.each {|s|
- assert_equal(a(s).sum, s.sum)
+ assert_equal(b(s).sum, s.sum)
}
end
@@ -1341,8 +1342,8 @@ class TestM17NComb < Test::Unit::TestCase
end
def test_str_succ2
- assert_equal("\x01\x00".force_encoding("US-ASCII"), "\x7f".force_encoding("US-ASCII").succ)
- assert_equal("\x01\x00".b, "\xff".b.succ)
+ assert_equal(a("\x01\x00"), a("\x7f").succ)
+ assert_equal(b("\x01\x00"), b("\xff").succ)
end
def test_str_hash