diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-30 15:13:28 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-30 16:45:41 +0100 |
| commit | f70cea508cd30fa40770ea989fe2a19e715a357b (patch) | |
| tree | 731bb96b375dc8fd0f7e5a2a7e1d1fe5cb2a600e /tests/typ/compiler/dict.typ | |
| parent | fe1f4400693690b68db5a7ec0976ba998624a740 (diff) | |
Remove index syntax in favor of accessor methods
Diffstat (limited to 'tests/typ/compiler/dict.typ')
| -rw-r--r-- | tests/typ/compiler/dict.typ | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/typ/compiler/dict.typ b/tests/typ/compiler/dict.typ index d791f77b..0170cb8b 100644 --- a/tests/typ/compiler/dict.typ +++ b/tests/typ/compiler/dict.typ @@ -12,17 +12,17 @@ #dict #test(dict.normal, 1) -#test(dict("spacy key"), 2) +#test(dict.at("spacy key"), 2) --- // Test lvalue and rvalue access. { let dict = (a: 1, "b b": 1) - dict("b b") += 1 + dict.at("b b") += 1 dict.state = (ok: true, err: false) test(dict, (a: 1, "b b": 2, state: (ok: true, err: false))) test(dict.state.ok, true) - dict("state").ok = false + dict.at("state").ok = false test(dict.state.ok, false) test(dict.state.err, false) } @@ -31,19 +31,31 @@ // Test rvalue missing key. { let dict = (a: 1, b: 2) - // Error: 11-20 dictionary does not contain key "c" - let x = dict("c") + // Error: 11-23 dictionary does not contain key "c" + let x = dict.at("c") } --- // Missing lvalue is automatically none-initialized. { let dict = (:) - dict("b") += 1 + dict.at("b") += 1 test(dict, (b: 1)) } --- +// Test dictionary methods. +#let dict = (a: 3, c: 2, b: 1) +#test("c" in dict, true) +#test(dict.len(), 3) +#test(dict.values(), (3, 1, 2)) +#test(dict.pairs((k, v) => k + str(v)).join(), "a3b1c2") + +{ dict.remove("c") } +#test("c" in dict, false) +#test(dict, (a: 3, b: 1)) + +--- // Error: 24-32 pair has duplicate key {(first: 1, second: 2, first: 3)} @@ -65,7 +77,7 @@ --- // Error: 3-15 cannot mutate a temporary value -{ (key: value).other = "some" } +{ (key: "val").other = "some" } --- { |
