Skip to content

Commit 9f304b0

Browse files
committed
Commit the changes to the normalization test-gen.p6
1 parent 64e385f commit 9f304b0

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

S15-normalization/test-gen.p6

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ constant MAX_TESTS_PER_FILE = 2000;
22
constant NUM_SANITY_TESTS = 500;
33
constant SANITY_IDENTITY_RATIO = 3;
44
my $uni-version;
5+
my Str:D $NFC-concat-tests = '';
6+
my Int:D $NFC-concat-tests-number = 0;
57
sub MAIN(Str $unidata-normalization-tests) {
68
# Parse the normalization test data.
79
my @targets = my ($source, $nfc, $nfd, $nfkc, $nfkd) = [] xx 5;
@@ -20,6 +22,12 @@ sub MAIN(Str $unidata-normalization-tests) {
2022
write-test-files('S15-normalization/nfd', 'NFD', $source, $nfd);
2123
write-test-files('S15-normalization/nfkc', 'NFKC', $source, $nfkc);
2224
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";
2331
}
2432

2533
sub write-test-files($template, $method, @source, @expected) {
@@ -30,49 +38,51 @@ sub write-test-files($template, $method, @source, @expected) {
3038
}
3139
write-sanity-test-file($template ~ "-sanity.t", $method, @source, @expected);
3240
}
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.
3347
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;
4249
43-
use Test;
50+
plan $plan;
51+
HEADER
52+
}
4453

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;
5260
for flat @source Z @expected -> $s, $e {
5361
.say: "ok Uni.new(&hexy($s)).$method.list ~~ (&hexy($e),), '$s -> $e';";
5462
if $method eq 'NFC' {
5563
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+
}
6681
}
6782
}
6883

6984
.close;
7085
}
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-
}
7686

7787
say "Wrote $target";
7888
}

0 commit comments

Comments
 (0)