mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Add containsKey() to Map, and validate key types.
This commit is contained in:
11
test/map/contains_key.wren
Normal file
11
test/map/contains_key.wren
Normal file
@ -0,0 +1,11 @@
|
||||
var map = {
|
||||
"one": 1,
|
||||
"two": 2,
|
||||
"three": 3
|
||||
}
|
||||
|
||||
IO.print(map.containsKey("one")) // expect: true
|
||||
IO.print(map.containsKey("two")) // expect: true
|
||||
IO.print(map.containsKey("three")) // expect: true
|
||||
IO.print(map.containsKey("four")) // expect: false
|
||||
IO.print(map.containsKey("five")) // expect: false
|
||||
1
test/map/contains_key_not_value.wren
Normal file
1
test/map/contains_key_not_value.wren
Normal file
@ -0,0 +1 @@
|
||||
var result = {}.containsKey([]) // expect runtime error: Key must be a value type.
|
||||
1
test/map/subscript_key_not_value.wren
Normal file
1
test/map/subscript_key_not_value.wren
Normal file
@ -0,0 +1 @@
|
||||
var result = {}[[]] // expect runtime error: Key must be a value type.
|
||||
1
test/map/subscript_setter_key_not_value.wren
Normal file
1
test/map/subscript_setter_key_not_value.wren
Normal file
@ -0,0 +1 @@
|
||||
var result = {}[[]] = "value" // expect runtime error: Key must be a value type.
|
||||
Reference in New Issue
Block a user