Skip to content

Commit 7e0e754

Browse files
cristianoczth
authored andcommitted
Add test for the various aspects of first class dicts.
1 parent 39d4f3d commit 7e0e754

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

jscomp/test/FirstClassDicts.js

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/FirstClassDicts.res

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module CreateAndLookup = {
2+
type myDict = {name?: string, mutable anyOtherField?: int}
3+
4+
let test_create: myDict = {name: "hello", something: 5}
5+
6+
let test_lookup = (d: myDict) => d.something = Some(10)
7+
}
8+
9+
10+
module Update = {
11+
type myDict = {name?: string, mutable anyOtherField?: int}
12+
13+
let test_update = (d: myDict) => d.something = Some(10)
14+
}
15+
16+
17+
module PatternMatching = {
18+
type myDict = {name?: string, anyOtherField?: int}
19+
20+
let tst1 = (d: myDict) =>
21+
switch d {
22+
| {name: n, something: i} => String.length(n) + i
23+
| {name: n} => String.length(n)
24+
| {something: i} => i
25+
| _ => 0
26+
}
27+
28+
let tst2 = (d: myDict) =>
29+
switch d {
30+
| {name: _, a: i, b: j} => i + j
31+
| _ => 0
32+
}
33+
}

0 commit comments

Comments
 (0)