|
| 1 | +use "jik/testing" as test |
| 2 | +use "support/module_shapes" as shapes |
| 3 | + |
| 4 | + |
| 5 | +struct Settings: |
| 6 | + host: String |
| 7 | + port: int |
| 8 | + verbose: bool |
| 9 | +end |
| 10 | + |
| 11 | +struct Label: |
| 12 | + text: String |
| 13 | +end |
| 14 | + |
| 15 | +struct Holder: |
| 16 | + label: Label |
| 17 | +end |
| 18 | + |
| 19 | + |
| 20 | +func test_all_shorthand(ts): |
| 21 | + host := "localhost" |
| 22 | + port := 8080 |
| 23 | + verbose := true |
| 24 | + settings := Settings{host, port, verbose} |
| 25 | + |
| 26 | + test::suite_assert(ts, settings.host == "localhost", site()) |
| 27 | + test::suite_assert(ts, settings.port == 8080, site()) |
| 28 | + test::suite_assert(ts, settings.verbose, site()) |
| 29 | +end |
| 30 | + |
| 31 | +func test_mixed_and_omitted_fields(ts): |
| 32 | + port := 9000 |
| 33 | + verbose := true |
| 34 | + settings := Settings{port, host = "example.com", verbose} |
| 35 | + defaults := Settings{port} |
| 36 | + |
| 37 | + test::suite_assert(ts, settings.host == "example.com", site()) |
| 38 | + test::suite_assert(ts, settings.port == 9000, site()) |
| 39 | + test::suite_assert(ts, settings.verbose, site()) |
| 40 | + test::suite_assert(ts, defaults.host == "", site()) |
| 41 | + test::suite_assert(ts, defaults.port == 9000, site()) |
| 42 | +end |
| 43 | + |
| 44 | +func test_reordered_multiline_shorthand(ts): |
| 45 | + host := "reordered" |
| 46 | + port := 1234 |
| 47 | + verbose := false |
| 48 | + settings := Settings{ |
| 49 | + verbose, |
| 50 | + host, |
| 51 | + port |
| 52 | + } |
| 53 | + |
| 54 | + test::suite_assert(ts, settings.host == "reordered", site()) |
| 55 | + test::suite_assert(ts, settings.port == 1234, site()) |
| 56 | + test::suite_assert(ts, not settings.verbose, site()) |
| 57 | +end |
| 58 | + |
| 59 | +func test_imported_struct_and_composite_field(ts): |
| 60 | + name := "Ada" |
| 61 | + tags := ["compiler"] |
| 62 | + nickname := Some{"analyst"} |
| 63 | + person := shapes::Person{name, tags, nickname} |
| 64 | + |
| 65 | + text := "nested" |
| 66 | + label := Label{text} |
| 67 | + holder := Holder{label} |
| 68 | + |
| 69 | + test::suite_assert(ts, person.name == "Ada", site()) |
| 70 | + test::suite_assert(ts, person.tags[0] == "compiler", site()) |
| 71 | + test::suite_assert(ts, person.nickname? == "analyst", site()) |
| 72 | + test::suite_assert(ts, holder.label.text == "nested", site()) |
| 73 | +end |
| 74 | + |
| 75 | +func run_tests(ts): |
| 76 | + test_all_shorthand(ts) |
| 77 | + test_mixed_and_omitted_fields(ts) |
| 78 | + test_reordered_multiline_shorthand(ts) |
| 79 | + test_imported_struct_and_composite_field(ts) |
| 80 | +end |
0 commit comments