Debian Codegraph @

t/010_internals/036_merge_hash.t

raw symbols SCIP
1 #!perl
2 use strictscip-perl cpan Text-Xslate v3.5.9 strict/;
3 use warningsscip-perl cpan Text-Xslate v3.5.9 warnings/;
4 use Test::Morescip-perl cpan Text-Xslate v3.5.9 Test/More/;
5
6 use Text::Xslatescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/;
7
8 BEGIN {
9 package Text::Xslate::Syntax::Customscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/;
10 use Mousescip-perl cpan Text-Xslate v3.5.9 Mouse/;
11 extendsscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/extends(). 'Text::Xslate::Parser';
12
13 sub init_symbolsscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/init_symbols(). {
14 my $self = shiftscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/shift().;
15
16 $self->SUPER::init_symbolsscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/`SUPER::init_symbols`().(@_scip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/`@_`.);
17
18 $self->symbolscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/symbol().('merge_hash')->set_nudscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/set_nud().($self->canscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/can().('nud_merge_hash'));
19 }
20
21 sub nud_merge_hashscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/nud_merge_hash(). {
22 my $self = shiftscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/shift().;
23 my ($symbol) = @_scip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/`@_`.;
24
25 $self->advancescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/advance().('(');
26 my $base = $self->expressionscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/expression().(0);
27 $self->advancescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/advance().(',');
28 my $value = $self->expressionscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/expression().(0);
29 $self->advancescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/advance().(')');
30
31 return $symbol->clonescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Syntax/Custom/clone().(
32 arity => 'merge_hash',
33 first => $base,
34 second => $value,
35 );
36 }
37
38 package Text::Xslate::Compiler::Customscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/;
39 use Mousescip-perl cpan Text-Xslate v3.5.9 Mouse/;
40 extendsscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/extends(). 'Text::Xslate::Compiler';
41
42 sub _generate_merge_hashscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/_generate_merge_hash(). {
43 my $self = shiftscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/shift().;
44 my ($node) = @_scip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/`@_`.;
45
46 my $lvar_id = $self->lvar_idscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/lvar_id().;
47 local $self->{lvar_id} = $self->lvar_usescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/lvar_use().(1);
48
49 return (
50 $self->compile_astscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/compile_ast().($node->firstscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/first().),
51 $self->opcodescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/opcode().('save_to_lvar', $lvar_id),
52 $self->compile_astscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/compile_ast().($node->secondscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/second().),
53 $self->opcodescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/opcode().('move_to_sb'),
54 $self->opcodescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/opcode().('load_lvar', $lvar_id),
55 $self->opcodescip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Compiler/Custom/opcode().('merge_hash'),
56 );
57 }
58
59 package Text::Xslate::Customscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/;
60 use basescip-perl cpan Text-Xslate v3.5.9 base/ 'Text::Xslate';
61
62 sub optionsscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/options(). {
63 my $class = shiftscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/shift().;
64
65 my $options = $class->SUPER::optionsscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/`SUPER::options`().(@_scip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/`@_`.);
66
67 $options->{compiler} = 'Text::Xslate::Compiler::Custom';
68 $options->{syntax} = 'Custom';
69
70 return $options;
71 }
72 }
73
74 my $tx = Text::Xslate::Custom->newscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/new().;
75
76 my @tests = (
77 [ ': [ merge_hash($a, $b).foo, $a.foo, $b.foo ].map(-> $elem { defined($elem) ? $elem : "undef" }).join(" ")', 'FOO FOO undef' ],
78 [ ': [ merge_hash($b, $a).foo, $a.foo, $b.foo ].map(-> $elem { defined($elem) ? $elem : "undef" }).join(" ")', 'FOO FOO undef' ],
79 [ ': [ merge_hash($a, $b).bar, $a.bar, $b.bar ].map(-> $elem { defined($elem) ? $elem : "undef" }).join(" ")', 'RAB BAR RAB' ],
80 [ ': [ merge_hash($b, $a).bar, $a.bar, $b.bar ].map(-> $elem { defined($elem) ? $elem : "undef" }).join(" ")', 'BAR BAR RAB' ],
81 [ ': [ merge_hash($a, $b).baz, $a.baz, $b.baz ].map(-> $elem { defined($elem) ? $elem : "undef" }).join(" ")', 'ZAB undef ZAB' ],
82 [ ': [ merge_hash($b, $a).baz, $a.baz, $b.baz ].map(-> $elem { defined($elem) ? $elem : "undef" }).join(" ")', 'ZAB undef ZAB' ],
83 );
84
85 for my $test (@tests) {
86 isscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/is().(
87 $tx->render_stringscip-perl cpan Text-Xslate v3.5.9 Text/Xslate/Custom/render_string().(
88 $test->[0],
89 {
90 a => {
91 foo => 'FOO',
92 bar => 'BAR',
93 },
94 b => {
95 bar => 'RAB',
96 baz => 'ZAB',
97 },
98 }
99 ),
100 $test->[1],
101 $test->[0]
102 );
103 }
104
105 done_testing;