| 435 | } |
| 436 | |
| 437 | static void test_set_statement(testing & t) { |
| 438 | test_template(t, "simple set", |
| 439 | "{% set x = 5 %}{{ x }}", |
| 440 | json::object(), |
| 441 | "5" |
| 442 | ); |
| 443 | |
| 444 | test_template(t, "set with expression", |
| 445 | "{% set x = a + b %}{{ x }}", |
| 446 | {{"a", 10}, {"b", 20}}, |
| 447 | "30" |
| 448 | ); |
| 449 | |
| 450 | test_template(t, "set list", |
| 451 | "{% set items = [1, 2, 3] %}{{ items|length }}", |
| 452 | json::object(), |
| 453 | "3" |
| 454 | ); |
| 455 | |
| 456 | test_template(t, "set dict", |
| 457 | "{% set d = {'a': 1} %}{{ d.a }}", |
| 458 | json::object(), |
| 459 | "1" |
| 460 | ); |
| 461 | |
| 462 | test_template(t, "set dict with mixed type keys", |
| 463 | "{% set d = {0: 1, none: 2, 1.0: 3, '0': 4, (0, 0): 5, false: 6, 1: 7} %}{{ d[(0, 0)] + d[0] + d[none] + d['0'] + d[false] + d[1.0] + d[1] }}", |
| 464 | json::object(), |
| 465 | "37" |
| 466 | ); |
| 467 | |
| 468 | test_template(t, "print dict with mixed type keys", |
| 469 | "{% set d = {0: 1, none: 2, 1.0: 3, '0': 4, (0, 0): 5, true: 6} %}{{ d|string }}", |
| 470 | json::object(), |
| 471 | "{0: 1, None: 2, 1.0: 6, '0': 4, (0, 0): 5}" |
| 472 | ); |
| 473 | |
| 474 | test_template(t, "print array with mixed types", |
| 475 | "{% set d = [0, none, 1.0, '0', true, (0, 0)] %}{{ d|string }}", |
| 476 | json::object(), |
| 477 | "[0, None, 1.0, '0', True, (0, 0)]" |
| 478 | ); |
| 479 | |
| 480 | test_template(t, "object member assignment with mixed key types", |
| 481 | "{% set d = namespace() %}{% set d.a = 123 %}{{ d['a'] == 123 }}", |
| 482 | json::object(), |
| 483 | "True" |
| 484 | ); |
| 485 | |
| 486 | test_template(t, "tuple unpacking", |
| 487 | "{% set t = (1, 2, 3) %}{% set a, b, c = t %}{{ a + b + c }}", |
| 488 | json::object(), |
| 489 | "6" |
| 490 | ); |
| 491 | } |
| 492 | |
| 493 | static void test_filters(testing & t) { |
| 494 | test_template(t, "upper", |
nothing calls this directly
no test coverage detected