2 # Copyright (C) 2009-2010, Parrot Foundation.
11 Test the Configure PBC
15 % prove t/library/configure.t
20 .include 'test_more.pir'
22 load_bytecode 'Configure/genfile.pbc'
25 test_conditioned_line()
27 test_interpolate_var()
31 .sub 'test_conditioned_line'
38 $S0 = conditioned_line("plain text\nwithout #", config)
39 is($S0, "plain text\nwithout #\n", "plain text")
41 $S0 = conditioned_line("#IF(malformed", config)
42 is($S0, "#IF(malformed\n", "malformed")
44 $S0 = conditioned_line("#IF(foo):positive", config)
45 is($S0, "positive\n", "#IF positive")
46 $S0 = conditioned_line("#IF(bar):negative", config)
47 is($S0, "", "#IF negative")
49 $S0 = conditioned_line("#UNLESS(bar):positive", config)
50 is($S0, "positive\n", "#UNLESS positive")
51 $S0 = conditioned_line("#UNLESS(foo):negative", config)
52 is($S0, "", "#UNLESS negative")
54 $S0 = conditioned_line("#IF(foo):positive\n#ELSE:alternate", config)
55 is($S0, "positive\n", "#IF/ELSE positive")
56 $S0 = conditioned_line("#IF(bar):negative\n#ELSE:alternate", config)
57 is($S0, "alternate\n", "#IF/ELSE alternate")
59 $S0 = conditioned_line("#IF(foo):positive\n#ELSIF(baz):alternate", config)
60 is($S0, "positive\n", "#IF/ELSIF positive")
61 $S0 = conditioned_line("#IF(bar):negative\n#ELSIF(baz):alternate", config)
62 is($S0, "alternate\n", "#IF/ELSIF alternate")
63 $S0 = conditioned_line("#IF(bar):negative\n#ELSIF(bar):negative", config)
64 is($S0, "", "#IF/ELSIF negative")
74 $I0 = cond_eval("foo", config)
76 $I0 = cond_eval(" foo ", config)
78 $I0 = cond_eval("bar", config)
80 $I0 = cond_eval(" unknown ", config)
81 is($I0, 0, " unknown ")
83 $I0 = cond_eval(" ( foo ) ", config)
84 is($I0, 1, " ( foo ) ")
86 $I0 = cond_eval("NOT foo", config)
88 $I0 = cond_eval(" NOT bar", config)
89 is($I0, 1, " NOT bar")
90 $I0 = cond_eval("!!foo", config)
93 $I0 = cond_eval(" foo OR bar ", config)
94 is($I0, 1, " foo OR bar ")
95 $I0 = cond_eval("foo||bar", config)
96 is($I0, 1, "foo||bar")
98 $I0 = cond_eval(" foo AND bar ", config)
99 is($I0, 0, " foo AND bar ")
100 $I0 = cond_eval("foo&&bar", config)
101 is($I0, 0, "foo&&bar")
103 $I0 = cond_eval(" foo == bar ", config)
104 is($I0, 0, " foo == bar ")
105 $I0 = cond_eval(" foo == baz ", config)
106 is($I0, 1, " foo == baz ")
108 $I0 = cond_eval(" foo != bar ", config)
109 is($I0, 1, " foo != bar ")
110 $I0 = cond_eval(" foo != baz ", config)
111 is($I0, 0, " foo != baz ")
114 .sub 'test_interpolate_var'
117 config['foo'] = 'bar'
118 $S0 = interpolate_var("# plain text", config)
119 is($S0, "# plain text\n", "plain text")
121 $S0 = interpolate_var("\t@echo foo", config)
122 is($S0, "\t@echo foo\n", "@ alone")
124 $S0 = interpolate_var("here @foo@ variable", config)
125 is($S0, "here bar variable\n", "variable")
127 $S0 = interpolate_var("here @foo@ variable, and here @foo@.", config)
128 is($S0, "here bar variable, and here bar.\n", "variable")
130 $S0 = interpolate_var("\t@echo var @foo@.", config)
131 is($S0, "\t@echo var bar.\n", "gives a second change")
134 .sub 'test_replace_slash'
135 $S1 = "path/to/somewhere/"
136 $S0 = replace_slash($S1, 'MSWin32')
137 is($S0, "path\\to\\somewhere\\", "paths on win32")
138 $S0 = replace_slash($S1, '*nix')
139 is($S0, $S1, "paths on *nix")
142 $S0 = replace_slash($S1, 'MSWin32')
143 is($S0, "prove t\\\\*.t")
144 $S0 = replace_slash($S1, '*nix')
148 $S0 = replace_slash($S1, 'MSWin32')
149 is($S0, "prove t/*.t")
150 $S0 = replace_slash($S1, '*nix')
151 is($S0, "prove t/*.t")
153 $S1 = "http:////host//paths//"
154 $S0 = replace_slash($S1, 'MSWin32')
155 is($S0, "http://host/paths/", "url on win32")
156 $S0 = replace_slash($S1, '*nix')
157 is($S0, "http://host/paths/", "url on *nix")
165 # vim: expandtab shiftwidth=4 ft=pir: