-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from nbuilding/value-access-tests
Add tests for the value access operator
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
[] | ||
[()] | ||
) |