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