Skip to content

Commit a19c90e

Browse files
committed
Add a test for nested canonical modules
1 parent f2fbcef commit a19c90e

File tree

4 files changed

+252
-0
lines changed

4 files changed

+252
-0
lines changed

test/xref2/canonical_nested.t/main.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
open Main__
2+
3+
module Container = Container
4+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(** @canonical Main.Container *)
2+
module Container = Main__Container
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Test : sig
2+
(** Nested canonical test *)
3+
4+
module A : sig
5+
(** @canonical Main.Container.Test.B *)
6+
7+
type t
8+
end
9+
10+
module B = A
11+
12+
type t = A.t
13+
end
14+
15+

test/xref2/canonical_nested.t/run.t

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
In this test, we have two nested canonical modules. An outer one that
2+
resembles the normal dune namespacing trick, and an inner one where we
3+
have declared a particular module alias to be the canonical module for
4+
another module:
5+
6+
$ cat main__Container.mli
7+
module Test : sig
8+
(** Nested canonical test *)
9+
10+
module A : sig
11+
(** @canonical Main.Container.Test.B *)
12+
13+
type t
14+
end
15+
16+
module B = A
17+
18+
type t = A.t
19+
end
20+
21+
22+
Here is the inner alias with the canonical tag in `module A` declaring
23+
`B` to be the canonical module, where `B` is an alias of `A`. The
24+
result of this is that:
25+
1. module `B` should be expanded
26+
2. type `t` should link to the definition of `t` in module `B` rather
27+
than in module `A`.
28+
29+
$ ocamlc -c -bin-annot main__Container.mli
30+
$ ocamlc -c -bin-annot main__.ml
31+
$ ocamlc -c -bin-annot main.ml
32+
$ odoc compile main__Container.cmti
33+
$ odoc compile -I . main__.cmt
34+
$ odoc compile -I . main.cmt
35+
36+
At this point none of the canonical references are resolved. They should be
37+
unresolved in the paths though:
38+
39+
$ odoc_print -r Test.B main__Container.odoc
40+
{
41+
"id": {
42+
"`Module": [
43+
{ "`Module": [ { "`Root": [ "None", "Main__Container" ] }, "Test" ] },
44+
"B"
45+
]
46+
},
47+
"doc": [],
48+
"type_": {
49+
"Alias": [
50+
{
51+
"`Resolved": {
52+
"`Canonical": [
53+
{
54+
"`Identifier": {
55+
"`Module": [
56+
{
57+
"`Module": [
58+
{ "`Root": [ "None", "Main__Container" ] },
59+
"Test"
60+
]
61+
},
62+
"A"
63+
]
64+
}
65+
},
66+
{
67+
"`Dot": [
68+
{
69+
"`Dot": [
70+
{ "`Dot": [ { "`Root": "Main" }, "Container" ] },
71+
"Test"
72+
]
73+
},
74+
"B"
75+
]
76+
}
77+
]
78+
}
79+
},
80+
"None"
81+
]
82+
},
83+
"canonical": "None",
84+
"hidden": "false"
85+
}
86+
87+
$ odoc_print -r Container main.odoc
88+
{
89+
"id": { "`Module": [ { "`Root": [ "None", "Main" ] }, "Container" ] },
90+
"doc": [],
91+
"type_": {
92+
"Alias": [
93+
{
94+
"`Resolved": {
95+
"`Canonical": [
96+
{
97+
"`Module": [
98+
{
99+
"`Hidden": {
100+
"`Identifier": { "`Root": [ "None", "Main__" ] }
101+
}
102+
},
103+
"Container"
104+
]
105+
},
106+
{ "`Dot": [ { "`Root": "Main" }, "Container" ] }
107+
]
108+
}
109+
},
110+
"None"
111+
]
112+
},
113+
"canonical": "None",
114+
"hidden": "false"
115+
}
116+
117+
$ odoc link -I . main.odoc
118+
119+
$ odoc_print -r Container.Test.B main.odocl
120+
{
121+
"id": {
122+
"`Module": [
123+
{
124+
"`Module": [
125+
{ "`Module": [ { "`Root": [ "None", "Main" ] }, "Container" ] },
126+
"Test"
127+
]
128+
},
129+
"B"
130+
]
131+
},
132+
"doc": [],
133+
"type_": {
134+
"Alias": [
135+
{
136+
"`Resolved": {
137+
"`Canonical": [
138+
{
139+
"`Identifier": {
140+
"`Module": [
141+
{
142+
"`Module": [
143+
{
144+
"`Module": [
145+
{ "`Root": [ "None", "Main" ] },
146+
"Container"
147+
]
148+
},
149+
"Test"
150+
]
151+
},
152+
"A"
153+
]
154+
}
155+
},
156+
{
157+
"`Resolved": {
158+
"`Identifier": {
159+
"`Module": [
160+
{
161+
"`Module": [
162+
{
163+
"`Module": [
164+
{ "`Root": [ "None", "Main" ] },
165+
"Container"
166+
]
167+
},
168+
"Test"
169+
]
170+
},
171+
"B"
172+
]
173+
}
174+
}
175+
}
176+
]
177+
}
178+
},
179+
{
180+
"Some": {
181+
"Signature": {
182+
"items": [
183+
{
184+
"Type": [
185+
"Ordinary",
186+
{
187+
"id": {
188+
"`Type": [
189+
{
190+
"`Module": [
191+
{
192+
"`Module": [
193+
{
194+
"`Module": [
195+
{ "`Root": [ "None", "Main" ] },
196+
"Container"
197+
]
198+
},
199+
"Test"
200+
]
201+
},
202+
"B"
203+
]
204+
},
205+
"t"
206+
]
207+
},
208+
"doc": [],
209+
"equation": {
210+
"params": [],
211+
"private_": "false",
212+
"manifest": "None",
213+
"constraints": []
214+
},
215+
"representation": "None"
216+
}
217+
]
218+
}
219+
],
220+
"compiled": "true",
221+
"doc": []
222+
}
223+
}
224+
}
225+
]
226+
},
227+
"canonical": "None",
228+
"hidden": "false"
229+
}
230+
231+

0 commit comments

Comments
 (0)