aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/backends/python
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-03-31 11:43:46 +0100
committerMichael Williamson <mike@zwobble.org>2016-03-31 11:43:46 +0100
commit04c3c57ca6b0f7e2985425d07faa9a72bc1817fa (patch)
tree91435e78d9db38b04c4c578302d0ca704aeae797 /src/test/java/org/zwobble/couscous/tests/backends/python
parent66b9c8813b3a4d60420134ccff700b64d4668da3 (diff)
Move isA to ExtraMatchers.isInstance
Diffstat (limited to 'src/test/java/org/zwobble/couscous/tests/backends/python')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java37
1 files changed, 3 insertions, 34 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java
index bdbf47e..7557f92 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCodeGeneratorTests.java
@@ -15,6 +15,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.zwobble.couscous.ast.ArrayNode.array;
import static org.zwobble.couscous.ast.LiteralNode.literal;
+import static org.zwobble.couscous.tests.util.ExtraMatchers.isInstance;
import static org.zwobble.couscous.util.ExtraLists.list;
public class PythonCodeGeneratorTests {
@@ -28,48 +29,16 @@ public class PythonCodeGeneratorTests {
}
private <T> Matcher<PythonExpressionNode> isPythonLiteral(String value) {
- return isA(PythonStringLiteralNode.class, hasFeature(
+ return isInstance(PythonStringLiteralNode.class, hasFeature(
"value",
node -> node.getValue(),
equalTo(value)));
}
- private static <T, U> Matcher<T> isA(Class<U> type, Matcher<? super U> downcastMatcher) {
- return new DiagnosingMatcher<T>() {
- @Override
- protected boolean matches(Object item, Description mismatch) {
- if (null == item) {
- mismatch.appendText("null");
- return false;
- }
-
- if (!type.isInstance(item)) {
- mismatch.appendValue(item).appendText(" is a " + item.getClass().getName());
- return false;
- }
-
- if (!downcastMatcher.matches(item)) {
- downcastMatcher.describeMismatch(item, mismatch);
- return false;
- }
-
- return true;
- }
-
- @Override
- public void describeTo(Description description) {
- description
- .appendText(type.getSimpleName())
- .appendText(" with ");
- downcastMatcher.describeTo(description);
- }
- };
- }
-
private static Matcher<PythonExpressionNode> isPythonList(
List<Matcher<? super PythonExpressionNode>> expectedElements)
{
- return isA(PythonListNode.class, hasFeature(
+ return isInstance(PythonListNode.class, hasFeature(
"elements",
list -> list.getElements(),
contains(expectedElements)));