From 6a9866dc80fefd5cd32e1432c4e95d3a834c3886 Mon Sep 17 00:00:00 2001 From: Leedehai <18319900+Leedehai@users.noreply.github.com> Date: Mon, 5 Feb 2024 04:42:47 -0500 Subject: [PATCH] Update dictionary.insert() doc and tests (#3343) --- crates/typst/src/foundations/dict.rs | 4 ++-- tests/typ/compiler/dict.typ | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/typst/src/foundations/dict.rs b/crates/typst/src/foundations/dict.rs index da82889db..341504cb4 100644 --- a/crates/typst/src/foundations/dict.rs +++ b/crates/typst/src/foundations/dict.rs @@ -182,8 +182,8 @@ impl Dict { .ok_or_else(|| missing_key_no_default(&key)) } - /// Inserts a new pair into the dictionary and return the value. If the - /// dictionary already contains this key, the value is updated. + /// Inserts a new pair into the dictionary. If the dictionary already + /// contains this key, the value is updated. #[func] pub fn insert( &mut self, diff --git a/tests/typ/compiler/dict.typ b/tests/typ/compiler/dict.typ index cba2b6184..92cacdb39 100644 --- a/tests/typ/compiler/dict.typ +++ b/tests/typ/compiler/dict.typ @@ -40,6 +40,16 @@ #test((a: 1, b: 2).at("b", default: 3), 2) #test((a: 1, b: 2).at("c", default: 3), 3) +--- +// Test insert. +#{ + let dict = (a: 1, b: 2) + dict.insert("b", 3) + test(dict, (a: 1, b: 3)) + dict.insert("c", 5) + test(dict, (a: 1, b: 3, c: 5)) +} + --- // Test remove with default value. #{