aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--template/unicode_norm_gen.tmpl10
-rw-r--r--test/test_unicode_normalize.rb4
2 files changed, 12 insertions, 2 deletions
diff --git a/template/unicode_norm_gen.tmpl b/template/unicode_norm_gen.tmpl
index 2123643018..b8f9f963b3 100644
--- a/template/unicode_norm_gen.tmpl
+++ b/template/unicode_norm_gen.tmpl
@@ -7,7 +7,7 @@
# Constants for input and ouput directory
InputDataDir = ARGV[0] || 'enc/unicode/data'
-OuputDataDir = ARGV[1] || 'lib/unicode_normalize'
+unicode_version = InputDataDir[/[\d.]+\z/]
# convenience methods
class Integer
@@ -67,6 +67,12 @@ end
# read the file 'CompositionExclusions.txt'
composition_exclusions = vpath.open("#{InputDataDir}/CompositionExclusions.txt") {|f|
+ base = Regexp.quote(File.basename(f.path, '.*'))
+ ext = Regexp.quote(File.extname(f.path))
+ version = (line = f.gets)[/^# *#{base}-([\d.]+)#{ext}\s*$/, 1] or
+ abort "No file version in #{f.path}: #{line}"
+ (unicode_version ||= version) == version or
+ abort "Unicode version of directory (#{unicode_version}) and file (#{version}) mismatch"
f.grep(/^[A-Z0-9]{4,5}/) {|line| line.hex}
}
@@ -151,6 +157,8 @@ end
# automatically generated by template/unicode_norm_gen.tmpl
module UnicodeNormalize
+ UNICODE_VERSION = "<%=unicode_version%>".freeze
+
accents = "" \
"[<% accent_array.each_regexp_chars do |rx|%><%=rx%>" \
"<% end%>]" \
diff --git a/test/test_unicode_normalize.rb b/test/test_unicode_normalize.rb
index 64916a0855..75b571a4a3 100644
--- a/test/test_unicode_normalize.rb
+++ b/test/test_unicode_normalize.rb
@@ -3,15 +3,17 @@
# Copyright Ayumu Nojima (野島 歩) and Martin J. Dürst (duerst@it.aoyama.ac.jp)
require 'test/unit'
+require 'unicode_normalize/normalize'
class TestUnicodeNormalize < Test::Unit::TestCase
- UNICODE_VERSION = '7.0.0'
+ UNICODE_VERSION = UnicodeNormalize::UNICODE_VERSION
NormTest = Struct.new :source, :NFC, :NFD, :NFKC, :NFKD, :line
def read_tests
IO.readlines(File.expand_path("../enc/unicode/data/#{UNICODE_VERSION}/NormalizationTest.txt", __dir__), encoding: 'utf-8')
+ .tap { |lines| assert_include(lines[0], "NormalizationTest-#{UNICODE_VERSION}.txt")}
.collect.with_index { |linedata, linenumber| [linedata, linenumber]}
.reject { |line| line[0] =~ /^[\#@]/ }
.collect do |line|