From f3895598fe24e51cd19a3e205b0d89015308cf0b Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Sat, 1 Jun 2002 12:19:27 +0000 Subject: [PATCH] Watching Germany destroy a team in the 2002 world cup. Oh, also updating the code coverage of the tests. :-) --- .../tools/checkstyle/CheckerTest.java | 3 +- .../tools/checkstyle/ConfigurationTest.java | 45 +++++++++++++++++++ .../tools/checkstyle/MyCommonASTTest.java | 21 +++++++++ .../tools/checkstyle/UtilsTest.java | 5 +++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/ConfigurationTest.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/MyCommonASTTest.java diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 72c7332ed..17441f36f 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -46,7 +46,7 @@ public class CheckerTest mConfig.setRCurly(RightCurlyOption.ALONE); } - protected String getPath(String aFilename) + static String getPath(String aFilename) throws IOException { final File f = new File(System.getProperty("tests.dir"), aFilename); @@ -151,6 +151,7 @@ public class CheckerTest filepath + ":156:21: ':' is not followed by whitespace.", }; verify(c, filepath, expected); + c.destroy(); } public void testWhitespaceCastParenOff() diff --git a/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationTest.java b/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationTest.java new file mode 100644 index 000000000..0fe18151e --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/ConfigurationTest.java @@ -0,0 +1,45 @@ +package com.puppycrawl.tools.checkstyle; + +import junit.framework.TestCase; + +import java.util.Properties; + +public class ConfigurationTest + extends TestCase +{ + public ConfigurationTest(String name) + { + super(name); + } + + public void test1() throws Exception + { + final Properties p = new Properties(); + p.setProperty(Defn.HEADER_FILE_PROP, CheckerTest.getPath("java.header")); + p.setProperty(Defn.MAX_FILE_LENGTH_PROP, "a"); + p.setProperty(Defn.MAX_LINE_LENGTH_PROP, "66"); + p.setProperty(Defn.ALLOW_TABS_PROP, "true"); + p.setProperty(Defn.LCURLY_METHOD_PROP, "ignore"); + p.setProperty(Defn.LCURLY_OTHER_PROP, "claiea"); + p.setProperty(Defn.RCURLY_PROP, "ignore"); + p.setProperty(Defn.CATCH_BLOCK_PROP, "ignore"); + p.setProperty(Defn.PAREN_PAD_PROP, "ignore"); + final Configuration c = new Configuration(p, System.out); + assertNotNull(c); + assertEquals(66, c.getMaxLineLength()); + assertEquals(-1, c.getHeaderIgnoreLineNo()); + assertEquals(true, c.isAllowTabs()); + c.setHeaderIgnoreLineNo(666); + assertEquals(666, c.getHeaderIgnoreLineNo()); + } + + public void test2() throws Exception + { + final Properties p = new Properties(); + p.setProperty(Defn.RCURLY_PROP, "claira"); + p.setProperty(Defn.CATCH_BLOCK_PROP, "is great"); + p.setProperty(Defn.PAREN_PAD_PROP, "at sleeping"); + final Configuration c = new Configuration(p, System.out); + assertNotNull(c); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/MyCommonASTTest.java b/src/tests/com/puppycrawl/tools/checkstyle/MyCommonASTTest.java new file mode 100644 index 000000000..5aaeca470 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/MyCommonASTTest.java @@ -0,0 +1,21 @@ +package com.puppycrawl.tools.checkstyle; + +import junit.framework.TestCase; +import antlr.Token; + +public class MyCommonASTTest + extends TestCase +{ + public MyCommonASTTest(String name) + { + super(name); + } + + public void testMisc() + { + final MyCommonAST o = new MyCommonAST(); + assertNotNull(o); + o.initialize(new Token()); + assertEquals("{Text = '', Line = 0, Column = -1}", o.toString()); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/UtilsTest.java b/src/tests/com/puppycrawl/tools/checkstyle/UtilsTest.java index 51090b91d..03e189c68 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/UtilsTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/UtilsTest.java @@ -27,6 +27,11 @@ public class UtilsTest String s4 = " \t "; assertEquals(9, Utils.lengthExpandedTabs(s4, s4.length(), 8)); + + assertEquals(0, Utils.lengthMinusTrailingWhitespace("")); + assertEquals(0, Utils.lengthMinusTrailingWhitespace(" \t ")); + assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23")); + assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23 \t ")); } }