Skip to content

Commit bcea7dc

Browse files
committedJan 17, 2022
Allow param range merging with generic components
1 parent 237572c commit bcea7dc

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
 

‎lib/preprocess/GenericsContext.ts

+9
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ export class GenericsContext {
270270
if (rangeB.isA('ParameterRangeUnion')) {
271271
return this.mergeUnion(rangeB, rangeA, typeTypeValidator);
272272
}
273+
274+
// Check if the range refers to a component with a generic type
275+
// TODO: somehow pass the range's component and genericTypeInstances (like in ParameterPropertyHandlerRange)?
276+
if (rangeA.isA('ParameterRangeGenericComponent')) {
277+
return this.mergeRanges(rangeA.property.component, rangeB, typeTypeValidator);
278+
}
279+
if (rangeB.isA('ParameterRangeGenericComponent')) {
280+
return this.mergeRanges(rangeB.property.component, rangeA, typeTypeValidator);
281+
}
273282
}
274283

275284
protected mergeUnion(

‎test/unit/preprocess/GenericsContexts-test.ts

+52
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,58 @@ describe('GenericsContext', () => {
929929
typeTypeValidatorOnlyIdentical,
930930
)).toBeUndefined();
931931
});
932+
933+
it('should merge with left a generic component', () => {
934+
expect(
935+
genericsContext.mergeRanges(
936+
objectLoader.createCompactedResource({
937+
'@type': 'ParameterRangeGenericComponent',
938+
component: 'ex:TYPE1',
939+
}),
940+
objectLoader.createCompactedResource('ex:TYPE1'),
941+
typeTypeValidatorOnlyIdentical,
942+
)!.term,
943+
).toEqualRdfTerm(objectLoader.createCompactedResource('ex:TYPE1')!.term);
944+
});
945+
946+
it('should not merge with left a non-matching generic component', () => {
947+
expect(
948+
genericsContext.mergeRanges(
949+
objectLoader.createCompactedResource({
950+
'@type': 'ParameterRangeGenericComponent',
951+
component: 'ex:TYPE1',
952+
}),
953+
objectLoader.createCompactedResource('ex:TYPE2'),
954+
typeTypeValidatorOnlyIdentical,
955+
),
956+
).toBeUndefined();
957+
});
958+
959+
it('should merge with right a generic component', () => {
960+
expect(
961+
genericsContext.mergeRanges(
962+
objectLoader.createCompactedResource('ex:TYPE1'),
963+
objectLoader.createCompactedResource({
964+
'@type': 'ParameterRangeGenericComponent',
965+
component: 'ex:TYPE1',
966+
}),
967+
typeTypeValidatorOnlyIdentical,
968+
)!.term,
969+
).toEqualRdfTerm(objectLoader.createCompactedResource('ex:TYPE1')!.term);
970+
});
971+
972+
it('should not merge with right a non-matching generic component', () => {
973+
expect(
974+
genericsContext.mergeRanges(
975+
objectLoader.createCompactedResource('ex:TYPE2'),
976+
objectLoader.createCompactedResource({
977+
'@type': 'ParameterRangeGenericComponent',
978+
component: 'ex:TYPE1',
979+
}),
980+
typeTypeValidatorOnlyIdentical,
981+
),
982+
).toBeUndefined();
983+
});
932984
});
933985

934986
describe('isXsdSubType', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.