Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expectShapeId for fully-qualified shape ID #147

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}