@@ -2,6 +2,8 @@ constant MAX_TESTS_PER_FILE = 2000;
2
2
constant NUM_SANITY_TESTS = 500 ;
3
3
constant SANITY_IDENTITY_RATIO = 3 ;
4
4
my $ uni-version ;
5
+ my Str : D $ NFC-concat-tests = ' ' ;
6
+ my Int : D $ NFC-concat-tests-number = 0 ;
5
7
sub MAIN (Str $ unidata-normalization-tests ) {
6
8
# Parse the normalization test data.
7
9
my @ targets = my ($ source , $ nfc , $ nfd , $ nfkc , $ nfkd ) = [] xx 5 ;
@@ -20,6 +22,12 @@ sub MAIN(Str $unidata-normalization-tests) {
20
22
write-test-files(' S15-normalization/nfd' , ' NFD' , $ source , $ nfd );
21
23
write-test-files(' S15-normalization/nfkc' , ' NFKC' , $ source , $ nfkc );
22
24
write-test-files(' S15-normalization/nfkd' , ' NFKD' , $ source , $ nfkd );
25
+ my $ NFC-concat-target = ' S15-normalization/nfc-concat.t' ;
26
+ $ NFC-concat-target . IO . spurt (
27
+ make-header($ uni-version , $ NFC-concat-tests-number )
28
+ ~ " \n " ~ ' my @list; my @result;' ~ " \n "
29
+ ~ $ NFC-concat-tests
30
+ ) and say " Wrote $ NFC-concat-target" ;
23
31
}
24
32
25
33
sub write-test-files ($ template , $ method , @ source , @ expected ) {
@@ -30,49 +38,51 @@ sub write-test-files($template, $method, @source, @expected) {
30
38
}
31
39
write-sanity-test-file($ template ~ " -sanity.t" , $ method , @ source , @ expected );
32
40
}
41
+ sub make-header (Str : D $ uni-version , Int : D $ plan ) {
42
+ qq :to /HEADER /;
43
+ use v6;
44
+ # Unicode normalization tests, generated from NormalizationTests.txt in the
45
+ # Unicode database by S15-normalization/test-gen.p6.
46
+ # Generated from Unicode version $ uni-version .
33
47
34
- sub write-test-file ($ target , $ method , @ source , @ expected ) {
35
- my $ NFC-concat-tests ;
36
- given open ($ target , : w) {
37
- my $ header = qq :to /HEADER /;
38
- use v6;
39
- # Unicode normalization tests, generated from NormalizationTests.txt in the
40
- # Unicode database by S15-normalization/test-gen.p6.
41
- # Generated from Unicode version $ uni-version .
48
+ use Test;
42
49
43
- use Test;
50
+ plan $ plan ;
51
+ HEADER
52
+ }
44
53
45
- plan { @ source . elems } ;
46
- HEADER
47
- . say : $ header ;
48
- if $ method eq ' NFC' {
49
- $ NFC-concat-tests ~ = $ header ~ " \n " ;
50
- $ NFC-concat-tests ~ = ' my @list; my @result;' ~ " \n " ;
51
- }
54
+ sub write-test-file ($ target , $ method , @ source , @ expected ) {
55
+ my @ last-list ;
56
+ my @ last-result ;
57
+ given open ($ target , : w) {
58
+ my $ header = make-header($ uni-version , @ source . elems );
59
+ . say : $ header ;
52
60
for flat @ source Z @ expected -> $ s , $ e {
53
61
. say : " ok Uni.new(& hexy($ s ) ).$ method .list ~~ (& hexy($ e ) ,), '$ s -> $ e ';" ;
54
62
if $ method eq ' NFC' {
55
63
my @ list = hexy-unjoined($ s );
56
- my $ list-joined = @ list . join (' , ' );
57
- my $ result-joined = & hexy ($ e );
58
- $ NFC-concat-tests ~ = " \@list = $ list-joined ; \@result = $ result-joined ; \n " ;
59
- $ NFC-concat-tests ~ = (
60
- " ok all(((Uni.new("
61
- ~ ' @list[0..($_ - 1)]'
62
- ~ ' ) ~ Uni.new('
63
- ~ ' @list[$_..*]'
64
- ~ " )).$ method .list ~~ \@result " ~ " for 1..(\@list-1))), '$ s -> $ e CONCAT';\n "
65
- );
64
+ my @ result = & hexy-unjoined ($ e );
65
+ my $ list-joined ;
66
+ my $ result-joined ;
67
+ my $ is-synthetic = False ;
68
+ # Only if there's at least two codepoints add it to the concat
69
+ # test file
70
+ if 1 < @ list . elems {
71
+ $ list-joined = @ list . join (' , ' );
72
+ $ result-joined = @ result . join (' , ' );
73
+ $ NFC-concat-tests-number ++ ;
74
+ $ NFC-concat-tests ~ = " \@list = $ list-joined ; \@result = $ result-joined ; \n " ;
75
+ $ NFC-concat-tests ~ = (
76
+ " ok all(((Uni.new(\@list[0..(\$_ - 1)]) ~ Uni.new(\@list[\$_..*]"
77
+ ~ " )).$ method .list ~~ \@result for 1..(\@list-1))), "
78
+ ~ " '$ list-joined -> $ result-joined CONCAT';\n "
79
+ );
80
+ }
66
81
}
67
82
}
68
83
69
84
. close ;
70
85
}
71
- if $ method eq ' NFC' {
72
- my $ NFC-concat-target = $ target . subst (/'nfc' (<[ \S ] - [ / ] >+ '.t' ) /, {" nfc-concat$0" });
73
- $ NFC-concat-target . IO . spurt ($ NFC-concat-tests );
74
- say " Wrote $ NFC-concat-target" ;
75
- }
76
86
77
87
say " Wrote $ target" ;
78
88
}
0 commit comments