-
Notifications
You must be signed in to change notification settings - Fork 135
/
string_nfg.t
114 lines (78 loc) · 2.63 KB
/
string_nfg.t
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
#!./parrot
# Copyright (C) 2010, Parrot Foundation.
# $Id$
=head1 NAME
t/op/string_nfg.t - test the NFG encoding and related string operations
=head1 SYNOPSIS
% prove t/op/string_mem.t
=head1 DESCRIPTION
Tests the behaviour of nfg-encoded strings when subjected to various
string operations.
=cut
.include 'stringinfo.pasm'
.const int TESTS = 12
.sub _main :main
.include 'test_more.pir'
plan(TESTS)
literals_and_transcoding()
transcode_without_graphemes()
transcode_with_graphemes()
.end
.sub literals_and_transcoding
$S0 = utf16:unicode:"\u006e\u0303\u0303\u0303\u0303\u00d1\u00d1"
$I0 = find_encoding 'nfg'
$S0 = trans_encoding $S0, $I0
$S1 = nfg:unicode:"\u006e\u0303\u0303\u0303\u0303\u00d1\u00d1"
$I0 = stringinfo $S0, .STRINGINFO_STRLEN
$I1 = stringinfo $S1, .STRINGINFO_STRLEN
is($I0, $I1, "Lenght is the same.")
$I0 = stringinfo $S0, .STRINGINFO_BUFUSED
$I1 = stringinfo $S1, .STRINGINFO_BUFUSED
is($I0, $I1, "Bufused is the same.")
# Do the same thing again, without dynamic codepoints.
$S2 = utf16:unicode:"n\u0303"
$I0 = find_encoding 'nfg'
$S2 = trans_encoding $S2, $I0
$S3 = nfg:unicode:"n\u0303"
$I0 = stringinfo $S2, .STRINGINFO_STRLEN
$I1 = stringinfo $S3, .STRINGINFO_STRLEN
is($I0, $I1, "Lenght is the same.")
$I0 = stringinfo $S2, .STRINGINFO_BUFUSED
$I1 = stringinfo $S3, .STRINGINFO_BUFUSED
is($I0, $I1, "Bufused is the same.")
$I0 = stringinfo $S2, .STRINGINFO_EXTRA
$I1 = stringinfo $S3, .STRINGINFO_EXTRA
is($I0, $I1, "EXTRA is the same.")
is($I1, 0, "EXTRA is NULL.")
.end
.sub transcode_without_graphemes
$S0 = "Hello, world"
$I0 = find_encoding 'nfg'
$S1 = trans_encoding $S0, $I0
$I1 = stringinfo $S0, .STRINGINFO_EXTRA
is($I1, 0, "Lazy table creation.")
$I0 = stringinfo $S0, .STRINGINFO_STRLEN
$I1 = stringinfo $S1, .STRINGINFO_STRLEN
is($I0, $I1, "Lenght is the same.")
$I2 = stringinfo $S1, .STRINGINFO_BUFUSED
$I1 *= 4
is($I2, $I1, "bufused = 4 * strlen")
.end
.sub transcode_with_graphemes
$S0 = utf16:unicode:"\u006e\u0303\u0303\u0303\u0303\u00d1\u00d1"
$I0 = find_encoding 'nfg'
$S1 = trans_encoding $S0, $I0
$I1 = stringinfo $S1, .STRINGINFO_EXTRA
isnt($I1, 0, "Lazy table creation.")
$I0 = stringinfo $S0, .STRINGINFO_STRLEN
$I1 = stringinfo $S1, .STRINGINFO_STRLEN
isnt($I0, $I1, "Lenght is not the same.")
$I2 = stringinfo $S1, .STRINGINFO_BUFUSED
$I1 *= 4
is($I2, $I1, "bufused = 4 * strlen")
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: