Map literals!

This commit is contained in:
Bob Nystrom
2015-01-24 23:21:50 -08:00
parent abe80e6d4b
commit e740a4c95a
12 changed files with 83 additions and 20 deletions

View File

@ -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

View File

@ -0,0 +1 @@
var map = {1: // expect error

View File

@ -0,0 +1,2 @@
var map = {1: 2,
// expect error

View File

@ -0,0 +1 @@
var map = {1 // expect error

View File

@ -0,0 +1,2 @@
var map = {1: 2
// expect error

View File

@ -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
}

View File

@ -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

View File

@ -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