... | ... |
@@ -71,6 +71,7 @@ sub _parse { |
71 | 71 |
my $pos; |
72 | 72 |
|
73 | 73 |
# Parse |
74 |
+ my $original = $source; |
|
74 | 75 |
while (my $c = substr($source, 0, 1, '')) { |
75 | 76 |
|
76 | 77 |
# State is text |
... | ... |
@@ -112,7 +113,7 @@ sub _parse { |
112 | 113 |
# Unexpected |
113 | 114 |
else { |
114 | 115 |
croak qq/Parsing error. unexpected "}". / . |
115 |
- qq/pos $pos of "$source"/; |
|
116 |
+ qq/pos $pos of "$original"/; |
|
116 | 117 |
} |
117 | 118 |
} |
118 | 119 |
|
... | ... |
@@ -121,7 +122,7 @@ sub _parse { |
121 | 122 |
} |
122 | 123 |
|
123 | 124 |
# State is tags |
124 |
- elsif ($state eq 'tag') { |
|
125 |
+ else { |
|
125 | 126 |
|
126 | 127 |
# Tag start charactor |
127 | 128 |
if ($c eq '{') { |
... | ... |
@@ -135,7 +136,7 @@ sub _parse { |
135 | 136 |
# Unexpected |
136 | 137 |
else { |
137 | 138 |
croak qq/Parsing error. unexpected "{". / . |
138 |
- qq/pos $pos of "$source"/; |
|
139 |
+ qq/pos $pos of "$original"/; |
|
139 | 140 |
} |
140 | 141 |
} |
141 | 142 |
|
... | ... |
@@ -176,7 +177,7 @@ sub _parse { |
176 | 177 |
} |
177 | 178 |
|
178 | 179 |
# Tag not finished |
179 |
- croak qq{Tag not finished. "$source"} |
|
180 |
+ croak qq{Tag not finished. "$original"} |
|
180 | 181 |
if $state eq 'tag'; |
181 | 182 |
|
182 | 183 |
# Add rest text |
... | ... |
@@ -198,17 +199,11 @@ sub _build_query { |
198 | 199 |
# Build SQL |
199 | 200 |
foreach my $node (@$tree) { |
200 | 201 |
|
201 |
- # Get type, tag name, and arguments |
|
202 |
- my $type = $node->{type}; |
|
203 |
- |
|
204 | 202 |
# Text |
205 |
- if ($type eq 'text') { |
|
206 |
- # Join text |
|
207 |
- $sql .= $node->{value}; |
|
208 |
- } |
|
203 |
+ if ($node->{type} eq 'text') { $sql .= $node->{value} } |
|
209 | 204 |
|
210 | 205 |
# Tag |
211 |
- elsif ($type eq 'tag') { |
|
206 |
+ else { |
|
212 | 207 |
|
213 | 208 |
# Tag name |
214 | 209 |
my $tag_name = $node->{tag_name}; |
... | ... |
@@ -16,6 +16,8 @@ my $datas; |
16 | 16 |
my $builder; |
17 | 17 |
my $query; |
18 | 18 |
my $ret_val; |
19 |
+my $source; |
|
20 |
+my $tree; |
|
19 | 21 |
|
20 | 22 |
test "Various source pattern"; |
21 | 23 |
$datas = [ |
... | ... |
@@ -142,7 +144,24 @@ eval{$builder->build_query("{in a r}")}; |
142 | 144 |
like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, |
143 | 145 |
"$test : in : key not exist"); |
144 | 146 |
|
145 |
-test '_parse'; |
|
147 |
+test 'variouse source'; |
|
148 |
+$source = "a {= b} c \\{ \\} {= \\{} {= \\}} d;"; |
|
149 |
+$query = $builder->build_query($source); |
|
150 |
+is($query->sql, 'a b = ? c { } { = ? } = ? d;', "$test : 1"); |
|
146 | 151 |
|
152 |
+$source = "abc;"; |
|
153 |
+$query = $builder->build_query($source); |
|
154 |
+is($query->sql, 'abc;', "$test : 2"); |
|
147 | 155 |
|
156 |
+$source = "{= a}"; |
|
157 |
+$query = $builder->build_query($source); |
|
158 |
+is($query->sql, 'a = ?;', "$test : 3"); |
|
159 |
+ |
|
160 |
+$source = "a {= b} }"; |
|
161 |
+eval{$builder->build_query($source)}; |
|
162 |
+like($@, qr/unexpected "}"/, "$test : error : 1"); |
|
163 |
+ |
|
164 |
+$source = "a {= {}"; |
|
165 |
+eval{$builder->build_query($source)}; |
|
166 |
+like($@, qr/unexpected "{"/, "$test : error : 2"); |
|
148 | 167 |
|