Search in sources :

Example 31 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class FileAwareTestLanguageImportTest method testMoveToNewPackage.

@Test
public void testMoveToNewPackage() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content1 = "package pkg1\n" + "\n" + "element Foo {\n" + "}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/file1.fileawaretestlanguage", content1));
    String content2 = "package pkg1\n" + "\n" + "element Bar {\n" + "	ref Foo\n" + "}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/file2.fileawaretestlanguage", content2));
    ResourceSet rs = importTestHelper.createResourceSet(fs);
    PackageDeclaration model = importTestHelper.contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
    ChangeSerializer serializer = serializerProvider.get();
    serializer.addModification(model, (PackageDeclaration it) -> {
        it.setName("newpackage");
    });
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> changes = importTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package <8:4|newpackage>\n" + "\n" + "element Foo {\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "8 4 \"pkg1\" -> \"newpackage\"\n" + "-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package pkg1\n" + "\n" + "<14:0|import newpackage.Foo\n" + "\n" + ">element Bar {\n" + "	ref Foo\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "14 0 \"\" -> \"import newpackage...\"\n";
    importTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Example 32 with InMemoryURIHandler

use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.

the class FileAwareTestLanguageImportTest method testMoveIntoLocalPackage.

@Test
public void testMoveIntoLocalPackage() {
    InMemoryURIHandler fs = new InMemoryURIHandler();
    String content1 = "package other\n" + "\n" + "element Foo {\n" + "}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/file1.fileawaretestlanguage", content1));
    String content2 = "package pkg1\n" + "\n" + "import other.Foo\n" + "\n" + "element Bar {\n" + "	ref Foo\n" + "}\n";
    importTestHelper.operator_add(fs, Pair.of("inmemory:/file2.fileawaretestlanguage", content2));
    ResourceSet rs = importTestHelper.createResourceSet(fs);
    PackageDeclaration model = importTestHelper.contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
    ChangeSerializer serializer = serializerProvider.get();
    serializer.addModification(model, (PackageDeclaration it) -> {
        it.setName("pkg1");
    });
    Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
    Collection<IEmfResourceChange> changes = importTestHelper.endRecordChangesToTextDocuments(serializer);
    String expectation = "-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package <8:5|pkg1>\n" + "\n" + "element Foo {\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "8 5 \"other\" -> \"pkg1\"\n" + "-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package pkg1\n" + "\n" + "<14:18|>element Bar {\n" + "	ref Foo\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "14 18 \"import other.Foo\\n" + "\\n" + "\" -> \"\"\n";
    importTestHelper.operator_tripleEquals(changes, expectation);
}
Also used : ChangeSerializer(org.eclipse.xtext.ide.serializer.impl.ChangeSerializer) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) PackageDeclaration(org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange) Test(org.junit.Test)

Aggregations

InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)32 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)29 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)26 Test (org.junit.Test)26 Resource (org.eclipse.emf.ecore.resource.Resource)22 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)20 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)12 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)10 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)5 TwoChildLists (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.TwoChildLists)4 PackageDeclaration (org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration)4 EClass (org.eclipse.emf.ecore.EClass)3 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)2 EPackage (org.eclipse.emf.ecore.EPackage)1