-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtestTables.lean
More file actions
144 lines (122 loc) · 4.38 KB
/
testTables.lean
File metadata and controls
144 lines (122 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/-
Copyright © 2024-2025 François G. Dorais. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
import UnicodeBasic
import UnicodeData
open Unicode
def testAlphabetic (d : UnicodeData) : Bool :=
let v :=
if d.gc ∈ [.Lu, .Ll, .Lt, .Lm, .Lo, .Nl] then true
else PropList.isOtherAlphabetic d.code
v == lookupAlphabetic d.code
def testBidiClass (d : UnicodeData) : Bool :=
d.bidi == lookupBidiClass d.code
def testBidiMirrored (d : UnicodeData) : Bool :=
d.bidiMirrored == lookupBidiMirrored d.code
def testCanonicalCombiningClass (d : UnicodeData) : Bool :=
d.cc == lookupCanonicalCombiningClass d.code
partial def testCanonicalDecompositionMapping (d : UnicodeData) : Bool :=
let m := lookupCanonicalDecompositionMapping d.code
let l := match d.decomp with
| some ⟨none, l⟩ => mapping (l.map Char.val)
| _ => [d.code]
m == l
where
mapping : List UInt32 → List UInt32
| [] => unreachable!
| c :: cs =>
let d := getUnicodeData! c
match d.decomp with
| some ⟨none, l⟩ => mapping <| l.map Char.val ++ cs
| _ => c :: cs
def testCased (d : UnicodeData) : Bool :=
let v :=
match d.gc with
| .Lu | .Ll | .Lt => true
| _ =>
PropList.isOtherLowercase d.code
|| PropList.isOtherUppercase d.code
v == lookupCased d.code
def testCaseMapping (d : UnicodeData) : Bool :=
let (mu, ml, mt) := lookupCaseMapping d.code
mu == (d.uppercase.map Char.val).getD d.code
&& ml == (d.lowercase.map Char.val).getD d.code
&& mt == (d.titlecase.map Char.val).getD d.code
def testDecompositionMapping (d : UnicodeData) : Bool :=
d.decomp == lookupDecompositionMapping? d.code
def testDefautlIgnorableCodePoint (d : UnicodeData) : Bool :=
let v :=
d.gc == .Cf
|| PropList.isOtherDefaultIgnorableCodePoint d.code
|| PropList.isVariationSelector d.code
let v := v
&& !(0xFFF9 ≤ d.code && d.code ≤ 0xFFFB)
&& !(0x13430 ≤ d.code && d.code ≤ 0x1343F)
&& !PropList.isWhiteSpace d.code
&& !PropList.isPrependedConcatenationMark d.code
v == lookupDefaultIgnorableCodePoint d.code
def testGeneralCategory (d : UnicodeData) : Bool :=
d.gc == lookupGC d.code
def testLowercase (d : UnicodeData) : Bool :=
let v :=
match d.gc with
| .Ll => true
| _ => PropList.isOtherLowercase d.code
v == lookupLowercase d.code
def testMath (d : UnicodeData) : Bool :=
let v :=
match d.gc with
| .Sm => true
| _ => PropList.isOtherMath d.code
v == lookupMath d.code
def testName (d : UnicodeData) : Bool :=
d.name == lookupName d.code
def testNoncharacterCodePoint (d : UnicodeData) : Bool :=
PropList.isNoncharacterCodePoint d.code == lookupNoncharacterCodePoint d.code
def testNumericValue (d : UnicodeData) : Bool :=
d.numeric == lookupNumericValue d.code
def testTitlecase (d : UnicodeData) : Bool :=
let v :=
match d.gc with
| .Lt => true
| _ => false
v == lookupTitlecase d.code
def testUppercase (d : UnicodeData) : Bool :=
let v :=
match d.gc with
| .Lu => true
| _ => PropList.isOtherUppercase d.code
v == lookupUppercase d.code
def testWhiteSpace (d : UnicodeData) : Bool :=
PropList.isWhiteSpace d.code == lookupWhiteSpace d.code
def tests : Array (String × (UnicodeData → Bool)) := #[
("Bidi_Class", testBidiClass),
("Alphabetic", testAlphabetic),
("Bidi_Class", testBidiClass),
("Bidi_Mirrored", testBidiMirrored),
("Canonical_Combining_Class", testCanonicalCombiningClass),
("Canonical_Decomposition_Mapping", testCanonicalDecompositionMapping),
("Case_Mapping", testCaseMapping),
("Cased", testCased),
("Decomposition_Mapping", testDecompositionMapping),
("Default_Ignorable_Code_Point", testDefautlIgnorableCodePoint),
("Lowercase", testLowercase),
("Math", testMath),
("Name", testName),
("Noncharacter_Code_Point", testNoncharacterCodePoint),
("Titlecase", testTitlecase),
("Uppercase", testUppercase),
("Numeric_Value", testNumericValue),
("General_Category", testGeneralCategory),
("White_Space", testWhiteSpace)]
def main (args : List String) : IO UInt32 := do
let args := if args.isEmpty then tests.map Prod.fst else args.toArray
let stream : UnicodeDataStream := {}
let mut err : UInt32 := 0
for d in stream do
for t in tests do
if t.1 ∈ args && !t.2 d then
err := 1
IO.println s!"Error: {t.1} {toHexStringAux d.code}"
return err