|
71 | 71 | public class CreatesTraitTest { |
72 | 72 | private static final ShapeId DUMMY_ID = ShapeId.from("ns.foo#foo"); |
73 | 73 | private final TraitFactory provider = TraitFactory.createServiceFactory(); |
| 74 | + private static final SourceLocation testLocation = new SourceLocation("test.smithy", 1, 2); |
74 | 75 |
|
75 | 76 | static Stream<Arguments> createTraitTests() { |
76 | 77 | return Stream.of( |
@@ -236,4 +237,44 @@ void createsTraitFromNode(ShapeId traitId, Node fromNode) { |
236 | 237 | assertEquals(SourceLocation.NONE, trait.getSourceLocation()); |
237 | 238 | assertEquals(trait, provider.createTrait(traitId, DUMMY_ID, trait.toNode()).orElseThrow(RuntimeException::new)); |
238 | 239 | } |
| 240 | + |
| 241 | + static Stream<Arguments> createSourceLocationTests() { |
| 242 | + return Stream.of( |
| 243 | + Arguments.of(NumberListTrait.ID, |
| 244 | + ArrayNode.builder() |
| 245 | + .withValue(Node.from(1)) |
| 246 | + .withValue(Node.from(2)) |
| 247 | + .withValue(Node.from(3)) |
| 248 | + .sourceLocation(testLocation) |
| 249 | + .build() |
| 250 | + .toNode()), |
| 251 | + Arguments.of(NumberSetTrait.ID, |
| 252 | + ArrayNode.builder() |
| 253 | + .withValue(Node.from(1)) |
| 254 | + .withValue(Node.from(2)) |
| 255 | + .withValue(Node.from(3)) |
| 256 | + .sourceLocation(testLocation) |
| 257 | + .build() |
| 258 | + .toNode()), |
| 259 | + Arguments.of(NestedMapTrait.ID, |
| 260 | + NestedMapTrait.builder() |
| 261 | + .putValues("1", MapUtils.of("1", MapUtils.of("2", "3"))) |
| 262 | + .sourceLocation(testLocation) |
| 263 | + .build() |
| 264 | + .toNode()), |
| 265 | + Arguments.of(StructWithListOfMapTrait.ID, |
| 266 | + StructWithListOfMapTrait.builder() |
| 267 | + .addItems(MapUtils.of("1", "2")) |
| 268 | + .addItems(MapUtils.of("3", "4")) |
| 269 | + .sourceLocation(testLocation) |
| 270 | + .build() |
| 271 | + .toNode())); |
| 272 | + } |
| 273 | + |
| 274 | + @ParameterizedTest |
| 275 | + @MethodSource("createSourceLocationTests") |
| 276 | + void sourceLocationTest(ShapeId traitId, Node fromNode) { |
| 277 | + Trait trait = provider.createTrait(traitId, DUMMY_ID, fromNode).orElseThrow(RuntimeException::new); |
| 278 | + assertEquals(testLocation, trait.getSourceLocation()); |
| 279 | + } |
239 | 280 | } |
0 commit comments