Skip to content

Commit

Permalink
Merge pull request #215 from nbuilding/value-access-tests
Browse files Browse the repository at this point in the history
Add tests for the value access operator
  • Loading branch information
Ashvin-Ranjan authored Jul 8, 2021
2 parents fe1457e + 73cf9c2 commit 03a7cf4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/assertions/value-access.n
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Lists

let first = ["un", "du", "trois"][0]
assert type first : maybe[str]
assert value first == yes("un")

let nested = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
assert type nested[-1][-1] : maybe[int]
assert value nested[-1][-1] == none
assert value nested[3][0] == none
assert value nested[0][3] == none
assert value nested[0][0] == yes(1)
assert value nested[0][2] == yes(3)

// Maps

let sheep = mapFrom([("baa", "sheep"), ("moo", "cow")])["baa"]
assert type sheep : maybe[str]
assert value sheep == yes("sheep")

let nestedMap = mapFrom([
(
"english",
mapFrom([
("sheep", "a fluffy, ruminant animal"),
("apple", "orangen't"),
]),
),
])
assert type nestedMap["english"]["apple"] : maybe[str]
assert value nestedMap["english"]["apple"] == "orangen't"

// Strings

assert type "wow"[0] : maybe[char]
assert value "wow"[0] == yes(\{w})
assert value "wow"[-1] == none

let strings = ["happy", "sheep", "goes", "boing"]
assert value strings[3][2] == yes(\{i})
30 changes: 30 additions & 0 deletions tests/syntax/value-access.n
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Simple syntax test for the value access operator

// The value access operator should be chainable like function calls and the
// record access and await operators.
let a = -b[if c { d } else { e }].f[[] -> () {}]![g |> h]()[i | j][[]]
let b = [][()]


let a = -(
(
(
(
(
(
(
(
(b)[(if c { d } else { e })]
).f
)[([] -> () {})]
)!
)[(g |> h)]
)()
)([i | j)]
)[([])]
)
let b = (
// Allow a newline between the value and value access operator
[]
[()]
)

0 comments on commit 03a7cf4

Please sign in to comment.