File: Cell.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (54 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (2)
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
use Term::Table::Cell;
use strict;
use warnings;
use utf8;

BEGIN {
    if (eval { require Test2::Tools::Tiny }) {
        print "# Using Test2::Tools::Tiny\n";
        Test2::Tools::Tiny->import();
    }
    else {
        print "1..0 # SKIP Test2::Tools::Tiny is not installed\n";
        exit(0);
    }
}

use Test2::API qw/test2_stack/;
test2_stack->top->format->encoding('utf8');

tests sanitization => sub {
    my $unsanitary = <<"    EOT";
This string
has vertical space
including        

 ‌\N{U+000B}unicode stuff
and some non-whitespace ones: 婧 ʶ ๖
    EOT
    my $sanitary = 'This string\nhas vertical space\nincluding\N{U+A0}\N{U+1680}\N{U+2000}\N{U+2001}\N{U+2002}\N{U+2003}\N{U+2004}\N{U+2008}\N{U+2028}\N{U+2029}\N{U+3000}\N{U+200C}\N{U+FEFF}\N{U+B}unicode stuff\nand some non-whitespace ones: 婧 ʶ ๖\n';
    $sanitary =~ s/\\n/\\n\n/g;

    local *show_char = sub { Term::Table::Cell->show_char(@_) };

    # Common control characters
    is(show_char("\a"), '\a',    "translated bell");
    is(show_char("\b"), '\b',    "translated backspace");
    is(show_char("\e"), '\e',    "translated escape");
    is(show_char("\f"), '\f',    "translated formfeed");
    is(show_char("\n"), "\\n\n", "translated newline");
    is(show_char("\r"), '\r',    "translated return");
    is(show_char("\t"), '\t',    "translated tab");
    is(show_char(" "),  ' ',     "plain space is not translated");

    # unicodes
    is(show_char("婧"), '\N{U+5A67}', "translated unicode 婧 (U+5A67)");
    is(show_char("ʶ"),  '\N{U+2B6}',  "translated unicode ʶ (U+2B6)");
    is(show_char("߃"),  '\N{U+7C3}',  "translated unicode ߃ (U+7C3)");
    is(show_char("๖"),  '\N{U+E56}',  "translated unicode ๖ (U+E56)");

    my $cell = Term::Table::Cell->new(value => $unsanitary);
    $cell->sanitize;

    is($cell->value, $sanitary, "Sanitized string");
};

done_testing;