From 30a373787116c3928cc19f34e66e2128afb12283 Mon Sep 17 00:00:00 2001 From: Moritz Eysholdt Date: Fri, 17 Apr 2015 09:54:07 +0200 Subject: [PATCH] [formatter/serializer] added integration test This particularly tests the changes introduced by 37ab5c4965c9920dd625dee77b4a6d5a64bf7638 Signed-off-by: Moritz Eysholdt --- .../FormatterSerializerIntegrationTest.xtend | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/FormatterSerializerIntegrationTest.xtend diff --git a/tests/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/FormatterSerializerIntegrationTest.xtend b/tests/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/FormatterSerializerIntegrationTest.xtend new file mode 100644 index 000000000..67bcba0e0 --- /dev/null +++ b/tests/org.eclipse.xtext.tests/src/org/eclipse/xtext/formatting2/internal/FormatterSerializerIntegrationTest.xtend @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.xtext.formatting2.internal + +import com.google.inject.Guice +import com.google.inject.Inject +import java.io.BufferedOutputStream +import java.io.ByteArrayOutputStream +import java.util.Collections +import org.eclipse.emf.common.util.URI +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl +import org.eclipse.xtext.formatting2.AbstractFormatter2 +import org.eclipse.xtext.formatting2.IFormattableDocument +import org.eclipse.xtext.formatting2.IFormatter2 +import org.eclipse.xtext.formatting2.internal.formattertestlanguage.FormattertestlanguageFactory +import org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList +import org.eclipse.xtext.junit4.InjectWith +import org.eclipse.xtext.junit4.XtextRunner +import org.eclipse.xtext.resource.IResourceFactory +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith + +/** + * @author Moritz Eysholdt - Initial contribution and API + */ +@RunWith(XtextRunner) +@InjectWith(InjectorProvider) +class FormatterSerializerIntegrationTest { + static class InjectorProvider extends FormatterTestLanguageInjectorProvider { + override protected internalCreateInjector() { + new Setup().createInjectorAndDoEMFRegistration() + } + } + + static class Setup extends FormatterTestLanguageStandaloneSetup { + override createInjector() { + return Guice.createInjector(new Module()); + } + } + + static class Module extends FormatterTestLanguageRuntimeModule { + def Class bindIFormatter2() { + return Formatter; + } + } + + static class Formatter extends AbstractFormatter2 { + def dispatch format(IDList model, extension IFormattableDocument document) { + model.regionForKeyword("idlist").append[space = " "] + } + } + + @Inject IResourceFactory factory; + + @Test def void testFormatterIntegrationWithSerializer() { + val resource = factory.createResource(URI.createURI("dummy.ext")) + new ResourceSetImpl().resources.add(resource) + val model = FormattertestlanguageFactory.eINSTANCE.createIDList + model.ids += "foo" + resource.contents += model + val out = new ByteArrayOutputStream + resource.save(new BufferedOutputStream(out), Collections.emptyMap) + Assert.assertEquals('idlist foo', out.toString) + } +} +