Update dictionary.insert() doc and tests (#3343)
This commit is contained in:
parent
92aba81a91
commit
6a9866dc80
@ -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,
|
||||
|
@ -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.
|
||||
#{
|
||||
|
Loading…
x
Reference in New Issue
Block a user