mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Map literals!
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
var map = new Map
|
||||
var map = {}
|
||||
IO.print(map.count) // expect: 0
|
||||
map["one"] = "value"
|
||||
IO.print(map.count) // expect: 1
|
||||
|
||||
1
test/map/eof_after_colon.wren
Normal file
1
test/map/eof_after_colon.wren
Normal file
@ -0,0 +1 @@
|
||||
var map = {1: // expect error
|
||||
2
test/map/eof_after_comma.wren
Normal file
2
test/map/eof_after_comma.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var map = {1: 2,
|
||||
// expect error
|
||||
1
test/map/eof_after_key.wren
Normal file
1
test/map/eof_after_key.wren
Normal file
@ -0,0 +1 @@
|
||||
var map = {1 // expect error
|
||||
2
test/map/eof_after_value.wren
Normal file
2
test/map/eof_after_value.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var map = {1: 2
|
||||
// expect error
|
||||
@ -58,7 +58,7 @@ var fishes = [
|
||||
"Cutlassfish", "Cutthroat eel", "Cutthroat trout"
|
||||
]
|
||||
|
||||
var map = new Map
|
||||
var map = {}
|
||||
for (fish in fishes) {
|
||||
map[fish] = fish.count
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
var map = new Map
|
||||
|
||||
map[null] = "null value"
|
||||
map[true] = "true value"
|
||||
map[false] = "false value"
|
||||
map[0] = "zero"
|
||||
map[1.2] = "1 point 2"
|
||||
map[List] = "list class"
|
||||
map["null"] = "string value"
|
||||
map[1..3] = "1 to 3"
|
||||
var map = {
|
||||
null: "null value",
|
||||
true: "true value",
|
||||
false: "false value",
|
||||
0: "zero",
|
||||
1.2: "1 point 2",
|
||||
List: "list class",
|
||||
"null": "string value",
|
||||
(1..3): "1 to 3"
|
||||
}
|
||||
|
||||
IO.print(map[null]) // expect: null value
|
||||
IO.print(map[true]) // expect: true value
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
// TODO: Use map literal.
|
||||
|
||||
IO.print(new Map is Map) // expect: true
|
||||
IO.print({} is Map) // expect: true
|
||||
// TODO: Abstract base class for associations.
|
||||
IO.print(new Map is Object) // expect: true
|
||||
IO.print(new Map is Bool) // expect: false
|
||||
IO.print((new Map).type == Map) // expect: true
|
||||
IO.print({} is Object) // expect: true
|
||||
IO.print({} is Bool) // expect: false
|
||||
IO.print({}.type == Map) // expect: true
|
||||
|
||||
Reference in New Issue
Block a user