From 04c3c57ca6b0f7e2985425d07faa9a72bc1817fa Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 31 Mar 2016 11:43:46 +0100 Subject: Move isA to ExtraMatchers.isInstance --- .../backends/python/PythonCodeGeneratorTests.java | 37 ++-------------------- 1 file changed, 3 insertions(+), 34 deletions(-) (limited to 'src/test/java/org/zwobble/couscous/tests/backends/python') 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 Matcher isPythonLiteral(String value) { - return isA(PythonStringLiteralNode.class, hasFeature( + return isInstance(PythonStringLiteralNode.class, hasFeature( "value", node -> node.getValue(), equalTo(value))); } - private static Matcher isA(Class type, Matcher downcastMatcher) { - return new DiagnosingMatcher() { - @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 isPythonList( List> expectedElements) { - return isA(PythonListNode.class, hasFeature( + return isInstance(PythonListNode.class, hasFeature( "elements", list -> list.getElements(), contains(expectedElements))); -- cgit v1.2.3