Skip to content

Commit 4dc6806

Browse files
committed
add inheritance preference test
1 parent ffdd3f1 commit 4dc6806

File tree

1 file changed

+110
-30
lines changed

1 file changed

+110
-30
lines changed

Sources/SymbolGraphLinkerTests/LinkResolution.swift

Lines changed: 110 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,26 @@ struct LinkResolution
2424
{
2525
var tables:SSGC.Linker.Tables = .init()
2626

27-
tables.packageLinks["ThisModule", .init(["A"], "b")].append(.init(
28-
phylum: .func(.instance),
29-
kinks: [],
27+
tables.packageLinks["ThisModule", .init(["A"], "b")].append(.init(traits: .init(
28+
autograph: nil,
29+
phylum: .func(.instance),
30+
kinks: [],
31+
hash: .init(hashing: "x")),
3032
decl: 0,
3133
heir: nil,
32-
hash: .init(hashing: "x"),
3334
documented: true,
34-
autograph: nil,
35+
inherited: false,
3536
id: "x"))
3637

37-
tables.packageLinks["ThisModule", .init(["A"], "c")].append(.init(
38-
phylum: .func(.instance),
39-
kinks: [],
38+
tables.packageLinks["ThisModule", .init(["A"], "c")].append(.init(traits: .init(
39+
autograph: nil,
40+
phylum: .func(.instance),
41+
kinks: [],
42+
hash: .init(hashing: "y")),
4043
decl: 1,
4144
heir: nil,
42-
hash: .init(hashing: "y"),
4345
documented: true,
44-
autograph: nil,
46+
inherited: false,
4547
id: "y"))
4648

4749
// Unscoped tests
@@ -87,24 +89,26 @@ struct LinkResolution
8789
{
8890
var tables:SSGC.Linker.Tables = .init()
8991

90-
tables.packageLinks["OtherModule", .init(["A"], "b")].append(.init(
91-
phylum: .func(.instance),
92-
kinks: [],
92+
tables.packageLinks["OtherModule", .init(["A"], "b")].append(.init(traits: .init(
93+
autograph: nil,
94+
phylum: .func(.instance),
95+
kinks: [],
96+
hash: .init(hashing: "x")),
9397
decl: 0,
9498
heir: nil,
95-
hash: .init(hashing: "x"),
9699
documented: true,
97-
autograph: nil,
100+
inherited: false,
98101
id: "x"))
99102

100-
tables.packageLinks["OtherModule", .init(["A"], "c")].append(.init(
101-
phylum: .func(.instance),
102-
kinks: [],
103+
tables.packageLinks["OtherModule", .init(["A"], "c")].append(.init(traits: .init(
104+
autograph: nil,
105+
phylum: .func(.instance),
106+
kinks: [],
107+
hash: .init(hashing: "y")),
103108
decl: 1,
104109
heir: nil,
105-
hash: .init(hashing: "y"),
106110
documented: true,
107-
autograph: nil,
111+
inherited: false,
108112
id: "y"))
109113

110114
// Without registering modules, these symbols should be invisible to the resolver.
@@ -215,14 +219,15 @@ struct LinkResolution
215219
].enumerated()
216220
{
217221
let id:Symbol.Decl = .init(.s, ascii: "\(i)")
218-
tables.packageLinks["ThisModule", .init(["A"], name)].append(.init(
219-
phylum: .func(.instance),
220-
kinks: [],
222+
tables.packageLinks["ThisModule", .init(["A"], name)].append(.init(traits: .init(
223+
autograph: .init(inputs: inputs, output: output),
224+
phylum: .func(.instance),
225+
kinks: [],
226+
hash: .init(hashing: "\(id)")),
221227
decl: Int32.init(i),
222228
heir: nil,
223-
hash: .init(hashing: "\(id)"),
224229
documented: true,
225-
autograph: .init(inputs: inputs, output: output),
230+
inherited: false,
226231
id: id))
227232
}
228233

@@ -277,14 +282,15 @@ struct LinkResolution
277282
].enumerated()
278283
{
279284
let id:Symbol.Decl = .init(.s, ascii: "\(i)")
280-
tables.packageLinks["ThisModule", .init(["A"], name)].append(.init(
281-
phylum: .func(.instance),
282-
kinks: kinks,
285+
tables.packageLinks["ThisModule", .init(["A"], name)].append(.init(traits: .init(
286+
autograph: .init(inputs: inputs, output: output),
287+
phylum: .func(.instance),
288+
kinks: kinks,
289+
hash: .init(hashing: "\(id)")),
283290
decl: Int32.init(i),
284291
heir: nil,
285-
hash: .init(hashing: "\(id)"),
286292
documented: true,
287-
autograph: .init(inputs: inputs, output: output),
293+
inherited: false,
288294
id: id))
289295
}
290296

@@ -327,4 +333,78 @@ struct LinkResolution
327333
])
328334
}
329335
}
336+
@Test
337+
static func Preference()
338+
{
339+
var tables:SSGC.Linker.Tables = .init()
340+
341+
for (i, (name, (documented, inherited), kinks)):
342+
(Int, (String, (Bool, Bool), Phylum.Decl.Kinks)) in [
343+
("f(_:)", (false, false), []),
344+
("f(_:)", (false, true), []),
345+
346+
("g(_:)", (true, false), []),
347+
("g(_:)", (false, false), []),
348+
349+
// We should always prefer a symbol that is not inherited, even if it lacks
350+
// documentation and the inherited symbol has it.
351+
("h(_:)", (true, true), []),
352+
("h(_:)", (false, true), []),
353+
("h(_:)", (false, false), []),
354+
355+
// Inherited symbols with documentation should never cause a conflict.
356+
("i(_:)", (true, true), []),
357+
("i(_:)", (false, true), []),
358+
("i(_:)", (false, false), []),
359+
("i(_:)", (true, false), []),
360+
361+
("w(_:)", (true, true), []),
362+
("w(_:)", (true, true), []),
363+
364+
("x(_:)", (true, false), []),
365+
("x(_:)", (true, false), []),
366+
367+
("y(_:)", (false, false), []),
368+
("y(_:)", (false, false), []),
369+
370+
("z(_:)", (false, true), []),
371+
("z(_:)", (false, true), []),
372+
].enumerated()
373+
{
374+
let id:Symbol.Decl = .init(.s, ascii: "\(i)")
375+
tables.packageLinks["ThisModule", .init(["A"], name)].append(.init(traits: .init(
376+
autograph: .init(inputs: ["Int"], output: []),
377+
phylum: .func(.instance),
378+
kinks: kinks,
379+
hash: .init(hashing: "\(id)")),
380+
decl: Int32.init(i),
381+
heir: nil,
382+
documented: documented,
383+
inherited: inherited,
384+
id: id))
385+
}
386+
387+
tables.resolving(with: .init(origin: nil,
388+
namespace: nil,
389+
context: .init(id: "ThisModule"),
390+
scope: ["A"]))
391+
{
392+
#expect(nil != $0.outline(reference: .lexical(ucf: Self._string("f(_:)"))))
393+
#expect(nil != $0.outline(reference: .lexical(ucf: Self._string("g(_:)"))))
394+
#expect(nil != $0.outline(reference: .lexical(ucf: Self._string("h(_:)"))))
395+
#expect(nil != $0.outline(reference: .lexical(ucf: Self._string("i(_:)"))))
396+
397+
#expect(nil == $0.outline(reference: .lexical(ucf: Self._string("w(_:)"))))
398+
#expect(nil == $0.outline(reference: .lexical(ucf: Self._string("x(_:)"))))
399+
#expect(nil == $0.outline(reference: .lexical(ucf: Self._string("y(_:)"))))
400+
#expect(nil == $0.outline(reference: .lexical(ucf: Self._string("z(_:)"))))
401+
402+
#expect($0.outlines() == [
403+
.vertex(0, text: "f(_:)"),
404+
.vertex(2, text: "g(_:)"),
405+
.vertex(6, text: "h(_:)"),
406+
.vertex(10, text: "i(_:)"),
407+
])
408+
}
409+
}
330410
}

0 commit comments

Comments
 (0)