Skip to content

Commit c537a55

Browse files
authored
Add tests for printing jkinds (#169)
1 parent c9145f8 commit c537a55

File tree

1 file changed

+100
-0
lines changed
  • tests/test-dirs/type-enclosing

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Test that kinds get printed correctly.
2+
3+
$ type_enclosing () {
4+
> local filename=test.ml
5+
> cat > "$filename"
6+
> local pos="$1"
7+
>
8+
> local prev_output=""
9+
> local verbosity=0
10+
> while true; do
11+
> local current_output=$($MERLIN single type-enclosing -position "$pos" -verbosity "$verbosity" -filename "$filename" < "$filename" \
12+
> | revert-newlines | jq .value[0].type -r)
13+
>
14+
> # Check if current output matches previous output
15+
> if [ "$current_output" = "$prev_output" ]; then
16+
> break
17+
> else
18+
> echo "Verbosity $verbosity:"
19+
> echo "$current_output"
20+
> prev_output="$current_output"
21+
> verbosity=$((verbosity + 1))
22+
> fi
23+
> done
24+
> }
25+
26+
Abstract types
27+
$ type_enclosing 2:11 <<EOF
28+
> type t
29+
> type foo = t
30+
> EOF
31+
Verbosity 0:
32+
type t
33+
34+
$ type_enclosing 2:11 <<EOF
35+
> type t : immutable_data
36+
> type foo = t
37+
> EOF
38+
Verbosity 0:
39+
type t : immutable_data
40+
41+
Types with kinds (kinds, not jkinds)
42+
$ type_enclosing 2:11 <<EOF
43+
> type t = Foo of { mutable foo : int }
44+
> type foo = t
45+
> EOF
46+
Verbosity 0:
47+
type t = Foo of { mutable foo : int; }
48+
Verbosity 1:
49+
type t : mutable_data = Foo of { mutable foo : int; }
50+
51+
$ type_enclosing 3:17 <<EOF
52+
> type 'a t1 = { foo : 'a }
53+
> type 'a t2 = 'a t1 = { foo : 'a }
54+
> type foo = int t2
55+
> EOF
56+
Verbosity 0:
57+
type 'a t2 = 'a t1 = { foo : 'a; }
58+
Verbosity 1:
59+
type 'a t2 : immutable_data with 'a = 'a t1 = { foo : 'a; }
60+
61+
Non-Tconstr types
62+
$ type_enclosing 2:11 <<EOF
63+
> type t = int * string
64+
> type foo = t
65+
> EOF
66+
Verbosity 0:
67+
type t = int * string
68+
Verbosity 1:
69+
type t : immutable_data with int with string = int * string
70+
71+
$ type_enclosing 2:11 <<EOF
72+
> type t = [\`Foo | \`Bar of int]
73+
> type foo = t
74+
> EOF
75+
Verbosity 0:
76+
type t = [ `Bar of int | `Foo ]
77+
Verbosity 1:
78+
type t : value mod non_float = [ `Bar of int | `Foo ]
79+
80+
Module types
81+
# CR-someday: Make kinds get printed when verbosity is 1
82+
$ type_enclosing 8:11 <<EOF
83+
> module M = struct
84+
> type t_value
85+
> type t_immediate : immediate
86+
> type t_record = { foo : int }
87+
> type t_kind_and_manifest = t_record = { foo : int }
88+
> type t_tuple = int * string
89+
> end
90+
> module _ = M
91+
> EOF
92+
Verbosity 0:
93+
sig
94+
type t_value
95+
type t_immediate : immediate
96+
type t_record = { foo : int; }
97+
type t_kind_and_manifest = t_record = { foo : int; }
98+
type t_tuple = int * string
99+
end
100+

0 commit comments

Comments
 (0)