1#!./parrot 2# Copyright (C) 2009-2010, Parrot Foundation. 3 4=head1 NAME 5 6t/library/configure.t 7 8=head1 DESCRIPTION 9 10Test the Configure PBC 11 12=head1 SYNOPSIS 13 14 % prove t/library/configure.t 15 16=cut 17 18.sub 'main' :main 19 .include 'test_more.pir' 20 21 load_bytecode 'Configure/genfile.pbc' 22 23 plan(40) 24 test_conditioned_line() 25 test_eval_expr() 26 test_interpolate_var() 27 test_replace_slash() 28.end 29 30.sub 'test_conditioned_line' 31 .local pmc config 32 config = new 'Hash' 33 config['foo'] = 1 34 config['bar'] = 0 35 config['baz'] = 1 36 37 $S0 = conditioned_line("plain text\nwithout #", config) 38 is($S0, "plain text\nwithout #\n", "plain text") 39 40 $S0 = conditioned_line("#IF(malformed", config) 41 is($S0, "#IF(malformed\n", "malformed") 42 43 $S0 = conditioned_line("#IF(foo):positive", config) 44 is($S0, "positive\n", "#IF positive") 45 $S0 = conditioned_line("#IF(bar):negative", config) 46 is($S0, "", "#IF negative") 47 48 $S0 = conditioned_line("#UNLESS(bar):positive", config) 49 is($S0, "positive\n", "#UNLESS positive") 50 $S0 = conditioned_line("#UNLESS(foo):negative", config) 51 is($S0, "", "#UNLESS negative") 52 53 $S0 = conditioned_line("#IF(foo):positive\n#ELSE:alternate", config) 54 is($S0, "positive\n", "#IF/ELSE positive") 55 $S0 = conditioned_line("#IF(bar):negative\n#ELSE:alternate", config) 56 is($S0, "alternate\n", "#IF/ELSE alternate") 57 58 $S0 = conditioned_line("#IF(foo):positive\n#ELSIF(baz):alternate", config) 59 is($S0, "positive\n", "#IF/ELSIF positive") 60 $S0 = conditioned_line("#IF(bar):negative\n#ELSIF(baz):alternate", config) 61 is($S0, "alternate\n", "#IF/ELSIF alternate") 62 $S0 = conditioned_line("#IF(bar):negative\n#ELSIF(bar):negative", config) 63 is($S0, "", "#IF/ELSIF negative") 64.end 65 66.sub 'test_eval_expr' 67 .local pmc config 68 config = new 'Hash' 69 config['foo'] = 1 70 config['bar'] = 0 71 config['baz'] = 1 72 73 $I0 = cond_eval("foo", config) 74 is($I0, 1, "foo") 75 $I0 = cond_eval(" foo ", config) 76 is($I0, 1, " foo ") 77 $I0 = cond_eval("bar", config) 78 is($I0, 0, "bar") 79 $I0 = cond_eval(" unknown ", config) 80 is($I0, 0, " unknown ") 81 82 $I0 = cond_eval(" ( foo ) ", config) 83 is($I0, 1, " ( foo ) ") 84 85 $I0 = cond_eval("NOT foo", config) 86 is($I0, 0, "NOT foo") 87 $I0 = cond_eval(" NOT bar", config) 88 is($I0, 1, " NOT bar") 89 $I0 = cond_eval("!!foo", config) 90 is($I0, 1, "!!foo") 91 92 $I0 = cond_eval(" foo OR bar ", config) 93 is($I0, 1, " foo OR bar ") 94 $I0 = cond_eval("foo||bar", config) 95 is($I0, 1, "foo||bar") 96 97 $I0 = cond_eval(" foo AND bar ", config) 98 is($I0, 0, " foo AND bar ") 99 $I0 = cond_eval("foo&&bar", config) 100 is($I0, 0, "foo&&bar") 101 102 $I0 = cond_eval(" foo == bar ", config) 103 is($I0, 0, " foo == bar ") 104 $I0 = cond_eval(" foo == baz ", config) 105 is($I0, 1, " foo == baz ") 106 107 $I0 = cond_eval(" foo != bar ", config) 108 is($I0, 1, " foo != bar ") 109 $I0 = cond_eval(" foo != baz ", config) 110 is($I0, 0, " foo != baz ") 111.end 112 113.sub 'test_interpolate_var' 114 .local pmc config 115 config = new 'Hash' 116 config['foo'] = 'bar' 117 $S0 = interpolate_var("# plain text", config) 118 is($S0, "# plain text\n", "plain text") 119 120 $S0 = interpolate_var("\t@echo foo", config) 121 is($S0, "\t@echo foo\n", "@ alone") 122 123 $S0 = interpolate_var("here @foo@ variable", config) 124 is($S0, "here bar variable\n", "variable") 125 126 $S0 = interpolate_var("here @foo@ variable, and here @foo@.", config) 127 is($S0, "here bar variable, and here bar.\n", "variable") 128 129 $S0 = interpolate_var("\t@echo var @foo@.", config) 130 is($S0, "\t@echo var bar.\n", "gives a second change") 131.end 132 133.sub 'test_replace_slash' 134 $S1 = "path/to/somewhere/" 135 $S0 = replace_slash($S1, 'MSWin32') 136 is($S0, "path\\to\\somewhere\\", "paths on win32") 137 $S0 = replace_slash($S1, '*nix') 138 is($S0, $S1, "paths on *nix") 139 140 $S1 = "prove t/*.t" 141 $S0 = replace_slash($S1, 'MSWin32') 142 is($S0, "prove t\\\\*.t") 143 $S0 = replace_slash($S1, '*nix') 144 is($S0, $S1) 145 146 $S1 = "prove t//*.t" 147 $S0 = replace_slash($S1, 'MSWin32') 148 is($S0, "prove t/*.t") 149 $S0 = replace_slash($S1, '*nix') 150 is($S0, "prove t/*.t") 151 152 $S1 = "http:////host//paths//" 153 $S0 = replace_slash($S1, 'MSWin32') 154 is($S0, "http://host/paths/", "url on win32") 155 $S0 = replace_slash($S1, '*nix') 156 is($S0, "http://host/paths/", "url on *nix") 157.end 158 159 160# Local Variables: 161# mode: pir 162# fill-column: 100 163# End: 164# vim: expandtab shiftwidth=4 ft=pir: 165