-
Notifications
You must be signed in to change notification settings - Fork 317
/
XImportSectionResourceDescriptionStrategyTest.java
79 lines (70 loc) · 3.29 KB
/
XImportSectionResourceDescriptionStrategyTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
* Copyright (c) 2022 Sebastian Zarnekow 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.xbase.tests.resources;
import java.util.Arrays;
import java.util.List;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.testlanguages.tests.XImportSectionTestLangInjectorProvider;
import org.eclipse.xtext.xbase.testlanguages.xImportSectionTestLang.ImportSectionTestLanguageRoot;
import org.junit.Assert;
import org.junit.Test;
import com.google.inject.Inject;
@InjectWith(XImportSectionResourceDescriptionStrategyTest.XImportSectionTestLangInjectorProviderCustom.class)
public class XImportSectionResourceDescriptionStrategyTest extends AbstractXbaseImportedNamesTest {
@Inject
private ParseHelper<ImportSectionTestLanguageRoot> parseHelper;
@Inject
private ValidationTestHelper validationHelper;
// inheritance allows for bindClassLoaderToInstance to get the class loader of this bundle
public static class XImportSectionTestLangInjectorProviderCustom extends XImportSectionTestLangInjectorProvider {
}
@Override
protected XExpression expression(CharSequence string) throws Exception {
return super.expression("some token import java.lang.Object " + string);
}
/**
* The bogus expectation documents a shortcoming of the XImportSection scoping logic when combined with nested types.
*/
@Test
public void testImportedNamesFromImportSection() throws Exception {
ImportSectionTestLanguageRoot model = parseHelper.parse("some token import java.util.Map.Entry import an.unknown.Type.With.Nested.Type");
Resource resource = model.eResource();
List<String> expectedImportedNames = Arrays.asList(
// "an$unknown$type$with$nested$type",
// "an.unknown$type$with$nested$type",
// "an.unknown.type$with$nested$type",
// "an.unknown.type.with$nested$type",
// "an.unknown.type.with.nested$type",
"an.unknown.type.with.nested.type",
"java.lang.object",
"java.util.map",
"java.util.map$entry",
"java.util.map.entry",
"my.test." + resource.getURI().trimFileExtension().lastSegment().toLowerCase());
List<String> actualImportedNames = importedNames(resource);
Assert.assertEquals(expectedImportedNames, actualImportedNames);
}
@Override
protected XExpression expression(CharSequence string, boolean resolve) throws Exception {
ImportSectionTestLanguageRoot parse = parseHelper.parse(string);
if (resolve)
validationHelper.assertNoErrors(parse);
return parse.getExpression();
}
@Override
protected void addExpectatedImportedNames(Resource resource, List<String> expectation) {
super.addExpectatedImportedNames(resource, expectation);
expectation.add("my.test." + resource.getURI().trimFileExtension().lastSegment().toLowerCase());
expectation.add("my.test.testdata$stubs$stubbedlist");
}
}