@@ -5,10 +5,50 @@ import * as Primitive_object from "rescript/lib/es6/Primitive_object.js";
55
66let eq = Primitive_object . equal ;
77
8+ let someString = "hello" ;
9+
10+ let createdDict = {
11+ name : "hello" ,
12+ age : "what" ,
13+ more : "stuff" ,
14+ otherStr : someString
15+ } ;
16+
17+ let intDict = {
18+ one : 1 ,
19+ two : 2 ,
20+ three : 3
21+ } ;
22+
23+ function inferDictByPattern ( dict ) {
24+ if ( dict . one === 1 && dict . three === 3 && dict . four === 4 ) {
25+ dict [ "five" ] = 5 ;
26+ return ;
27+ }
28+ if ( dict . two !== 1 ) {
29+ console . log ( "not one" ) ;
30+ } else {
31+ console . log ( "two" ) ;
32+ }
33+ }
34+
35+ function constrainedAsDict ( dict ) {
36+ if ( dict . one !== 1 ) {
37+ console . log ( "not one" ) ;
38+ } else {
39+ console . log ( "one" ) ;
40+ }
41+ }
42+
43+ let PatternMatching = {
44+ inferDictByPattern : inferDictByPattern ,
45+ constrainedAsDict : constrainedAsDict
46+ } ;
47+
848Test . run ( [
949 [
1050 "Core_DictTests.res" ,
11- 3 ,
51+ 39 ,
1252 20 ,
1353 26
1454 ] ,
@@ -18,7 +58,7 @@ Test.run([
1858Test . run ( [
1959 [
2060 "Core_DictTests.res" ,
21- 5 ,
61+ 41 ,
2262 20 ,
2363 31
2464 ] ,
@@ -31,7 +71,7 @@ Test.run([
3171Test . run ( [
3272 [
3373 "Core_DictTests.res" ,
34- 8 ,
74+ 44 ,
3575 13 ,
3676 35
3777 ] ,
@@ -44,14 +84,81 @@ Test.run([
4484Test . run ( [
4585 [
4686 "Core_DictTests.res" ,
47- 14 ,
87+ 50 ,
4888 13 ,
4989 34
5090 ] ,
5191 "getUnsafe - missing"
5292] , ( { } ) [ "foo" ] , eq , undefined ) ;
5393
94+ let dict = {
95+ key1 : false ,
96+ key2 : undefined
97+ } ;
98+
99+ Test . run ( [
100+ [
101+ "Core_DictTests.res" ,
102+ 62 ,
103+ 22 ,
104+ 38
105+ ] ,
106+ "has - existing"
107+ ] , "key1" in dict , eq , true ) ;
108+
109+ Test . run ( [
110+ [
111+ "Core_DictTests.res" ,
112+ 63 ,
113+ 22 ,
114+ 43
115+ ] ,
116+ "has - existing None"
117+ ] , "key2" in dict , eq , true ) ;
118+
119+ Test . run ( [
120+ [
121+ "Core_DictTests.res" ,
122+ 64 ,
123+ 22 ,
124+ 37
125+ ] ,
126+ "has - missing"
127+ ] , "key3" in dict , eq , false ) ;
128+
129+ Test . run ( [
130+ [
131+ "Core_DictTests.res" ,
132+ 65 ,
133+ 22 ,
134+ 39
135+ ] ,
136+ "has - prototype"
137+ ] , "toString" in dict , eq , true ) ;
138+
139+ Test . run ( [
140+ [
141+ "Core_DictTests.res" ,
142+ 67 ,
143+ 15 ,
144+ 51
145+ ] ,
146+ "has - parantesis in generated code"
147+ ] , typeof ( "key1" in dict ) , eq , "boolean" ) ;
148+
149+ let Has = {
150+ dict : dict
151+ } ;
152+
153+ let three = 3 ;
154+
54155export {
55156 eq ,
157+ someString ,
158+ createdDict ,
159+ three ,
160+ intDict ,
161+ PatternMatching ,
162+ Has ,
56163}
57164/* Not a pure module */
0 commit comments