2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2018-06-07 08:07:49 -04:00
|
|
|
require "fileutils"
|
|
|
|
require "open-uri"
|
|
|
|
require "tmpdir"
|
|
|
|
|
2008-09-21 11:37:38 -04:00
|
|
|
module MultibyteTestHelpers
|
2016-07-04 07:11:44 -04:00
|
|
|
class Downloader
|
|
|
|
def self.download(from, to)
|
|
|
|
unless File.exist?(to)
|
|
|
|
unless File.exist?(File.dirname(to))
|
|
|
|
system "mkdir -p #{File.dirname(to)}"
|
|
|
|
end
|
|
|
|
open(from) do |source|
|
2016-08-06 12:03:25 -04:00
|
|
|
File.open(to, "w") do |target|
|
2016-07-04 07:11:44 -04:00
|
|
|
source.each_line do |l|
|
|
|
|
target.write l
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-04 07:36:30 -04:00
|
|
|
UNIDATA_URL = "http://www.unicode.org/Public/#{ActiveSupport::Multibyte::Unicode::UNICODE_VERSION}/ucd"
|
2017-01-26 04:15:37 -05:00
|
|
|
CACHE_DIR = "#{Dir.tmpdir}/cache/unicode_conformance/#{ActiveSupport::Multibyte::Unicode::UNICODE_VERSION}"
|
2016-07-04 07:36:30 -04:00
|
|
|
FileUtils.mkdir_p(CACHE_DIR)
|
|
|
|
|
2018-02-27 23:33:37 -05:00
|
|
|
UNICODE_STRING = "こにちわ"
|
|
|
|
ASCII_STRING = "ohayo"
|
2018-05-17 04:32:27 -04:00
|
|
|
BYTE_STRING = (+"\270\236\010\210\245").force_encoding("ASCII-8BIT").freeze
|
2008-09-21 11:37:38 -04:00
|
|
|
|
|
|
|
def chars(str)
|
|
|
|
ActiveSupport::Multibyte::Chars.new(str)
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect_codepoints(str)
|
2016-08-16 03:30:11 -04:00
|
|
|
str.to_s.unpack("U*").map { |cp| cp.to_s(16) }.join(" ")
|
2008-09-21 11:37:38 -04:00
|
|
|
end
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
def assert_equal_codepoints(expected, actual, message = nil)
|
2008-09-21 11:37:38 -04:00
|
|
|
assert_equal(inspect_codepoints(expected), inspect_codepoints(actual), message)
|
|
|
|
end
|
2010-07-17 02:36:40 -04:00
|
|
|
end
|