Fixed ARTEMUS_STR.
[artemus.git] / tests / tests5.pl
blob50865bc656fa3cbefb6567f5c1c043415a7a011c
1 #!/usr/bin/perl
3 use Art5;
5 $art5 = Art5->new();
7 $tests = 0;
8 $tests_ok = 0;
10 $art5->{op}->{ary1} = sub { [ 'a', 'b', 'c' ]; };
11 $art5->{op}->{ary2} = sub { [ [1, 'a'], [2, 'b'], [3, 'b'], [4, 'c'] ]; };
12 $art5->{op}->{ary3} = sub { [ [3, 'b'], [1, 'a'], [2, 'k'], [9, 'z'], [7, 'q' ]]; };
13 $art5->{op}->{link} = sub { "<a href = '" . $art5->exec(shift) . "'>" . $art5->exec(shift) . "</a>"; };
15 sub try {
16 my $code = shift;
17 my $expected = shift;
19 my $result = $art5->process($code);
21 if ($result eq $expected) {
22 print "OK test: ", $code, "\n";
23 $tests_ok++;
25 else {
26 print "ERROR test: ", $code, "\n";
27 print "\tExpected: '", $expected, "' ",
28 "Got: '", $result, "'\n";
31 $tests++;
34 try('<{}>', '');
35 try('1<{}>2', '12');
36 try('1<{#}>2', '12');
37 try('1<{#this is a comment}>2', '12');
38 try('1<{#this is a comment "hello"}>2', '12');
39 try("1<{#this is a comment\n'hello'}>2", '1hello2');
40 try("1<{'hi'#this is a comment\n'hello'}>2", '1hihello2');
41 try('1<{"hello"}>2', '1hello2');
42 try("1<{'hello'}>2", '1hello2');
43 try('1<{"hello\n"}>2', "1hello\n2");
44 try('1<{%arch}>2', '1Unix2');
45 try('1<{3 4}>2', '1342');
46 try('1<{? 3 4}>2', '1342');
47 try('1<{3 4 5 6}>2', '134562');
48 try('1<{? 3 4 5 6}>2', '134562');
49 try('1<{add 3 4}>2', '172');
50 try('1<{foreach ary1}>2', '1abc2');
51 try('1<{foreach ary1 $0}>2', '1abc2');
52 try('1<{foreach ary1 {? "<" $0 ">"}>2', '1<a><b><c>2');
53 try('1<{foreach ary1 $0 ", "}>2', '1a, b, c2');
54 try('1<{foreach ary2}>2', '112342');
55 try('1<{foreach ary2 $0}>2', '112342');
56 try('1<{foreach ary2 $1}>2', '1abbc2');
57 try('1<{foreach ary2 $0 ", "}>2', '11, 2, 3, 42');
58 try('1<{foreach ary2 $1 ", "}>2', '1a, b, b, c2');
59 try('1<{foreach ary2 $0 ", " {? "[" $1 "]"}}>2', '1[a]1, [b]2, 3, [c]42');
60 try('1<{if {eq 1 2} "equal"}>2', '12');
61 try('1<{if {eq 1 1} "equal"}>2', '1equal2');
62 try('1<{if {eq 1 2} "equal" "different"}>2', '1different2');
63 try('1<{if {eq 1 1} "equal" "different"}>2', '1equal2');
64 try('1<{if {eq 1 2} {"equal"}}>2', '12');
65 try('1<{if {eq 1 1} {"equal"}}>2', '1equal2');
66 try('1<{if {eq 1 2} {"equal"} {"different"}}>2', '1different2');
67 try('1<{if {eq 1 1} {"equal"} "different"}}>2', '1equal2');
68 try('1<{link}>2', "1<a href = ''></a>2");
69 try('1<{link "http://url"}>2', "1<a href = 'http://url'></a>2");
70 try('1<{link "http://url" "label"}>2', "1<a href = 'http://url'>label</a>2");
71 try('1<{= "RESULT" 1000}>2<{RESULT}>3', '1210003');
72 try('1<{size ary1}>2', '132');
73 try('1<{size ary2}>2', '142');
74 try('1<{foreach {seq 1 10}}>2', '1123456789102');
75 try('1<{foreach {reverse {seq 1 10}}}>2', '1109876543212');
76 try('1<{foreach {sort ary3 $1}}>2', '1132792');
77 try('1<{foreach {sort ary3 {add 100 $0}}}>2', '1123792');
78 try('1<{case %arch "Windows" "Is Windows" "Unix" "Is Unix"}>2', '1Is Unix2');
79 try('1<{case %arch "Windows" "Is Windows" "MSDOS" "Is MSDOS" "Is Unix"}>2', '1Is Unix2');
80 try("1<{foreach {& 1 2 3 4}}>2", "112342");
81 try('1<{T @"this" "esto" }><{@"this"}>2', "1esto2");
83 print "\nTesting success: ", $tests_ok, '/', $tests, ' (', ($tests_ok / $tests) * 100, "%)\n";
85 exit 0;