2008-09-21 12:31:15 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2008-09-21 11:37:38 -04:00
|
|
|
module MultibyteTestHelpers
|
|
|
|
UNICODE_STRING = 'こにちわ'
|
|
|
|
ASCII_STRING = 'ohayo'
|
|
|
|
BYTE_STRING = "\270\236\010\210\245"
|
2010-07-17 02:36:40 -04:00
|
|
|
if BYTE_STRING.respond_to?(:force_encoding)
|
|
|
|
BYTE_STRING.force_encoding("ASCII-8BIT")
|
|
|
|
end
|
2008-09-21 11:37:38 -04:00
|
|
|
|
|
|
|
def chars(str)
|
|
|
|
ActiveSupport::Multibyte::Chars.new(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect_codepoints(str)
|
|
|
|
str.to_s.unpack("U*").map{|cp| cp.to_s(16) }.join(' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_equal_codepoints(expected, actual, message=nil)
|
|
|
|
assert_equal(inspect_codepoints(expected), inspect_codepoints(actual), message)
|
|
|
|
end
|
2010-07-17 02:36:40 -04:00
|
|
|
end
|