|
11 | 11 | import java.util.Map;
|
12 | 12 |
|
13 | 13 | import static java.lang.String.format;
|
| 14 | +import static junit.framework.TestCase.fail; |
14 | 15 | import static org.javalite.common.Collections.list;
|
15 | 16 | import static org.javalite.common.Collections.map;
|
16 | 17 | import static org.javalite.test.jspec.JSpec.a;
|
@@ -236,7 +237,7 @@ public void addHabits(String ... habitsAr) {
|
236 | 237 | }
|
237 | 238 |
|
238 | 239 | @Test
|
239 |
| - public void implementNestedTags() { |
| 240 | + public void shouldrenderNestedTags() { |
240 | 241 | String source = Util.readResource("/nested.html");
|
241 | 242 |
|
242 | 243 | Person4 jimmy = new Person4("Jimmy", "Henrdix");
|
@@ -273,27 +274,148 @@ public void shouldUseBuiltIn() {
|
273 | 274 |
|
274 | 275 | }
|
275 | 276 |
|
276 |
| - @Test @Ignore //TODO |
277 |
| - public void implement() { |
| 277 | + @Test |
| 278 | + public void shouldRejectWrongNumberOfArguments() { |
| 279 | + try{ |
| 280 | + new Template("<html><#if one two three four> tada </#if></html>"); |
| 281 | + }catch(Exception e){ |
| 282 | + a(e.getMessage()).shouldBeEqual("Incorrect number of arguments for <#if> tag. Either provide a single value or expression with two operands."); |
| 283 | + return; |
| 284 | + } |
| 285 | + fail(); |
| 286 | + } |
278 | 287 |
|
279 | 288 |
|
280 |
| - /* |
| 289 | + @Test |
| 290 | + public void shouldRejectWrongIncorrectOperator() { |
| 291 | + try{ |
| 292 | + new Template("<html><#if one bad_operator four> tada </#if></html>"); |
| 293 | + }catch(Exception e){ |
| 294 | + a(e.getMessage()).shouldBeEqual("Cannot parse operator for <#if> tag: bad_operator. The following operators supported: [lt, gt, gt=, lt=, ||, &&, ==, !=]"); |
| 295 | + return; |
| 296 | + } |
| 297 | + fail(); |
| 298 | + } |
281 | 299 |
|
282 |
| - Implement two operand conditions with operators: |
283 | 300 |
|
284 |
| - > //only for numeric types |
285 |
| - < |
286 |
| - >= |
287 |
| - <= |
288 |
| - || |
289 |
| - && |
290 |
| - eq - this is for .equals |
291 | 301 |
|
292 |
| - */ |
| 302 | + @Test |
| 303 | + public void shouldCompareNumbersWithLT() { |
| 304 | + |
| 305 | + String source = "<html><#if two lt three> tada </#if></html>"; |
| 306 | + Template template = new Template(source); |
| 307 | + StringWriter w = new StringWriter(); |
| 308 | + template.process(map("two", 2, "three", 3), w); |
| 309 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 310 | + |
| 311 | + source = "<html><#if three lt two> tada </#if></html>"; |
| 312 | + template = new Template(source); |
| 313 | + w = new StringWriter(); |
| 314 | + template.process(map("three", 3, "two", 2), w); |
| 315 | + a(w.toString()).shouldBeEqual("<html></html>"); |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + public void shouldCompareNumbersWithLTE() { |
293 | 320 |
|
| 321 | + String source = "<html><#if three lt= three> tada </#if></html>"; |
| 322 | + Template template = new Template(source); |
| 323 | + StringWriter w = new StringWriter(); |
| 324 | + template.process(map("three", 3, "three", 3), w); |
| 325 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 326 | + } |
| 327 | + |
| 328 | + @Test |
| 329 | + public void shouldCompareNumbersWithGTE() { |
| 330 | + |
| 331 | + String source = "<html><#if left gt= right> tada </#if></html>"; |
| 332 | + Template template = new Template(source); |
| 333 | + StringWriter w = new StringWriter(); |
| 334 | + template.process(map("left", 3, "right", 3), w); |
| 335 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 336 | + |
| 337 | + |
| 338 | + w = new StringWriter(); |
| 339 | + template.process(map("left", 1, "right", 3), w); |
| 340 | + a(w.toString()).shouldBeEqual("<html></html>"); |
| 341 | + } |
| 342 | + |
| 343 | + @Test |
| 344 | + public void shouldCompareNumbersWithGT() { |
| 345 | + |
| 346 | + String source = "<html><#if three gt two> tada </#if></html>"; |
| 347 | + Template template = new Template(source); |
| 348 | + StringWriter w = new StringWriter(); |
| 349 | + template.process(map("three", 3, "two", 2), w); |
| 350 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 351 | + |
| 352 | + source = "<html><#if two gt three> tada </#if></html>"; |
| 353 | + template = new Template(source); |
| 354 | + w = new StringWriter(); |
| 355 | + template.process(map("two", 2, "three", 3), w); |
| 356 | + a(w.toString()).shouldBeEqual("<html></html>"); |
294 | 357 | }
|
295 | 358 |
|
296 | 359 |
|
| 360 | + @Test |
| 361 | + public void shouldCompareObjectsWithEQ() { |
| 362 | + |
| 363 | + String source = "<html><#if word1 == word2> tada </#if></html>"; |
| 364 | + Template template = new Template(source); |
| 365 | + StringWriter w = new StringWriter(); |
| 366 | + template.process(map("word1", "help", "word2", "help"), w); |
| 367 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 368 | + |
| 369 | + w = new StringWriter(); |
| 370 | + template.process(map("word1", "help!", "word2", "help?"), w); |
| 371 | + a(w.toString()).shouldBeEqual("<html></html>"); |
| 372 | + } |
| 373 | + |
| 374 | + @Test |
| 375 | + public void shouldCompareObjectsWithNEQ() { |
| 376 | + |
| 377 | + String source = "<html><#if word1 != word2> tada </#if></html>"; |
| 378 | + Template template = new Template(source); |
| 379 | + StringWriter w = new StringWriter(); |
| 380 | + template.process(map("word1", "help!", "word2", "help?"), w); |
| 381 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 382 | + |
| 383 | + w = new StringWriter(); |
| 384 | + template.process(map("word1", "help", "word2", "help"), w); |
| 385 | + a(w.toString()).shouldBeEqual("<html></html>"); |
| 386 | + } |
| 387 | + |
| 388 | + |
| 389 | + @Test |
| 390 | + public void shouldCompareBooleansWithOR() { |
| 391 | + |
| 392 | + String source = "<html><#if cond1 || cond2> tada </#if></html>"; |
| 393 | + Template template = new Template(source); |
| 394 | + StringWriter w = new StringWriter(); |
| 395 | + template.process(map("cond1", true, "cond2", true), w); |
| 396 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 397 | + |
| 398 | + w = new StringWriter(); |
| 399 | + template.process(map("cond1", true, "cond2", false), w); |
| 400 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 401 | + } |
| 402 | + |
| 403 | + @Test |
| 404 | + public void shouldCompareBooleansWithAND() { |
| 405 | + |
| 406 | + String source = "<html><#if cond1 && cond2> tada </#if></html>"; |
| 407 | + Template template = new Template(source); |
| 408 | + StringWriter w = new StringWriter(); |
| 409 | + template.process(map("cond1", true, "cond2", true), w); |
| 410 | + a(w.toString()).shouldBeEqual("<html> tada </html>"); |
| 411 | + |
| 412 | + w = new StringWriter(); |
| 413 | + template.process(map("cond1", true, "cond2", false), w); |
| 414 | + a(w.toString()).shouldBeEqual("<html></html>"); |
| 415 | + } |
| 416 | + |
| 417 | + |
| 418 | + |
297 | 419 | @Test @Ignore //TODO
|
298 | 420 | public void implement1() {
|
299 | 421 | /*
|
|
0 commit comments