-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.re
142 lines (131 loc) · 3.74 KB
/
test.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
open Migrate_parsetree.Ast_403;
let module Convert = Migrate_parsetree.Convert(Migrate_parsetree.OCaml_403)(Migrate_parsetree.OCaml_current);
let show_structure structure => {
Pprintast.structure Format.str_formatter (Convert.copy_structure structure);
Format.flush_str_formatter();
};
let fixtures = [(/* (input, output) */
[%str [%%import One][@@from Three]],
[%str let module One = Three.One]
), (
[%str [%%import two][@@from Three]],
[%str let two = Three.two]
), (
[%str [%%import (One, two)][@@from Three]],
[%str
let module One = Three.One;
let two = Three.two;
]
), (
[%str [%%import (One child, Two (Child (grandchild1, grandchild2)))][@@from Three]],
[%str
let child = Three.One.child;
let grandchild1 = Three.Two.Child.grandchild1;
let grandchild2 = Three.Two.Child.grandchild2;
]
), (
[%str [%%import One.Two (five, Six.Seven ((), eight))][@@from Three.Four]],
[%str
let five = Three.Four.One.Two.five;
let module Seven = Three.Four.One.Two.Six.Seven;
let eight = Three.Four.One.Two.Six.Seven.eight;
]
), (
[%str
[%%import (One, two)][@@from Three];
let x = 10;
],
[%str
let module One = Three.One;
let two = Three.two;
let x = 10;
]
), (
[%str [%%import One.Two.three][@@from Source]],
[%str let three = Source.One.Two.three]
), (
[%str [%%import One.Two (three, Four.five)][@@from Source]],
[%str
let three = Source.One.Two.three;
let five = Source.One.Two.Four.five;
]
), (
[%str [%%import One (two, Three)][@@from Source]],
[%str
let two = Source.One.two;
let module Three = Source.One.Three;
]
), (
[%str [%%import One.Two.three][@@from Source]],
[%str let three = Source.One.Two.three]
), (
[%str [%%import One.Two.three][@@from Source]],
[%str let three = Source.One.Two.three]
), (
[%str let x = {
[%import One.Two.three][@from Source];
three
}],
[%str let x = {
let three = Source.One.Two.three;
three
}]
)];
/* Not implemented yet */
let todo = [(
[%str [%%import One [@as One']][@@from Three]],
[%str [%%import two [@as two']][@@from Three]],
[%str [%%import (One [@as One'], two [@as two'])][@@from Three]],
[%str [%import ExpressionLevel][@@from Somewhere]],
)];
let invalid = [
[%str [%%import bad + contents][@@from Somewhere]],
[%str [%%import 1][@@from Somewhere]],
[%str [%%import][@@from Somewhere]],
[%str [%%import thing][@@from bad + from]],
[%str [%%import noFrom]],
];
let run () => {
let (total, failures) = List.fold_left (fun (total, failures) (input, expected) => {
try {
let result = Lib.mapper.structure Lib.mapper input;
if (result != expected) {
print_endline ">> Input:";
print_endline (show_structure input);
print_endline ">> Output:";
print_endline (show_structure result);
print_endline ">> Expected:";
print_endline (show_structure expected);
(total + 1, failures + 1)
} else {
(total + 1, failures)
}
} {
| Location.Error error => {
print_endline ">> Input:";
print_endline (show_structure input);
print_endline ">> Error:";
print_endline error.Location.msg;
(total + 1, failures + 1)
}
}
}) (0, 0) fixtures;
let (total, failures) = List.fold_left (fun (total, failures) bad => {
try {
Lib.mapper.structure Lib.mapper bad |> ignore;
print_endline ">> Input was supposed to throw:";
print_endline (show_structure bad);
(total + 1, failures + 1) /* was supposed to raise */
} {
| _ => (total + 1, failures)
}
}) (total, failures) invalid;
if (failures !== 0) {
Printf.printf "Total: %d, Failures: %d" total failures;
exit 1;
} else {
Printf.printf "All %d succeeded!" total;
exit 0;
}
};
run ();