Skip to content

Commit

Permalink
Add expectShapeId for fully-qualified shape ID
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Aug 28, 2019
1 parent be9b444 commit 324891f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ public ShapeId expectShapeId(String namespace) {
}
}

/**
* Expects that the value of the string is a fully-qualified Shape ID.
*
* @return Returns the parsed Shape ID.
*/
public ShapeId expectShapeId() {
try {
return ShapeId.from(getValue());
} catch (ShapeIdSyntaxException e) {
throw new SourceException(e.getMessage(), this);
}
}

@Override
public boolean equals(Object other) {
return other instanceof StringNode && value.equals(((StringNode) other).getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.shapes.ShapeId;

public class StringNodeTest {

Expand Down Expand Up @@ -138,4 +139,12 @@ public void equalityAndHashCodeTest() {
public void convertsToStringNode() {
assertTrue(Node.from("foo").asStringNode().isPresent());
}

@Test
public void parsesShapeIds() {
ShapeId expected = ShapeId.from("foo.baz#Bar");

assertEquals(expected, Node.from("foo.baz#Bar").expectStringNode().expectShapeId());
assertEquals(expected, Node.from("foo.baz#Bar").expectStringNode().expectShapeId("notfoo"));
}
}

0 comments on commit 324891f

Please sign in to comment.