blob: 66067be623392f32dcd647b460b2390a36531d8f (
plain) (
blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*******************************************************************************
* Copyright (c) 2005, 2007 committers of openArchitectureWare 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
*
* Contributors:
* committers of openArchitectureWare - initial API and implementation
*******************************************************************************/
package org.eclipse.xtend.check;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import junit.framework.TestCase;
import org.eclipse.internal.xtend.xtend.ast.ExtensionFile;
import org.eclipse.internal.xtend.xtend.parser.ParseFacade;
import org.eclipse.xtend.expression.AnalysationIssue;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.ExecutionContextImpl;
public class CheckAnalyzationTest extends TestCase {
private Set<AnalysationIssue> issues;
private ExecutionContext ec;
@Override
protected void setUp() throws Exception {
ec = new ExecutionContextImpl();
issues = new HashSet<AnalysationIssue>();
}
private ExtensionFile parse(final String expression) {
return ParseFacade.file(new StringReader(expression), null);
}
private void dumpIssues() {
for (final Iterator<AnalysationIssue> iter = issues.iterator(); iter.hasNext();) {
final AnalysationIssue element = iter.next();
System.out.println(element.getType().toString() + " - " + element.getMessage());
}
}
public final void testAnalyze() {
final ExtensionFile file = parse("// test \n"
+ "context String ERROR this+' not allowed!' : this.startsWith('test') ;\n" + "\n"
+ "context Integer ERROR ''+this+' not allowed!' : this > 5; \n" + "\n"
+ "context Object WARNING 'Objects of type '+this.metaType+' not allowed!' : "
+ "!(String.isInstance(this) || Integer.isInstance(this)); \n");
ec = ec.cloneWithResource(file);
file.analyze(ec, issues);
dumpIssues();
assertEquals(0, issues.size());
}
public final void testAnalyze1() {
final ExtensionFile file = parse("context String ERROR this+' not allowed!' : this.startsWith('test') ;\n" + "\n"
+ "context Integers ERROR ''+this+' not allowed!' : this > 5; \n" + "\n"
+ "context Object WARNING 'Objects of type '+this.metaType+' not allowed!' : "
+ "!(String.isInstance(this) || Integer.isInstance(this)); \n");
ec = ec.cloneWithResource(file);
file.analyze(ec, issues);
dumpIssues();
assertEquals(1, issues.size());
}
public final void testAnalyze2() {
final ExtensionFile file = parse("context String ERROR this+' not allowed!' : this.startsWith('test') ;\n" + "\n"
+ "context Integer ERROR ''+this.is+' not allowed!' : this > 5; \n" + "\n"
+ "context Object WARNING 'Objects of type '+this.metaType+' not allowed!' : "
+ "!(String.isInstance(this) || Integer.isInstance(this)); \n");
ec = ec.cloneWithResource(file);
file.analyze(ec, issues);
dumpIssues();
assertEquals(1, issues.size());
}
public final void testAnalyze3() {
final ExtensionFile file = parse("context String ERROR this+' not allowed!' : this.startsWith('test') ;\n" + "\n"
+ "context Integer ERROR ''+this.is+' not allowed!' : this > 5; \n" + "\n"
+ "context Object WARNING 'Objects of type '+this.metaType+' not allowed!' : "
+ "!(String.isInstance(this) || Integer.blablubb(this)); \n");
ec = ec.cloneWithResource(file);
file.analyze(ec, issues);
dumpIssues();
assertEquals(2, issues.size());
}
}
|