diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-07-01 11:46:12 -0700 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-07-01 11:46:12 -0700 |
commit | be02e47ab5eda6d6d314c39a4f414678d09b9b9e (patch) | |
tree | 24c8d9e7f134f550a7a880ba6607394f591c6eaa /vespajlib/src/test/java/com/yahoo/text | |
parent | f09324087979f141deed25eb8fc24616e64b67be (diff) |
Output intermediate graph with type info on error
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/text')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/text/ExpressionFormatterTest.java | 140 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/text/ParenthesisExpressionPrettyPrinterTest.java | 82 |
2 files changed, 140 insertions, 82 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/text/ExpressionFormatterTest.java b/vespajlib/src/test/java/com/yahoo/text/ExpressionFormatterTest.java new file mode 100644 index 00000000000..6dfb2e6fc8a --- /dev/null +++ b/vespajlib/src/test/java/com/yahoo/text/ExpressionFormatterTest.java @@ -0,0 +1,140 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.text; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author bratseth + */ +public class ExpressionFormatterTest { + + @Test + public void testBasic() { + String expected = + "foo(\n" + + " bar(\n" + + " baz(\n" + + " )\n" + + " )\n" + + ")\n"; + assertPrettyPrint(expected, "foo(bar(baz()))"); + } + + @Test + public void testArgument() { + String expected = + "foo(\n" + + " bar(\n" + + " baz(\n" + + " hello world\n" + + " )\n" + + " )\n" + + ")\n"; + assertPrettyPrint(expected, "foo(bar(baz(hello world)))"); + } + + @Test + public void testMultipleArguments() { + String expected = + "foo(\n" + + " bar(\n" + + " baz(\n" + + " hello world,\n" + + " 37\n" + + " )\n" + + " )\n" + + ")\n"; + assertPrettyPrint(expected, "foo(bar(baz(hello world,37)))"); + } + + @Test + public void testUnmatchedStart() { + String expected = + "foo(\n" + + " (\n" + + " bar(\n" + + " baz(\n" + + " )\n" + + " )\n" + + " )\n"; + assertPrettyPrint(expected, "foo((bar(baz()))"); + } + + @Test + public void testUnmatchedEnd() { + String expected = + "foo(\n" + + " bar(\n" + + " baz(\n" + + " )\n" + + " )\n" + + ")\n" + + ")\n"; + assertPrettyPrint(expected, "foo(bar(baz())))"); + } + + @Test + public void testNoParenthesis() { + String expected = + "foo bar baz"; + assertPrettyPrint(expected, "foo bar baz"); + } + + @Test + public void testEmpty() { + String expected = + ""; + assertPrettyPrint(expected, ""); + } + + @Test + public void test2ColumnMode() { + String expected = + "1: foo(\n" + + " bar(\n" + + " baz(\n" + + "2: hello world\n" + + " )\n" + + "t(o )\n" + + " )\n"; + ExpressionFormatter pp = ExpressionFormatter.inTwoColumnMode(3); + assertEquals(expected, pp.format("\t1:\tfoo(bar(baz(\t2:\thello world)\tt(o)@olong:\t))")); + } + + @Test + public void test2ColumnModeMultipleArguments() { + String expected = + "1: foo(\n" + + " bar(\n" + + " baz(\n" + + "2: hello world,\n" + + "3: 37\n" + + " )\n" + + "t(o )\n" + + " )\n"; + ExpressionFormatter pp = ExpressionFormatter.inTwoColumnMode(3); + assertEquals(expected, pp.format("\t1:\tfoo(bar(baz(\t2:\thello world,\t3:\t37)\tt(o)@olong:\t))")); + } + + @Test + public void test2ColumnModeMultipleArgumentsWithSpaces() { + String expected = + "1: foo(\n" + + " bar(\n" + + " baz(\n" + + "2: hello world,\n" + + "3: 37\n" + + " )\n" + + "t(o )\n" + + " )\n"; + ExpressionFormatter pp = ExpressionFormatter.inTwoColumnMode(3); + assertEquals(expected, pp.format("\t1:\tfoo(bar(baz(\t2:\thello world, \t3:\t37)\tt(o)@olong:\t))")); + } + + private void assertPrettyPrint(String expected, String expression) { + assertEquals(expected, ExpressionFormatter.on(expression)); + } + +} diff --git a/vespajlib/src/test/java/com/yahoo/text/ParenthesisExpressionPrettyPrinterTest.java b/vespajlib/src/test/java/com/yahoo/text/ParenthesisExpressionPrettyPrinterTest.java deleted file mode 100644 index 79bdc6a5318..00000000000 --- a/vespajlib/src/test/java/com/yahoo/text/ParenthesisExpressionPrettyPrinterTest.java +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.text; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class ParenthesisExpressionPrettyPrinterTest { - - @Test - public void testBasic() { - String expected = - "foo(\n" + - " bar(\n" + - " baz(\n" + - " )\n" + - " )\n" + - ")\n"; - assertPrettyPrint(expected, "foo(bar(baz()))"); - } - - @Test - public void testInnerContent() { - String expected = - "foo(\n" + - " bar(\n" + - " baz(\n" + - " hello world\n" + - " )\n" + - " )\n" + - ")\n"; - assertPrettyPrint(expected, "foo(bar(baz(hello world)))"); - } - @Test - public void testUnmatchedStart() { - String expected = - "foo(\n" + - " (\n" + - " bar(\n" + - " baz(\n" + - " )\n" + - " )\n" + - " )\n" + - " "; - assertPrettyPrint(expected, "foo((bar(baz()))"); - } - - @Test - public void testUnmatchedEnd() { - String expected = - "foo(\n" + - " bar(\n" + - " baz(\n" + - " )\n" + - " )\n" + - ")\n" + - ")\n"; - assertPrettyPrint(expected, "foo(bar(baz())))"); - } - - @Test - public void testNoParenthesis() { - String expected = - "foo bar baz"; - assertPrettyPrint(expected, "foo bar baz"); - } - - @Test - public void testEmpty() { - String expected = - ""; - assertPrettyPrint(expected, ""); - } - - private void assertPrettyPrint(String expected, String expression) { - assertEquals(expected, ParenthesisExpressionPrettyPrinter.prettyPrint(expression)); - } - -} |