浏览代码

added type cast checks for type inferrer

Andreas Mülder 11 年之前
父节点
当前提交
ea941a41da

+ 19 - 0
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/TypeInferrerTest.java

@@ -746,6 +746,25 @@ public class TypeInferrerTest extends AbstractSTextTest {
 		assertTrue(isRealType(inferType("( 7.5 / 1.2 )")));
 		assertTrue(isStringType(inferType("( 'abc' )")));
 	}
+	
+	@Test
+	public void testTypeCastExpressionSuccess() {
+		assertTrue(isBooleanType(inferType("( true as boolean)")));
+		assertTrue(isIntegerType(inferType("( 7.5 as integer )")));
+		assertTrue(isRealType(inferType(" 7 as real ")));
+		assertTrue(isStringType(inferType("( 'abc' as string )")));
+	}
+	@Test
+	public void testTypeCastExpressionFailure() {
+		expectIssue(inferType("true as integer"),
+				"Cannot cast from boolean to integer.");
+		expectIssue(inferType("true as string"),
+				"Cannot cast from boolean to string.");
+		expectIssue(inferType("5 as string"),
+				"Cannot cast from integer to string.");
+		expectIssue(inferType("5.5 as string"),
+				"Cannot cast from real to string.");
+	}
 
 	@Test
 	public void testTernaryExpression() {