From 4d94b71ffe70e747082e4e8455df344fbddf6448 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 2 Dec 2016 14:33:57 +0100 Subject: [PATCH] pmd-ruby: checkstyle / formatting --- .../net/sourceforge/pmd/cpd/RubyLanguage.java | 1 + .../sourceforge/pmd/cpd/RubyTokenizer.java | 1 + .../pmd/lang/ruby/RubyLanguageModule.java | 1 + .../sourceforge/pmd/LanguageVersionTest.java | 7 +- .../pmd/cpd/RubyTokenizerTest.java | 64 +++++++------------ .../net/sourceforge/pmd/cpd/server.rb | 22 +++++++ 6 files changed, 51 insertions(+), 45 deletions(-) create mode 100644 pmd-ruby/src/test/resources/net/sourceforge/pmd/cpd/server.rb diff --git a/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyLanguage.java b/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyLanguage.java index b49bf554cf..a261e9c58c 100644 --- a/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyLanguage.java +++ b/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyLanguage.java @@ -1,6 +1,7 @@ /** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ + package net.sourceforge.pmd.cpd; /** diff --git a/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyTokenizer.java b/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyTokenizer.java index d069fed182..11f87a51a2 100644 --- a/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyTokenizer.java +++ b/pmd-ruby/src/main/java/net/sourceforge/pmd/cpd/RubyTokenizer.java @@ -1,6 +1,7 @@ /** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ + package net.sourceforge.pmd.cpd; import java.util.ArrayList; diff --git a/pmd-ruby/src/main/java/net/sourceforge/pmd/lang/ruby/RubyLanguageModule.java b/pmd-ruby/src/main/java/net/sourceforge/pmd/lang/ruby/RubyLanguageModule.java index e7501bffb6..48ff5f92a7 100644 --- a/pmd-ruby/src/main/java/net/sourceforge/pmd/lang/ruby/RubyLanguageModule.java +++ b/pmd-ruby/src/main/java/net/sourceforge/pmd/lang/ruby/RubyLanguageModule.java @@ -1,6 +1,7 @@ /** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ + package net.sourceforge.pmd.lang.ruby; import net.sourceforge.pmd.lang.BaseLanguageModule; diff --git a/pmd-ruby/src/test/java/net/sourceforge/pmd/LanguageVersionTest.java b/pmd-ruby/src/test/java/net/sourceforge/pmd/LanguageVersionTest.java index c2871902ee..fe133addd4 100644 --- a/pmd-ruby/src/test/java/net/sourceforge/pmd/LanguageVersionTest.java +++ b/pmd-ruby/src/test/java/net/sourceforge/pmd/LanguageVersionTest.java @@ -1,17 +1,18 @@ /** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ + package net.sourceforge.pmd; import java.util.Arrays; import java.util.Collection; +import org.junit.runners.Parameterized.Parameters; + import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ruby.RubyLanguageModule; -import org.junit.runners.Parameterized.Parameters; - public class LanguageVersionTest extends AbstractLanguageVersionTest { public LanguageVersionTest(String name, String terseName, String version, LanguageVersion expected) { @@ -21,6 +22,6 @@ public class LanguageVersionTest extends AbstractLanguageVersionTest { @Parameters public static Collection data() { return Arrays.asList(new Object[][] { { RubyLanguageModule.NAME, RubyLanguageModule.TERSE_NAME, "", - LanguageRegistry.getLanguage(RubyLanguageModule.NAME).getDefaultVersion() } }); + LanguageRegistry.getLanguage(RubyLanguageModule.NAME).getDefaultVersion(), }, }); } } diff --git a/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java b/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java index 826da5344a..decb493bf8 100644 --- a/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java +++ b/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java @@ -1,59 +1,39 @@ /** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ + package net.sourceforge.pmd.cpd; import java.io.IOException; +import java.nio.charset.StandardCharsets; -import net.sourceforge.pmd.PMD; -import net.sourceforge.pmd.testframework.AbstractTokenizerTest; - +import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; - +import net.sourceforge.pmd.testframework.AbstractTokenizerTest; public class RubyTokenizerTest extends AbstractTokenizerTest { - @Before - @Override - public void buildTokenizer() { - this.tokenizer = new RubyTokenizer(); - this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), "server.rb")); - } + @Before + @Override + public void buildTokenizer() { + this.tokenizer = new RubyTokenizer(); + this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), "server.rb")); + } - @Override - public String getSampleCode() { - return "require \"socket\"" + PMD.EOL + - "" + PMD.EOL + - "gs = TCPServer.open(0)" + PMD.EOL + - "addr = gs.addr" + PMD.EOL + - "addr.shift" + PMD.EOL + - "" + PMD.EOL + - "while true" + PMD.EOL + - " ns = gs.accept" + PMD.EOL + - " print(ns, \" is accepted\")" + PMD.EOL + - " Thread.start do" + PMD.EOL + - " s = ns # save to dynamic variable" + PMD.EOL + - " while s.gets" + PMD.EOL + - " s.write($_)" + PMD.EOL + - " end" + PMD.EOL + - " print(s, \" is " + PMD.EOL + - " gone" + PMD.EOL + - " and" + PMD.EOL + - " dead\")" + PMD.EOL + - " s.close" + PMD.EOL + - " end" + PMD.EOL + - "end" + PMD.EOL; - } + @Override + public String getSampleCode() { + try { + return IOUtils.toString(RubyTokenizerTest.class.getResourceAsStream("server.rb"), StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeException(e); + } + } - @Test - public void tokenizeTest() throws IOException { - this.expectedTokenCount = 30; - super.tokenizeTest(); - } - - public static junit.framework.Test suite() { - return new junit.framework.JUnit4TestAdapter(RubyTokenizerTest.class); + @Test + public void tokenizeTest() throws IOException { + this.expectedTokenCount = 30; + super.tokenizeTest(); } } diff --git a/pmd-ruby/src/test/resources/net/sourceforge/pmd/cpd/server.rb b/pmd-ruby/src/test/resources/net/sourceforge/pmd/cpd/server.rb new file mode 100644 index 0000000000..fcff68239c --- /dev/null +++ b/pmd-ruby/src/test/resources/net/sourceforge/pmd/cpd/server.rb @@ -0,0 +1,22 @@ +require "socket" + +gs = TCPServer.open(0) +addr = gs.addr +addr.shift + +while true + ns = gs.accept + print(ns, " is accepted") + Thread.start do + s = ns # save to dynamic variable + while s.gets + s.write($_) + end + print(s, " is + gone + and + dead") + s.close + end +end +