Skip to content

Commit

Permalink
Catch IntEnum removal cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Dec 13, 2023
1 parent 88238e5 commit dbab6d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ private boolean isMemberOfRemovedShape(Shape shape, Differences differences) {
}

private boolean isScalarType(Shape shape) {
return shape.isIntegerShape()
|| shape.isBigDecimalShape()
return shape.isBigDecimalShape()
|| shape.isBigIntegerShape()
|| shape.isBlobShape()
|| shape.isBooleanShape()
Expand All @@ -57,6 +56,7 @@ private boolean isScalarType(Shape shape) {
|| shape.isShortShape()
|| shape.isTimestampShape()
|| shape.isLongShape()
|| (shape.isStringShape() && !shape.hasTrait(EnumTrait.class));
|| (shape.isStringShape() && !shape.hasTrait(EnumTrait.class))
|| (shape.isIntegerShape() && !shape.isIntEnumShape());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import software.amazon.smithy.model.shapes.BooleanShape;
import software.amazon.smithy.model.shapes.ByteShape;
import software.amazon.smithy.model.shapes.DoubleShape;
import software.amazon.smithy.model.shapes.EnumShape;
import software.amazon.smithy.model.shapes.FloatShape;
import software.amazon.smithy.model.shapes.IntEnumShape;
import software.amazon.smithy.model.shapes.IntegerShape;
import software.amazon.smithy.model.shapes.ListShape;
import software.amazon.smithy.model.shapes.LongShape;
Expand Down Expand Up @@ -99,6 +101,21 @@ public void emitsErrorForEnumString() {
assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1));
}

@Test
public void emitsErrorForIntEnum() {
Shape shapeA1 = IntEnumShape.builder()
.id("foo.baz#Baz")
.addMember("FOO", 1)
.build();
Model modelA = Model.assembler().addShapes(shapeA1).assemble().unwrap();
Model modelB = Model.assembler().addShapes().assemble().unwrap();
List<ValidationEvent> events = ModelDiff.compare(modelA, modelB);

assertThat(TestHelper.findEvents(events, "RemovedShape").size(), equalTo(1));
assertThat(TestHelper.findEvents(events, shapeA1.getId()).size(), equalTo(1));
assertThat(TestHelper.findEvents(events, Severity.ERROR).size(), equalTo(1));
}

@Test
public void doesNotEmitForPrivateShapes() {
Shape shape = StringShape.builder().id("foo.baz#Baz").addTrait(new PrivateTrait()).build();
Expand Down

0 comments on commit dbab6d2

Please sign in to comment.