Skip to content

Commit 3d15ce4

Browse files
committed
Add test to check correctness of undefined case.
1 parent f6968ec commit 3d15ce4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tests/tests/src/pattern_match_json.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3+
import * as Primitive_option from "rescript/lib/es6/Primitive_option.js";
34

45
function decodeGroup(group) {
56
let id = group.id;
6-
if (id === null) {
7+
if (id == null) {
78
return [
89
"e",
910
"f"
@@ -38,8 +39,22 @@ function decodeNull(x) {
3839
}
3940
}
4041

42+
function decodeUndefined(x) {
43+
let match = x.field;
44+
if (match === undefined) {
45+
return "no";
46+
}
47+
let tmp = Primitive_option.valFromOption(match);
48+
if (tmp === undefined) {
49+
return "yes it's undefined";
50+
} else {
51+
return "no";
52+
}
53+
}
54+
4155
export {
4256
decodeGroup,
4357
decodeNull,
58+
decodeUndefined,
4459
}
4560
/* No side effect */

tests/tests/src/pattern_match_json.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
type rec t =
33
| Boolean(bool)
44
| @as(null) Null
5+
| @as(undefined) Undefined
56
| String(string)
67
| Number(float)
78
| Object(Dict.t<t>)
@@ -24,3 +25,9 @@ let decodeNull = x =>
2425
| dict{"field": Null} => "yes it's null"
2526
| _ => "no"
2627
}
28+
29+
let decodeUndefined = x =>
30+
switch x {
31+
| dict{"field": Undefined} => "yes it's undefined"
32+
| _ => "no"
33+
}

0 commit comments

Comments
 (0)