File: stash-xs-unicode.t

package info (click to toggle)
libtemplate-perl 3.102-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,680 kB
  • sloc: perl: 14,945; makefile: 11; sh: 5
file content (88 lines) | stat: -rw-r--r-- 2,074 bytes parent folder | download
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
#============================================================= -*-perl-*-
#
# t/stash-xs-unicode.t
#
# Template script to test unicode data with the XS Stash
#
# Written by Andy Wardley <abw@wardley.org> based on code provided
# by Максим Вуец.
#
# Copyright (C) 1996-2009 Andy Wardley.  All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================

use strict;
use warnings;
use lib qw( ./lib ../lib ../blib/lib ../blib/arch ./blib/lib ./blib/arch );
use utf8;
use Template;
use Template::Test;
use Template::Config;
use File::Spec;

# MacOS Catalina won't allow Dynaloader to load from relative paths
# Error: file system relative paths not allowed in hardened program
@INC = map { File::Spec->rel2abs($_) } @INC;

BEGIN {
    unless ($] > 5.007) {
        skip_all("perl < 5.8 can't do unicode well enough\n");
    }
}

# only run the test when compiled with Template::Stash
if ( $Template::Config::STASH ne 'Template::Stash::XS' ) {
    skip_all('Template::Config is not using Template::Stash::XS');
}

require Template::Stash::XS;

binmode STDOUT, ':utf8';

my $data = {
    ascii => 'key',
    utf8  => 'ключ',
    hash  => {
        key  => 'value',
        ключ => 'значение'
    },
    str => 'щука'
};


test_expect(\*DATA, undef, $data);

__DATA__
-- test --
-- name ASCII key --
ascii = [% ascii %]
hash.$ascii = [% hash.$ascii %]
-- expect --
ascii = key
hash.$ascii = value

-- test --
-- name UTF8 length --
str.length = [% str.length %]
-- expect --
str.length = 4

-- test --
-- name UTF8 key fetch --
utf8 = [% utf8 %]
hash.$utf8 = hash.[% utf8 %] = [% hash.$utf8 %]
-- expect --
utf8 = ключ
hash.$utf8 = hash.ключ = значение

-- test --
-- name UTF8 key assign --
[% value = hash.$utf8; hash.$value = utf8 -%]
value = [% value %]
hash.$value = hash.[% value %] = [% hash.$value %]
-- expect --
value = значение
hash.$value = hash.значение = ключ