]>
git.proxmox.com Git - rustc.git/blob - src/vendor/unicode-normalization/scripts/unicode_gen_normtests.py
3 # Copyright 2015 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
13 # This script uses the following Unicode tables:
14 # - NormalizationTest.txt
16 # Since this should not require frequent updates, we just store this
17 # out-of-line and check the unicode.rs file into git.
19 import unicode, re
, os
, fileinput
21 def load_test_data(f
):
23 testRe
= re
.compile("^(.*?);(.*?);(.*?);(.*?);(.*?);\s+#.*$")
26 for line
in fileinput
.input(os
.path
.basename(f
)):
27 # comment and header lines start with # and @ respectively
28 if len(line
) < 1 or line
[0:1] == '#' or line
[0:1] == '@':
31 m
= testRe
.match(line
)
34 print "error: no match on line where test was expected: %s" % line
37 has_surrogates
= False
40 chs
= m
.group(i
).split()
43 if unicode.is_surrogate(intch
):
68 outstr
+= "\\u{%x}" % ch
73 if __name__
== "__main__":
74 d
= load_test_data("NormalizationTest.txt")
75 ntype
= "&'static [(&'static str, &'static str, &'static str, &'static str, &'static str)]"
76 with
open("testdata.rs", "w") as nf
:
77 nf
.write(unicode.preamble
)
79 nf
.write(" // official Unicode test data\n")
80 nf
.write(" // http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt\n")
81 unicode.emit_table(nf
, "TEST_NORM", d
, ntype
, True, showfun
)