File: 07-eqatic.t

package info (click to toggle)
nqp 2022.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,436 kB
  • sloc: java: 28,030; perl: 3,394; ansic: 451; makefile: 200; javascript: 68; sh: 1
file content (39 lines) | stat: -rw-r--r-- 1,441 bytes parent folder | download | duplicates (4)
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
## TODO XXX need MORE tests to check failures, not just succeses
plan(103);
ok(!nqp::eqatic('b', 'bb', 0), "MVM index/eqatic bug");
ok(!nqp::eqatic('st', 'sta', 0));
ok(!nqp::eqatic('st', 'stassssssss', 0));
ok(!nqp::eqatic('st', 'stassssssss', 0));
ok( nqp::eqatic('aBcdef', 'bcd', 1));
# With ligatures that expand under casefolding
ok( nqp::eqatic('aastaa', 'st', 2) );
ok( nqp::eqatic('aastaa', 'st', 2) );
ok( nqp::eqatic('aastaa', 'st', 2) );
ok( nqp::eqatic('aastaaz', 'z', 5) );
ok( nqp::eqatic('aastzaa', 'z', 3) );
ok( nqp::eqatic('aaast', 'st', 3) );
ok( nqp::eqatic('staaa', 'st', 0) );
ok( nqp::eqatic('st', 'st', 0) );
ok( nqp::eqatic('st', 'st', 0) );
ok( nqp::eqatic('aaaast', 'st', 4) );
ok( nqp::eqatic('AAAAst', 'st', 4) );
test-it('st', 'st',  20, 1);
test-it('st', 'st',  20, 0);
test-it('st', 'st',  20, 1);
test-it('st', 'st',  20, 0);
# Without codepoint which expand when casefolded
for (0,1,2,3,4,5,6) -> $val {
    my str $letter := nqp::chr($val + nqp::ord('A'));
    ok( nqp::eqatic('ABCDEFG', $letter, $val), "nqp::eqatic(\$needle,  '$letter', $val)");
}

sub test-it ($needle, $text, $max, $opt) {
    my int $i := 0;
    while ($i < $max) {
        my str $str := nqp::x('a', $max - $i);
        $str := $str ~ $text;
        $str := $str ~ nqp::x('b', $i) if $opt;
        ok( nqp::eqatic($str, $needle, $max - $i), "eqatic haystack = '$str' needle = '$needle' $i");
        $i++
    }
}