Map
Background
Given a file named "pen.json" with:
{
"type": "library",
"dependencies": {}
}
Create an empty map
Given a file named "Foo.pen" with:
f = \() {string: number} {
{string: number}
}
When I successfully run pen build
Then the exit status should be 0.
Create a map with an entry
Given a file named "Foo.pen" with:
f = \() {string: number} {
{string: number "foo": 42}
}
When I successfully run pen build
Then the exit status should be 0.
Create a map with two elements
Given a file named "Foo.pen" with:
f = \() {string: number} {
{string: number "foo": 1, "bar": 2}
}
When I successfully run pen build
Then the exit status should be 0.
Get a value in a map
Given a file named "Foo.pen" with:
f = \(xs {string: number}) number {
if x = xs["foo"] {
x
} else {
0
}
}
When I successfully run pen build
Then the exit status should be 0.
Merge maps
Given a file named "Foo.pen" with:
f = \(xs {string: number}) {string: number} {
{string: number ...xs, ...xs}
}
When I successfully run pen build
Then the exit status should be 0.
Merge a map of different types
Given a file named "Foo.pen" with:
f = \(xs {string: number}) {string | none: number | none} {
{string | none: number | none ...xs}
}
When I successfully run pen build
Then the exit status should be 0.
Create a map of a union type key
Given a file named "Foo.pen" with:
f = \() {string|none:number} {
{string|none:number "foo": 1, none: 2}
}
When I successfully run pen build
Then the exit status should be 0.
Create a map of a union type value
Given a file named "Foo.pen" with:
f = \() {string: number | none} {
{string: number | none "foo": 42, "bar": none}
}
When I successfully run pen build
Then the exit status should be 0.
Iterate map keys
Given a file named "Foo.pen" with:
f = \(xs {string: number}) [string] {
keys(xs)
}
When I successfully run pen build
Then the exit status should be 0.
Iterate map values
Given a file named "Foo.pen" with:
f = \(xs {string: number}) [number] {
values(xs)
}
When I successfully run pen build
Then the exit status should be 0.
Get a size of a map
Given a file named "Foo.pen" with:
f = \(xs {string: number}) number {
size(xs)
}
When I run pen build
Then the exit status should be 0.
Delete an entry of a map
Given a file named "Foo.pen" with:
f = \(xs {string: number}) {string: number} {
delete(xs, "foo")
}
When I run pen build
Then the exit status should be 0.