Debian Codegraph @

test/-ext-/string/test_normalize.rb

raw
1 # frozen_string_literal: false
2 require 'test/unit'
3 require "-test-/string"
4 require "tempfile"
5
6 class Test_StringNormalize < Test::Unit::TestCase
7 =begin
8 def test_normalize_all
9 exclude = [
10 #0x340, 0x341, 0x343, 0x344
11 ]
12 (0x0080..0xFFFD).each do |n|
13 next if 0xD800 <= n && n <= 0xDFFF
14 next if exclude.include? n
15 code = n.to_s(16)
16 Tempfile.create("#{code}-#{n.chr(Encoding::UTF_8)}-") do |tempfile|
17 ary = Dir.glob(File.expand_path("../#{code}-*", tempfile.path))
18 assert_equal 1, ary.size
19 result = ary[0]
20 rn = result[/\/\h+-(.+?)-/, 1]
21 #assert_equal tempfile.path, result, "#{rn.dump} is not U+#{n.to_s(16)}"
22 r2 = Bug::String.new(result ).normalize_ospath
23 rn2 = r2[/\/\h+-(.+?)-/, 1]
24 if tempfile.path == result
25 if tempfile.path == r2
26 else
27 puts "U+#{n.to_s(16)} shouldn't be r2#{rn2.dump}"
28 end
29 else
30 if tempfile.path == r2
31 # puts "U+#{n.to_s(16)} shouldn't be r#{rn.dump}"
32 elsif result == r2
33 puts "U+#{n.to_s(16)} shouldn't be #{rn.dump}"
34 else
35 puts "U+#{n.to_s(16)} shouldn't be r#{rn.dump} r2#{rn2.dump}"
36 end
37 end
38 end
39 end
40 end
41 =end
42
43 def test_normalize
44 %[
45 \u304C \u304B\u3099
46 \u3077 \u3075\u309A
47 \u308F\u3099 \u308F\u3099
48 \u30F4 \u30A6\u3099
49 \u30DD \u30DB\u309A
50 \u30AB\u303A \u30AB\u303A
51 \u00C1 A\u0301
52 B\u030A B\u030A
53 \u0386 \u0391\u0301
54 \u03D3 \u03D2\u0301
55 \u0401 \u0415\u0308
56 \u2260 =\u0338
57 \u{c548} \u{110b}\u{1161}\u{11ab}
58 ].scan(/(\S+)\s+(\S+)/) do |expected, src|
59 result = Bug::String.new(src).normalize_ospath
60 assert_equal expected, result,
61 "#{expected.dump} is expected but #{src.dump}"
62 end
63 end
64
65 def test_not_normalize_kc
66 %W[
67 \u2460
68 \u2162
69 \u3349
70 \u33A1
71 \u337B
72 \u2116
73 \u33CD
74 \u2121
75 \u32A4
76 \u3231
77 ].each do |src|
78 result = Bug::String.new(src).normalize_ospath
79 assert_equal src, result,
80 "#{src.dump} is expected not to be normalized, but #{result.dump}"
81 end
82 end
83
84 def test_dont_normalize_hfsplus
85 %W[
86 \u2190\u0338
87 \u219A
88 \u212B
89 \uF90A
90 \uF9F4
91 \uF961 \uF9DB
92 \uF96F \uF3AA
93 \uF915 \uF95C \uF9BF
94 \uFA0C
95 \uFA10
96 \uFA19
97 \uFA26
98 ].each do |src|
99 result = Bug::String.new(src).normalize_ospath
100 assert_equal src, result,
101 "#{src.dump} is expected not to be normalized, but #{result.dump}"
102 end
103 end
104
105 def test_invalid_sequence
106 assert_separately(%w[-r-test-/string], <<-'end;')
107 assert_equal("\u{fffd}", Bug::String.new("\xff").normalize_ospath)
108 end;
109 end
110 end if Bug::String.method_defined?(:normalize_ospath)