Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Basic tests for I/O and NFG interaction.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use Test; | ||
|
|
||
| plan 4; | ||
|
|
||
| sub spurt-bin($file, $buf) { | ||
| given open($file, :bin, :w) { | ||
| .write: $buf; | ||
| .close; | ||
| } | ||
| } | ||
|
|
||
| sub nonce () { return (".{$*PID}." ~ 1000.rand.Int) } | ||
| my $tmpfile = "temp-test" ~ nonce(); | ||
|
|
||
| { | ||
| # UTF-8 of codepoints 0044 0307 0323 | ||
| spurt-bin $tmpfile, buf8.new(68, 204, 135, 204, 163); | ||
| my $s = slurp $tmpfile, enc => 'utf-8'; | ||
| is $s.chars, 1, 'Reading UTF-8 file as NFG (one grapheme)'; | ||
| } | ||
|
|
||
| { | ||
| # UTF-8 of codepoints 0044 0307 0323 0044 0307 0044 0323 | ||
| spurt-bin $tmpfile, buf8.new(68, 204, 135, 204, 163, 68, 204, 135, 68, 204, 163); | ||
| my $s = slurp $tmpfile, enc => 'utf-8'; | ||
| is $s.chars, 3, 'Reading UTF-8 file as NFG (a few graphemes)'; | ||
| } | ||
|
|
||
| { | ||
| # UTF-16 of codepoints 0044 0307 0323 | ||
| spurt-bin $tmpfile, buf16.new(68, 775, 803); | ||
| my $s = slurp $tmpfile, enc => 'utf-16'; | ||
| is $s.chars, 1, 'Reading UTF-16 file as NFG (one grapheme)'; | ||
| } | ||
|
|
||
| { | ||
| # UTF-16 of codepoints 0044 0307 0323 0044 0307 0044 0323 | ||
| spurt-bin $tmpfile, buf16.new(68, 775, 803, 68, 775, 68, 803); | ||
| my $s = slurp $tmpfile, enc => 'utf-16'; | ||
| is $s.chars, 3, 'Reading UTF-16 file as NFG (a few graphemes)'; | ||
| } | ||
|
|
||
| unlink $tmpfile; |