Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 86 lines (51 sloc) 4.586 kb
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
1 #!/usr/bin/env perl6
2
2bce131 @supernovus Query parsing changed, Handlers support query options now.
authored
3 BEGIN { @*INC.unshift: './lib' }
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
4
5 use Test;
85d8307 @supernovus Work in progress, nearly there!
authored
6 use Flower::TAL;
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
7
85d8307 @supernovus Work in progress, nearly there!
authored
8 plan 9; ## also from outer space.
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
9
10 my $xml = '<?xml version="1.0"?>';
11
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
12 ## test 1
13
e449ef5 @supernovus Default namespace changed to 'tal' instead of 'petal'.
authored
14 my $template = '<test><item tal:repeat="item items" tal:attributes="alt item/alt" tal:content="item/content"/></test>';
85d8307 @supernovus Work in progress, nearly there!
authored
15 my $tal = Flower::TAL.new();
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
16 my @items = (
17 { :alt<One>, :content<First> },
18 { :alt<Two>, :content<Second> },
19 { :alt<Three>, :content<Third> },
20 );
21
85d8307 @supernovus Work in progress, nearly there!
authored
22 is ~$tal.parse($template, :items(@items)), $xml~'<test><item alt="One">First</item><item alt="Two">Second</item><item alt="Three">Third</item></test>', 'tal:repeat';
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
23
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
24 ## test 2
25
e449ef5 @supernovus Default namespace changed to 'tal' instead of 'petal'.
authored
26 $template = '<test><div tal:repeat="item items" tal:omit-tag=""><tr><td tal:content="item/alt"/><td tal:content="item/content"/></tr></div></test>';
85d8307 @supernovus Work in progress, nearly there!
authored
27 is ~$tal.parse($template, :items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:repeat with nested elements and omit-tag';
2bd1877 @supernovus Tests added, need to fix repeat with nested elements.
authored
28
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
29 ## test 3, Here we test tal:block as well.
30
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
31 $template = '<test><tal:block tal:repeat="item items"><tr><td tal:content="item/alt"/><td tal:content="item/content"/></tr></tal:block></test>';
85d8307 @supernovus Work in progress, nearly there!
authored
32 is ~$tal.parse($template, :items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:block used in repeat';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
33
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
34 ## test 4, Now we're going to test the repeat object.
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
35
36 $template = '<table><tr tal:repeat="row rows"><td tal:repeat="col row"><div tal:define="x repeat/row/number; y repeat/col/number" tal:replace="string:${x} / ${y} = ${col}">row col</div></td></tr></table>';
37
38 my @rows = (
39 [ '1.1', '1.2', '1.3' ],
40 [ '2.1', '2.2', '2.3' ],
41 [ '3.1', '3.2', '3.3' ],
42 );
43
85d8307 @supernovus Work in progress, nearly there!
authored
44 is ~$tal.parse($template, :rows(@rows)), $xml~'<table><tr><td>1 / 1 = 1.1</td><td>1 / 2 = 1.2</td><td>1 / 3 = 1.3</td></tr><tr><td>2 / 1 = 2.1</td><td>2 / 2 = 2.2</td><td>2 / 3 = 2.3</td></tr><tr><td>3 / 1 = 3.1</td><td>3 / 2 = 3.2</td><td>3 / 3 = 3.3</td></tr></table>', 'nested repeat numbers';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
45
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
46 ## test 5
47
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
48 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/odd" tal:attributes="id repeat/item/index">Odd</item><item tal:condition="repeat/item/even" tal:attributes="id repeat/item/index">Even</item></tal:block></test>';
49
85d8307 @supernovus Work in progress, nearly there!
authored
50 is ~$tal.parse($template, :items([1..4])), $xml~'<test><item id="0">Odd</item><item id="1">Even</item><item id="2">Odd</item><item id="3">Even</item></test>', 'repeat with odd and even conditionals';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
51
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
52 ## test 6
53
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
54 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/start">First</item><item tal:condition="repeat/item/inner">Inner</item><item tal:condition="repeat/item/end" tal:attributes="length repeat/item/length">Last</item></tal:block></test>';
55
85d8307 @supernovus Work in progress, nearly there!
authored
56 is ~$tal.parse($template, :items([1..4])), $xml~'<test><item>First</item><item>Inner</item><item>Inner</item><item length="4">Last</item></test>', 'repeat with start, end, inner and length.';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
57
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
58 ## test 7
59
1ed469a @supernovus Cleanups, another() method, initial List utils.
authored
60 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/every \'3\'">Every third</item><item tal:condition="repeat/item/skip \'3\'">Normal item</item></tal:block></test>';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
61
85d8307 @supernovus Work in progress, nearly there!
authored
62 is ~$tal.parse($template, :items([1..7])), $xml~'<test><item>Normal item</item><item>Normal item</item><item>Every third</item><item>Normal item</item><item>Normal item</item><item>Every third</item><item>Normal item</item></test>', 'repeat with every and skip';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
63
031c66b @supernovus Lots of changes, this thing is getting complex. I wish Rakudo was faster...
authored
64 ## test 8
65
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
66 $template = '<test><tal:block tal:repeat="item items"><item tal:condition="repeat/item/lt \'3\'">lt 3</item><item tal:condition="repeat/item/gt \'3\'">gt 3</item><item tal:condition="repeat/item/eq \'3\'">the third</item></tal:block></test>';
67
85d8307 @supernovus Work in progress, nearly there!
authored
68 is ~$tal.parse($template, :items([1..5])), $xml~'<test><item>lt 3</item><item>lt 3</item><item>the third</item><item>gt 3</item><item>gt 3</item></test>', 'repeat with gt, lt and eq';
69
70 ## test 9
71
72 sub attrmake (*@opts) { @opts.join(' ') | @opts.reverse.join(' ') }
73
74 my @options = (
75 { value => 'a', label => 'Option 1' },
76 { value => 'b', label => 'Option 2', selected => 'selected' },
77 { value => 'c', label => 'Option 3' },
78 );
79
80 $template = '<select><option tal:repeat="option options" tal:attributes="value option/value; selected option/selected" tal:content="option/label"/></select>';
81
82 my $attrpos = attrmake 'value="b"', 'selected="selected"';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
83
85d8307 @supernovus Work in progress, nearly there!
authored
84 is ~$tal.parse($template, options => @options), $xml~'<select><option value="a">Option 1</option><option '~$attrpos~'>Option 2</option><option value="c">Option 3</option></select>', 'attributes with undefined value';
f4f1de1 @supernovus Repeat object, default attribute, multiple defines.
authored
85
Something went wrong with that request. Please try again.