Conversion + cleanups in o.e.dltk.ruby.formatter.tests.
* Convert AllTests to JUnit 4 style suite.
* Formatting fixes.
* vararg usage.
* Single Charset constant in the activator instead of having it in
multiple places.
* Drop unneeded dep from manifest.
Change-Id: I4517b655ef008f3ec7877938f2dfaba8a1075003
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.dltk.ruby.formatter.tests/META-INF/MANIFEST.MF
index 0649255..0df3551 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/META-INF/MANIFEST.MF
@@ -11,7 +11,6 @@
org.eclipse.dltk.core;bundle-version="0.0.0",
org.eclipse.dltk.ui,
org.eclipse.dltk.ruby.formatter,
- org.eclipse.core.resources,
org.eclipse.ui,
org.eclipse.dltk.formatter,
org.eclipse.dltk.formatter.tests
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AbstractRubyFormatterTest.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AbstractRubyFormatterTest.java
index b79ebdf..356d781 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AbstractRubyFormatterTest.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AbstractRubyFormatterTest.java
@@ -22,7 +22,8 @@
@Override
protected IScriptFormatter createFormatter(
Map<String, Object> preferences) {
- return preferences != null ? new TestRubyFormatter(Util.LINE_SEPARATOR,
- preferences) : new TestRubyFormatter();
+ return preferences != null
+ ? new TestRubyFormatter(Util.LINE_SEPARATOR, preferences)
+ : new TestRubyFormatter();
}
}
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AllTests.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AllTests.java
index 6e54c9c..e70e46d 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AllTests.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 xored software, Inc.
+ * Copyright (c) 2008, 2016 xored software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,35 +11,15 @@
*******************************************************************************/
package org.eclipse.dltk.ruby.formatter.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ ParserTest.class, SimpleTests.class,
+ ClassesAndMethodsTest.class, ModulesTest.class, BlocksTest.class,
+ RDocTest.class, IfTest.class, BeginTest.class, DoTest.class,
+ CommentsTest.class, UnaryPlusTest.class, HereDocumentTest.class,
+ StringsTest.class, RegexpTest.class, RubyDoc1Test.class,
+ RubyDoc2Test.class, FormatRubyLibTest.class })
public class AllTests {
-
- static final String CHARSET = "ISO-8859-1";
-
- public static Test suite() {
- TestSuite suite = new TestSuite("org.eclipse.dltk.ruby.formatter.tests");
- // $JUnit-BEGIN$
- suite.addTestSuite(ParserTest.class);
- suite.addTestSuite(SimpleTests.class);
- suite.addTest(ClassesAndMethodsTest.suite());
- suite.addTest(ModulesTest.suite());
- suite.addTest(BlocksTest.suite());
- suite.addTest(RDocTest.suite());
- suite.addTest(IfTest.suite());
- suite.addTest(BeginTest.suite());
- suite.addTest(DoTest.suite());
- suite.addTest(CommentsTest.suite());
- suite.addTest(UnaryPlusTest.suite());
- suite.addTest(HereDocumentTest.suite());
- suite.addTest(StringsTest.suite());
- suite.addTest(RegexpTest.suite());
- suite.addTest(RubyDoc1Test.suite());
- suite.addTest(RubyDoc2Test.suite());
- suite.addTest(FormatRubyLibTest.suite());
- // $JUnit-END$
- return suite;
- }
-
}
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/CommentWrapTests.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/CommentWrapTests.java
index aebe86d..4f6126f 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/CommentWrapTests.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/CommentWrapTests.java
@@ -19,19 +19,18 @@
public class CommentWrapTests extends AbstractRubyFormatterTest {
public void testWrapping1() throws FormatterException {
- String input = joinLines(new String[] { "# 01234567890 01234567890",
- "def m1", "", "end" });
- String output = joinLines(new String[] { "# 01234567890",
- "# 01234567890", "def m1", "", "end" });
+ String input = joinLines("# 01234567890 01234567890", "def m1", "",
+ "end");
+ String output = joinLines("# 01234567890", "# 01234567890", "def m1",
+ "", "end");
assertEquals(output, format(input));
}
public void testWrapping2() throws FormatterException {
- String input = joinLines(new String[] { "# 01234567890 01234567890",
- "# 01234567890 01234567890", "def m1", "", "end" });
- String output = joinLines(new String[] { "# 01234567890",
- "# 01234567890", "# 01234567890", "# 01234567890", "def m1",
- "", "end" });
+ String input = joinLines("# 01234567890 01234567890",
+ "# 01234567890 01234567890", "def m1", "", "end");
+ String output = joinLines("# 01234567890", "# 01234567890",
+ "# 01234567890", "# 01234567890", "def m1", "", "end");
assertEquals(output, format(input));
}
@@ -39,8 +38,8 @@
protected Map<String, Object> getDefaultPreferences() {
Map<String, Object> preferences = TestRubyFormatter
.createTestingPreferences();
- preferences.put(RubyFormatterConstants.WRAP_COMMENTS, Boolean.TRUE
- .toString());
+ preferences.put(RubyFormatterConstants.WRAP_COMMENTS,
+ Boolean.TRUE.toString());
preferences.put(RubyFormatterConstants.WRAP_COMMENTS_LENGTH, "20");
return preferences;
}
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/FormatRubyLibTest.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/FormatRubyLibTest.java
index 2ff30e4..c553d39 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/FormatRubyLibTest.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/FormatRubyLibTest.java
@@ -42,8 +42,8 @@
if (path.isFile()) {
return new TestSuite(FormatRubyLibTest.class);
} else {
- final TestSuite suite = new TestSuite(FormatRubyLibTest.class
- .getName());
+ final TestSuite suite = new TestSuite(
+ FormatRubyLibTest.class.getName());
suite.addTest(new TestCase("testRubyLib-NOT-FOUND") {
@Override
@@ -56,8 +56,6 @@
}
}
- static final String CHARSET = "ISO-8859-1"; //$NON-NLS-1$
-
/**
* @param name
* @return
@@ -87,17 +85,18 @@
}
};
final char[] content = Util.getInputStreamAsCharArray(
- entryStream, (int) entry.getSize(), CHARSET);
+ entryStream, (int) entry.getSize(),
+ RubyFormatterTestsPlugin.CHARSET);
final String input = new String(content);
try {
- final TextEdit edit = f.format(input, 0,
- input.length(), 0);
+ final TextEdit edit = f.format(input, 0, input.length(),
+ 0);
assertNotNull(entry.getName(), edit);
final IDocument document = new Document(input);
edit.apply(document);
assertTrue(compareIgnoreBlanks(entry.getName(),
- new StringReader(input), new StringReader(
- document.get())));
+ new StringReader(input),
+ new StringReader(document.get())));
} catch (BadLocationException e) {
throw new RuntimeException(e);
} catch (FormatterSyntaxProblemException e) {
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/ParserTest.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/ParserTest.java
index fe42caa..dc09261 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/ParserTest.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/ParserTest.java
@@ -73,13 +73,15 @@
final List<HeredocNode> heredocNodes = selectHeredocNodes(result);
assertEquals(2, heredocNodes.size());
final HeredocNode doc1 = heredocNodes.get(0);
- assertTrue(substring(input, doc1.getEndMarkerPosition()).indexOf(id1) >= 0);
+ assertTrue(substring(input, doc1.getEndMarkerPosition())
+ .indexOf(id1) >= 0);
final String content1 = substring(input, doc1.getContentPosition());
assertTrue(content1.indexOf(id1) < 0);
assertTrue(content1.indexOf(hereDoc1[0]) >= 0);
assertTrue(content1.indexOf(hereDoc1[1]) >= 0);
final HeredocNode doc2 = heredocNodes.get(1);
- assertTrue(substring(input, doc2.getEndMarkerPosition()).indexOf(id2) >= 0);
+ assertTrue(substring(input, doc2.getEndMarkerPosition())
+ .indexOf(id2) >= 0);
final String content2 = substring(input, doc2.getContentPosition());
assertTrue(content2.indexOf(id2) < 0);
assertTrue(content2.indexOf(hereDoc2[0]) >= 0);
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/RubyFormatterTestsPlugin.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/RubyFormatterTestsPlugin.java
index bcd7512..82c5c2e 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/RubyFormatterTestsPlugin.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/RubyFormatterTestsPlugin.java
@@ -30,6 +30,8 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.dltk.ruby.formatter.tests"; //$NON-NLS-1$
+ static final String CHARSET = "ISO-8859-1";
+
// The shared instance
private static RubyFormatterTestsPlugin plugin;
@@ -89,7 +91,7 @@
@Override
public String getCharset() {
- return AllTests.CHARSET;
+ return CHARSET;
}
@Override
diff --git a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/SimpleTests.java b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/SimpleTests.java
index 4dcbe70..f4e84d5 100644
--- a/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/SimpleTests.java
+++ b/tests/org.eclipse.dltk.ruby.formatter.tests/src/org/eclipse/dltk/ruby/formatter/tests/SimpleTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 xored software, Inc.
+ * Copyright (c) 2008, 2016 xored software, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,42 +16,40 @@
public class SimpleTests extends AbstractRubyFormatterTest {
public void test1() throws FormatterException {
- String input = joinLines(new String[] { "class Hello",
- "\t" + "attr_accessor :var", "end" });
+ String input = joinLines("class Hello", "\t" + "attr_accessor :var",
+ "end");
String output = format(input);
assertEquals(input, output);
}
public void test2() throws FormatterException {
- String input = joinLines(new String[] { "class Hello",
- "attr_accessor :var1", "attr_accessor :var2",
- "attr_accessor :var3", "end" });
+ String input = joinLines("class Hello", "attr_accessor :var1",
+ "attr_accessor :var2", "attr_accessor :var3", "end");
String output = format(input);
- String expected = joinLines(new String[] { "class Hello",
- "\t" + "attr_accessor :var1", "\t" + "attr_accessor :var2",
- "\t" + "attr_accessor :var3", "end" });
+ String expected = joinLines("class Hello", "\t" + "attr_accessor :var1",
+ "\t" + "attr_accessor :var2", "\t" + "attr_accessor :var3",
+ "end");
assertEquals(expected, output);
}
public void test3() throws FormatterException {
final String hw = "attr_accessor :var";
final String tab2_hw = "\t\t\t\t" + hw;
- String input = joinLines(new String[] { "class Hello", tab2_hw,
- tab2_hw, tab2_hw, "end" });
+ String input = joinLines("class Hello", tab2_hw, tab2_hw, tab2_hw,
+ "end");
String output = format(input);
final String tab_hw = "\t" + hw;
- String expected = joinLines(new String[] { "class Hello", tab_hw,
- tab_hw, tab_hw, "end" });
+ String expected = joinLines("class Hello", tab_hw, tab_hw, tab_hw,
+ "end");
assertEquals(expected, output);
}
public void test4() throws FormatterException {
- String input = joinLines(new String[] { "class Hello", "def execute",
- "puts \"Hello, world\"", "end", "end" });
+ String input = joinLines("class Hello", "def execute",
+ "puts \"Hello, world\"", "end", "end");
String output = format(input);
- String expected = joinLines(new String[] { "class Hello",
- "\t" + "def execute", "\t\t" + "puts \"Hello, world\"",
- "\t" + "end", "end" });
+ String expected = joinLines("class Hello", "\t" + "def execute",
+ "\t\t" + "puts \"Hello, world\"", "\t" + "end", "end");
assertEquals(expected, output);
}