From 938f6c2275081bd00a7e87822c991b8525f37715 Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Fri, 9 Apr 2021 11:22:25 +0200 Subject: [PATCH] [eclipse/xtext#1952] converting test code to java Signed-off-by: Christian Dietrich --- .../internal/CommentFormatterTest.java | 162 +++++++++++++ .../internal/CommentFormatterTest.xtend | 153 ------------ .../internal/CommentFormatterTest.java | 225 ------------------ 3 files changed, 162 insertions(+), 378 deletions(-) create mode 100644 org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java delete mode 100644 org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.xtend delete mode 100644 org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java diff --git a/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java b/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java new file mode 100644 index 0000000000..9a912a3b14 --- /dev/null +++ b/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java @@ -0,0 +1,162 @@ +/** + * Copyright (c) 2017, 2021 TypeFox GmbH (http://www.typefox.io) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.xtext.formatting2.internal; + +import org.eclipse.xtext.formatting2.IFormattableDocument; +import org.eclipse.xtext.formatting2.IHiddenRegionFormatter; +import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList; +import org.eclipse.xtext.formatting2.internal.tests.FormatterTestLanguageInjectorProvider; +import org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions; +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.inject.Inject; + +/** + * @author Moritz Eysholdt - Initial contribution and API + */ +@RunWith(XtextRunner.class) +@InjectWith(FormatterTestLanguageInjectorProvider.class) +public class CommentFormatterTest { + public static class CustomFormatter extends GenericFormatter { + @Override + public void format(IDList model, ITextRegionExtensions regionAccess, IFormattableDocument document) { + document.append(textRegionExtensions.regionFor(model).keyword("idlist"), (IHiddenRegionFormatter it) -> { + it.oneSpace(); + }); + } + } + + @Inject + private GenericFormatterTester genericFormatterTester; + + @Test + public void SL_inline() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = + "idlist //x\n" + + "a\n"; + it.setToBeFormatted(model); + String expectation = + "idlist //x\n" + + "a\n"; + it.setExpectation(expectation); + }); + } + + @Test + public void SL_multiline() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = + "idlist \n" + + "\n" + + "//x\n" + + "\n" + + "\n" + + "a\n"; + it.setToBeFormatted(model); + String expectation = + "idlist //x\n" + + "a\n"; + it.setExpectation(expectation); + }); + } + + @Test + public void MLSL_inline() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = "idlist /*x*/ a\n"; + it.setToBeFormatted(model); + String expectation = "idlist /*x*/ a\n"; + it.setExpectation(expectation); + }); + } + + @Test + public void MLSL_double_inline() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = "idlist /*x*//*y*/ a\n"; + it.setToBeFormatted(model); + String expectation = "idlist /*x*/ /*y*/ a\n"; + it.setExpectation(expectation); + }); + } + + @Test + public void MLSL_paragraph() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = + "idlist\n" + + "\n" + + "\n" + + "/*x*/\n" + + "\n" + + "\n" + + "a\n"; + it.setToBeFormatted(model); + String expectation = + "idlist /*x*/\n" + + "a\n"; + it.setExpectation(expectation); + }); + } + + @Test + public void MLML_inline() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = + "idlist /*\n" + + "x\n" + + "*/ a\n"; + it.setToBeFormatted(model); + String expectation = + "idlist\n" + + "/*\n" + + " * x\n" + + " */\n" + + "a\n"; + it.setExpectation(expectation); + }); + } + + @Test + public void MLML_paragraph() { + genericFormatterTester.assertFormatted((GenericFormatterTestRequest it) -> { + it.setFormatter(new CustomFormatter()); + String model = + "idlist\n" + + "\n" + + "\n" + + "/*\n" + + "x\n" + + "*/\n" + + "\n" + + "\n" + + "a\n"; + it.setToBeFormatted(model); + String expectation = + "idlist\n" + + "\n" + + "\n" + + "/*\n" + + " * x\n" + + " */\n" + + "a\n"; + it.setExpectation(expectation); + }); + } +} diff --git a/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.xtend b/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.xtend deleted file mode 100644 index 7bacb54085..0000000000 --- a/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.xtend +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ -package org.eclipse.xtext.formatting2.internal - -import com.google.inject.Inject -import org.eclipse.xtext.formatting2.IFormattableDocument -import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList -import org.eclipse.xtext.formatting2.internal.tests.FormatterTestLanguageInjectorProvider -import org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith - -/** - * @author Moritz Eysholdt - Initial contribution and API - */ -@RunWith(XtextRunner) -@InjectWith(FormatterTestLanguageInjectorProvider) -class CommentFormatterTest { - @Inject extension GenericFormatterTester - - static class CustomFormatter extends GenericFormatter { - override format(IDList model, ITextRegionExtensions regionAccess, extension IFormattableDocument document) { - model.regionFor.keyword("idlist").append[oneSpace] - } - } - - @Test def void SL_inline() { - assertFormatted[ - toBeFormatted = ''' - idlist //x - a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist //x - a - ''' - ] - } - - @Test def void SL_multiline() { - assertFormatted[ - toBeFormatted = ''' - idlist - - //x - - - a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist //x - a - ''' - ] - } - - @Test def void MLSL_inline() { - assertFormatted[ - toBeFormatted = ''' - idlist /*x*/ a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist /*x*/ a - ''' - ] - } - - @Test def void MLSL_double_inline() { - assertFormatted[ - toBeFormatted = ''' - idlist /*x*//*y*/ a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist /*x*/ /*y*/ a - ''' - ] - } - - @Test def void MLSL_paragraph() { - assertFormatted[ - toBeFormatted = ''' - idlist - - - /*x*/ - - - a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist /*x*/ - a - ''' - ] - } - - @Test def void MLML_inline() { - assertFormatted[ - toBeFormatted = ''' - idlist /* - x - */ a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist - /* - * x - */ - a - ''' - ] - } - - @Test def void MLML_paragraph() { - assertFormatted[ - toBeFormatted = ''' - idlist - - - /* - x - */ - - - a - ''' - formatter = new CustomFormatter() - expectation = ''' - idlist - - - /* - * x - */ - a - ''' - ] - } -} diff --git a/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java b/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java deleted file mode 100644 index a47ff7b565..0000000000 --- a/org.eclipse.xtext.tests/xtend-gen/org/eclipse/xtext/formatting2/internal/CommentFormatterTest.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * Copyright (c) 2017 TypeFox GmbH (http://www.typefox.io) and others. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.xtext.formatting2.internal; - -import com.google.inject.Inject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.formatting2.IFormattableDocument; -import org.eclipse.xtext.formatting2.IHiddenRegionFormatter; -import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList; -import org.eclipse.xtext.formatting2.internal.tests.FormatterTestLanguageInjectorProvider; -import org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions; -import org.eclipse.xtext.testing.InjectWith; -import org.eclipse.xtext.testing.XtextRunner; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * @author Moritz Eysholdt - Initial contribution and API - */ -@RunWith(XtextRunner.class) -@InjectWith(FormatterTestLanguageInjectorProvider.class) -@SuppressWarnings("all") -public class CommentFormatterTest { - public static class CustomFormatter extends GenericFormatter { - @Override - public void format(final IDList model, final ITextRegionExtensions regionAccess, @Extension final IFormattableDocument document) { - final Procedure1 _function = (IHiddenRegionFormatter it) -> { - it.oneSpace(); - }; - document.append(this.textRegionExtensions.regionFor(model).keyword("idlist"), _function); - } - } - - @Inject - @Extension - private GenericFormatterTester _genericFormatterTester; - - @Test - public void SL_inline() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist //x"); - _builder.newLine(); - _builder.append("a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist //x"); - _builder_1.newLine(); - _builder_1.append("a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } - - @Test - public void SL_multiline() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist "); - _builder.newLine(); - _builder.newLine(); - _builder.append("//x"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist //x"); - _builder_1.newLine(); - _builder_1.append("a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } - - @Test - public void MLSL_inline() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist /*x*/ a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist /*x*/ a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } - - @Test - public void MLSL_double_inline() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist /*x*//*y*/ a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist /*x*/ /*y*/ a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } - - @Test - public void MLSL_paragraph() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("/*x*/"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist /*x*/"); - _builder_1.newLine(); - _builder_1.append("a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } - - @Test - public void MLML_inline() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist /*"); - _builder.newLine(); - _builder.append("x"); - _builder.newLine(); - _builder.append("*/ a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist"); - _builder_1.newLine(); - _builder_1.append("/*"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("* x"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("*/"); - _builder_1.newLine(); - _builder_1.append("a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } - - @Test - public void MLML_paragraph() { - final Procedure1 _function = (GenericFormatterTestRequest it) -> { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("idlist"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("/*"); - _builder.newLine(); - _builder.append("x"); - _builder.newLine(); - _builder.append("*/"); - _builder.newLine(); - _builder.newLine(); - _builder.newLine(); - _builder.append("a"); - _builder.newLine(); - it.setToBeFormatted(_builder); - CommentFormatterTest.CustomFormatter _customFormatter = new CommentFormatterTest.CustomFormatter(); - it.setFormatter(_customFormatter); - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("idlist"); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.newLine(); - _builder_1.append("/*"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("* x"); - _builder_1.newLine(); - _builder_1.append(" "); - _builder_1.append("*/"); - _builder_1.newLine(); - _builder_1.append("a"); - _builder_1.newLine(); - it.setExpectation(_builder_1); - }; - this._genericFormatterTester.assertFormatted(_function); - } -}