|
@@ -50,412 +50,417 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
@Test
|
|
|
public void testUnarySuccess() {
|
|
|
// int
|
|
|
- assertTrue(analyzer.isInteger(inferType("1")));
|
|
|
- assertTrue(analyzer.isInteger(inferType("-1")));
|
|
|
- assertTrue(analyzer.isInteger(inferType("0")));
|
|
|
- assertTrue(analyzer.isInteger(inferType("myInt")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("1")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("-1")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("0")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("myInt")));
|
|
|
// real
|
|
|
- assertTrue(analyzer.isReal(inferType("1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("-1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("0.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("myReal")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("-1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("0.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("myReal")));
|
|
|
// string
|
|
|
- assertTrue(analyzer.isString(inferType("'42'")));
|
|
|
- assertTrue(analyzer.isString(inferType("myString")));
|
|
|
+ assertTrue(analyzer.isString(getType("'42'")));
|
|
|
+ assertTrue(analyzer.isString(getType("myString")));
|
|
|
// boolean
|
|
|
- assertTrue(analyzer.isBoolean(inferType("true")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("false")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("myBool")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("true")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("false")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("myBool")));
|
|
|
}
|
|
|
|
|
|
// Add
|
|
|
@Test
|
|
|
public void testAddSuccess() {
|
|
|
- assertTrue(analyzer.isInteger(inferType("1 + 2")));
|
|
|
- assertTrue(analyzer.isInteger(inferType("myInt + 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1.1 + 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("2 + 1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1 + 2 + 3.0")));
|
|
|
+ Statement statement = (Statement) super.parseExpression("1+2",
|
|
|
+ super.createDefaultScope(), Expression.class.getSimpleName());
|
|
|
+ analyzer.getType(statement);
|
|
|
+ assertTrue(analyzer.isInteger(analyzer.getType(statement)));
|
|
|
+
|
|
|
+ assertTrue(analyzer.isInteger(getType("1 + 2")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("myInt + 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1.1 + 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("2 + 1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1 + 2 + 3.0")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException1() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("true + 5");
|
|
|
+ getType("true + 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException2() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("false + 5");
|
|
|
+ getType("false + 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException3() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("5 + false");
|
|
|
+ getType("5 + false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException4() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("true + (3 * 5)");
|
|
|
+ getType("true + (3 * 5)");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException5() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("(3 * 5) + true");
|
|
|
+ getType("(3 * 5) + true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException6() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("3.0 + true");
|
|
|
+ getType("3.0 + true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException7() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("3.0 + 'string'");
|
|
|
+ getType("3.0 + 'string'");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAddException8() {
|
|
|
expectOperatorPlusException();
|
|
|
- inferType("myInt + 'string'");
|
|
|
+ getType("myInt + 'string'");
|
|
|
}
|
|
|
|
|
|
// substract
|
|
|
@Test
|
|
|
public void testSubstractSuccess() {
|
|
|
- assertTrue(analyzer.isInteger(inferType("1 - 2")));
|
|
|
- assertTrue(analyzer.isInteger(inferType("myInt - 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1.0 - 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("2 - 1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("myReal - 1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1 - 2 - 3.0")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("1 - 2")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("myInt - 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1.0 - 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("2 - 1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("myReal - 1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1 - 2 - 3.0")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException1() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("true - 5");
|
|
|
+ getType("true - 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException2() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("false - 5");
|
|
|
+ getType("false - 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException3() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("5 - false");
|
|
|
+ getType("5 - false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException4() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("true - (3 * 5)");
|
|
|
+ getType("true - (3 * 5)");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException5() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("(3 * 5) - true");
|
|
|
+ getType("(3 * 5) - true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException6() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("3.0 - true");
|
|
|
+ getType("3.0 - true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException7() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("3.0 - 'string'");
|
|
|
+ getType("3.0 - 'string'");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSubstractException8() {
|
|
|
expectOperatorSubstractException();
|
|
|
- inferType("myReal - 'string'");
|
|
|
+ getType("myReal - 'string'");
|
|
|
}
|
|
|
|
|
|
// multiply
|
|
|
@Test
|
|
|
public void testMultiplySuccess() {
|
|
|
- assertTrue(analyzer.isInteger(inferType("1 * 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("myInt * myReal")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1.0 * 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("2 * 1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1 * 2 * 3.0")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("1 * 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("myInt * myReal")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1.0 * 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("2 * 1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1 * 2 * 3.0")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException1() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("true * 5");
|
|
|
+ getType("true * 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException2() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("false * 5");
|
|
|
+ getType("false * 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException3() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("5 * false");
|
|
|
+ getType("5 * false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException4() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("true * (3 - 5)");
|
|
|
+ getType("true * (3 - 5)");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException5() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("(3 + 5) * true");
|
|
|
+ getType("(3 + 5) * true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException6() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("3.0 * true");
|
|
|
+ getType("3.0 * true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException7() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("3.0 * 'string'");
|
|
|
+ getType("3.0 * 'string'");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testMultiplyException8() {
|
|
|
expectOperatorMultiplyException();
|
|
|
- inferType("myReal * 'string'");
|
|
|
+ getType("myReal * 'string'");
|
|
|
}
|
|
|
|
|
|
// divide
|
|
|
@Test
|
|
|
public void testDivideSuccess() {
|
|
|
- assertTrue(analyzer.isInteger(inferType("1 / 2")));
|
|
|
- assertTrue(analyzer.isInteger(inferType("1 / myInt")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1.0 / 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("2 / 1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1 / 2 / 3.0")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("1 / 2")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("1 / myInt")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1.0 / 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("2 / 1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1 / 2 / 3.0")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException1() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("true / 5");
|
|
|
+ getType("true / 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException2() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("false / 5");
|
|
|
+ getType("false / 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException3() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("5 / false");
|
|
|
+ getType("5 / false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException4() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("true / (3 - 5)");
|
|
|
+ getType("true / (3 - 5)");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException5() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("(3 + 5) / true");
|
|
|
+ getType("(3 + 5) / true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException6() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("3.0 / true");
|
|
|
+ getType("3.0 / true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException7() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("3.0 / 'string'");
|
|
|
+ getType("3.0 / 'string'");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testDivideException8() {
|
|
|
expectOperatorDivideException();
|
|
|
- inferType("3.0 / myString");
|
|
|
+ getType("3.0 / myString");
|
|
|
}
|
|
|
|
|
|
// mod
|
|
|
@Test
|
|
|
public void testModSuccess() {
|
|
|
- assertTrue(analyzer.isInteger(inferType("1 % 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1.0 % 2")));
|
|
|
- assertTrue(analyzer.isReal(inferType("2 % 1.0")));
|
|
|
- assertTrue(analyzer.isReal(inferType("2 % myReal")));
|
|
|
- assertTrue(analyzer.isReal(inferType("1 % 2 % 3.0")));
|
|
|
+ assertTrue(analyzer.isInteger(getType("1 % 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1.0 % 2")));
|
|
|
+ assertTrue(analyzer.isReal(getType("2 % 1.0")));
|
|
|
+ assertTrue(analyzer.isReal(getType("2 % myReal")));
|
|
|
+ assertTrue(analyzer.isReal(getType("1 % 2 % 3.0")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException1() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("true % 5");
|
|
|
+ getType("true % 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException2() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("false % 5");
|
|
|
+ getType("false % 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException3() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("5 % false");
|
|
|
+ getType("5 % false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException4() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("true % (3 - 5)");
|
|
|
+ getType("true % (3 - 5)");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException5() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("(3 + 5) % true");
|
|
|
+ getType("(3 + 5) % true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException6() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("3.0 % true");
|
|
|
+ getType("3.0 % true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException7() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("3.0 % 'string'");
|
|
|
+ getType("3.0 % 'string'");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testModException8() {
|
|
|
expectOperatorModException();
|
|
|
- inferType("3.0 % myString");
|
|
|
+ getType("3.0 % myString");
|
|
|
}
|
|
|
|
|
|
// Logical And Or Not
|
|
|
@Test
|
|
|
public void testLogicalSuccess() {
|
|
|
- assertTrue(analyzer.isBoolean(inferType("true || false")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("true || myBool")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("true || false && true")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("true || false")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("true || myBool")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("true || false && true")));
|
|
|
assertTrue(analyzer
|
|
|
- .isBoolean(inferType("true || true &&( false || true)")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("!true")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("!myBool")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("!true && !false")));
|
|
|
+ .isBoolean(getType("true || true &&( false || true)")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("!true")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("!myBool")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("!true && !false")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException1() {
|
|
|
expectLogicalAndException();
|
|
|
- inferType("true && 5");
|
|
|
+ getType("true && 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException2() {
|
|
|
expectLogicalOrException();
|
|
|
- inferType("false || 5");
|
|
|
+ getType("false || 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException3() {
|
|
|
expectLogicalAndException();
|
|
|
- inferType("5 && false");
|
|
|
+ getType("5 && false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException4() {
|
|
|
expectLogicalAndException();
|
|
|
- inferType("true && (3 - 5)");
|
|
|
+ getType("true && (3 - 5)");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException5() {
|
|
|
expectLogicalOrException();
|
|
|
- inferType("(3 + 5) || true");
|
|
|
+ getType("(3 + 5) || true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException6() {
|
|
|
expectLogicalAndException();
|
|
|
- inferType("3.0 && true");
|
|
|
+ getType("3.0 && true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException7() {
|
|
|
expectLogicalNotException();
|
|
|
- inferType("!3");
|
|
|
+ getType("!3");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException8() {
|
|
|
expectLogicalNotException();
|
|
|
- inferType("!1.2");
|
|
|
+ getType("!1.2");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException9() {
|
|
|
expectLogicalNotException();
|
|
|
- inferType("!'Test'");
|
|
|
+ getType("!'Test'");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testLogicalException10() {
|
|
|
expectLogicalNotException();
|
|
|
- inferType("!myString");
|
|
|
+ getType("!myString");
|
|
|
}
|
|
|
|
|
|
// LogicalRelation
|
|
|
@Test
|
|
|
public void testLogicalRelationSuccess() {
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5 < 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 < 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 < myInt")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5 < 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 < 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 < myInt")));
|
|
|
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5 <= 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 <= 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 <= myInt")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5 <= 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 <= 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 <= myInt")));
|
|
|
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5 > 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 >= 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 >= myInt")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5 > 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 >= 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 >= myInt")));
|
|
|
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5 == 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("'string' == 'string'")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 == 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("true == myBool")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5 == 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("'string' == 'string'")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 == 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("true == myBool")));
|
|
|
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5 != 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("'string' != 'string'")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("5.0 != 3")));
|
|
|
- assertTrue(analyzer.isBoolean(inferType("true != myBool")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5 != 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("'string' != 'string'")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("5.0 != 3")));
|
|
|
+ assertTrue(analyzer.isBoolean(getType("true != myBool")));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -463,7 +468,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '<'");
|
|
|
- inferType("3.0 < true");
|
|
|
+ getType("3.0 < true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -471,7 +476,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands string and integer for operator '<'");
|
|
|
- inferType("'string' < 5");
|
|
|
+ getType("'string' < 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -479,7 +484,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '<'");
|
|
|
- inferType("1.0 < false");
|
|
|
+ getType("1.0 < false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -487,7 +492,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '<='");
|
|
|
- inferType("3.0 <= true");
|
|
|
+ getType("3.0 <= true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -495,7 +500,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands string and integer for operator '<='");
|
|
|
- inferType("'string' <= 5");
|
|
|
+ getType("'string' <= 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -503,7 +508,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '<='");
|
|
|
- inferType("1.0 <= false");
|
|
|
+ getType("1.0 <= false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -511,7 +516,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '>'");
|
|
|
- inferType("3.0 > true");
|
|
|
+ getType("3.0 > true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -519,7 +524,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands string and integer for operator '>'");
|
|
|
- inferType("'string' > 5");
|
|
|
+ getType("'string' > 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -527,7 +532,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '>'");
|
|
|
- inferType("1.0 > false");
|
|
|
+ getType("1.0 > false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -535,7 +540,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '>='");
|
|
|
- inferType("3.0 >= true");
|
|
|
+ getType("3.0 >= true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -543,7 +548,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands string and integer for operator '>='");
|
|
|
- inferType("'string' >= 5");
|
|
|
+ getType("'string' >= 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -551,7 +556,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '>='");
|
|
|
- inferType("1.0 >= false");
|
|
|
+ getType("1.0 >= false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -559,7 +564,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '=='");
|
|
|
- inferType("3.0 == true");
|
|
|
+ getType("3.0 == true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -567,7 +572,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands string and integer for operator '=='");
|
|
|
- inferType("'string' == 5");
|
|
|
+ getType("'string' == 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -575,7 +580,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '=='");
|
|
|
- inferType("1.0 == false");
|
|
|
+ getType("1.0 == false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -583,7 +588,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '!='");
|
|
|
- inferType("3.0 != true");
|
|
|
+ getType("3.0 != true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -591,7 +596,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands string and integer for operator '!='");
|
|
|
- inferType("'string' != 5");
|
|
|
+ getType("'string' != 5");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -599,15 +604,15 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Incompatible operands real and boolean for operator '!='");
|
|
|
- inferType("1.0 != false");
|
|
|
+ getType("1.0 != false");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testAssignmentSuccess() {
|
|
|
- inferType("myInt = 5 * 3");
|
|
|
- inferType("myBool = true || false");
|
|
|
- inferType("myString = 'string'");
|
|
|
- inferType("myReal = 2.0 - 7");
|
|
|
+ getType("myInt = 5 * 3");
|
|
|
+ getType("myBool = true || false");
|
|
|
+ getType("myString = 'string'");
|
|
|
+ getType("myReal = 2.0 - 7");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -615,7 +620,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Can not assign a value of type boolean to a variable of type integer");
|
|
|
- inferType("myInt = true");
|
|
|
+ getType("myInt = true");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -623,14 +628,14 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
exception.expect(TypeCheckException.class);
|
|
|
exception
|
|
|
.expectMessage("Can not assign a value of type boolean to a variable of type integer");
|
|
|
- inferType("myInt = myBool");
|
|
|
+ getType("myInt = myBool");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testComplexExpressionsSuccess() {
|
|
|
- analyzer.isBoolean(inferType("((((3 * myInt) + 5) % 2) > 97) || false"));
|
|
|
- analyzer.isBoolean(inferType("!true != myBool && (3 > (myReal * 5 + 3))"));
|
|
|
- analyzer.isInteger(inferType("3 * 3 + 7 / (3 * myInt % 8)"));
|
|
|
+ analyzer.isBoolean(getType("((((3 * myInt) + 5) % 2) > 97) || false"));
|
|
|
+ analyzer.isBoolean(getType("!true != myBool && (3 > (myReal * 5 + 3))"));
|
|
|
+ analyzer.isInteger(getType("3 * 3 + 7 / (3 * myInt % 8)"));
|
|
|
}
|
|
|
|
|
|
// TODO: BitwiseOrExpression, BitwiseAndExpression, BitwiseXOrExpression
|
|
@@ -642,19 +647,19 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
// int events
|
|
|
EObject statement = super.parseExpression("raise intEvent : 42",
|
|
|
context, EventRaisingExpression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
// bool events
|
|
|
statement = super.parseExpression("raise boolEvent : myBool", context,
|
|
|
EventRaisingExpression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
// real events
|
|
|
statement = super.parseExpression("raise realEvent : 2.0 - 3.0",
|
|
|
context, EventRaisingExpression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
// string events
|
|
|
statement = super.parseExpression("raise stringEvent : 'string'",
|
|
|
context, EventRaisingExpression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -663,30 +668,30 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
// int events
|
|
|
EObject statement = super.parseExpression("valueof(intEvent)", context,
|
|
|
EventValueReferenceExpression.class.getSimpleName());
|
|
|
- analyzer.isInteger(analyzer.inferType((Statement) statement));
|
|
|
+ analyzer.isInteger(analyzer.getType((Statement) statement));
|
|
|
// bool events
|
|
|
statement = super.parseExpression("valueof(boolEvent)", context,
|
|
|
EventValueReferenceExpression.class.getSimpleName());
|
|
|
- analyzer.isBoolean(analyzer.inferType((Statement) statement));
|
|
|
+ analyzer.isBoolean(analyzer.getType((Statement) statement));
|
|
|
// real events
|
|
|
statement = super.parseExpression("valueof(realEvent)", context,
|
|
|
EventValueReferenceExpression.class.getSimpleName());
|
|
|
- analyzer.isReal(analyzer.inferType((Statement) statement));
|
|
|
+ analyzer.isReal(analyzer.getType((Statement) statement));
|
|
|
// string events
|
|
|
statement = super.parseExpression("valueof(stringEvent)", context,
|
|
|
EventValueReferenceExpression.class.getSimpleName());
|
|
|
- analyzer.isString(analyzer.inferType((Statement) statement));
|
|
|
+ analyzer.isString(analyzer.getType((Statement) statement));
|
|
|
// void events
|
|
|
statement = super.parseExpression("valueof(voidEvent)", context,
|
|
|
EventValueReferenceExpression.class.getSimpleName());
|
|
|
- analyzer.isVoid(analyzer.inferType((Statement) statement));
|
|
|
+ analyzer.isVoid(analyzer.getType((Statement) statement));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testEventIsRaisedSuccess() {
|
|
|
EObject statement = super.parseExpression("myBool = abc",
|
|
|
createDefaultScope(), Expression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -697,7 +702,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
EObject statement = super.parseExpression("raise intEvent : true",
|
|
|
createValuedEventsScope(),
|
|
|
EventRaisingExpression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -708,7 +713,7 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
EObject statement = super.parseExpression("raise intEvent : myBool",
|
|
|
createValuedEventsScope(),
|
|
|
EventRaisingExpression.class.getSimpleName());
|
|
|
- analyzer.inferType((Statement) statement);
|
|
|
+ analyzer.getType((Statement) statement);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -761,11 +766,11 @@ public class StaticTypeAnalyzerTest extends AbstractSTextTest {
|
|
|
return createContextScope("internal: var myBool : boolean event intEvent : integer = 22 event boolEvent : boolean event realEvent : real event stringEvent : string event voidEvent : void");
|
|
|
}
|
|
|
|
|
|
- protected Type inferType(String expression) {
|
|
|
+ protected Type getType(String expression) {
|
|
|
EObject statement = super.parseExpression(expression,
|
|
|
super.createDefaultScope(), Expression.class.getSimpleName());
|
|
|
assertNotNull(statement);
|
|
|
- return analyzer.inferType((Statement) statement);
|
|
|
+ return analyzer.getType((Statement) statement);
|
|
|
}
|
|
|
|
|
|
}
|