Commit ee60d316 authored by Adam Knapp's avatar Adam Knapp
Browse files

Advanced matching semantic check tests #413 #414 #415


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 638f3228
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Baranyi, Botond
*
******************************************************************************/
module TempDynamic_SE { //^In TTCN-3 module//
template integer t1 := @dynamic { return value mod 2 == 0; }
function f_not_a_template() return integer { //^In function definition//
return value mod 2; //^In return statement// //^In the left operand of operation//2 //Reference to value being matched is only allowed inside a dynamic template's statement block//
}
template integer t2 := @dynamic { } //^In template definition// //The dynamic template's statement block does not have a return statement//
template integer t3 := @dynamic { return; } //^In template definition// //^In return statement// //Missing return value. The dynamic template's statement block should return a boolean value//
template float t4 := @dynamic { return 1; } //^In template definition// //^In return statement// //boolean value was expected//
template integer t5 := @dynamic { return ?; } //^In template definition// //^In return statement// //A specific value without matching symbols was expected as return value//
template integer t6 := @dynamic { //^In template definition// //Control might leave the dynamic template's statement block without reaching a return statement//
if (value > 3) { return true; }
}
type component CT {
var integer v_cv;
}
const integer cg_c := 3;
function f_f() runs on CT {
var template integer vt := @dynamic {
if (value > cg_c) { return true; }
v_cv := value;
return false;
}
}
template (omit) integer t7 := @dynamic { return value mod 2 == 0; } //^In template definition// //^While checking template restriction// //Restriction on template definition does not allow usage of dynamic match//
template (value) integer t8 := @dynamic { return value mod 2 == 0; } //^In template definition// //^While checking template restriction// //Restriction on template definition does not allow usage of dynamic match//
template (present) integer t9 := @dynamic { return value mod 2 == 0; }
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Baranyi, Botond
*
******************************************************************************/
module TempImplication_SE { //^In TTCN-3 module//
// OK (the length restriction and ifpresent refer to the 2nd operand, not the resulting template)
template charstring t1 := ? length (1..4) ifpresent implies ? length (2..3) ifpresent;
// these are not allowed according to the BNF in the standard, but the compiler accepts them
// (the first length restriction/ifpresent pair refer to the 2nd operand, the second pair refer to the resulting template)
template charstring t2 := ? length (1..4) ifpresent implies ? length (2..3) ifpresent ifpresent;
template charstring t3 := ? length (1..4) ifpresent implies ? length (2..3) ifpresent length (3);
template charstring t4 := ? length (1..4) ifpresent implies ? length (2..3) ifpresent length (3) ifpresent;
// this is the standard's way of adding length restrictions and ifpresent to both the 2nd operand and the resulting template,
// but the compiler interprets the 2nd operand as a value list match with 1 element, which cannot have ifpresent
template charstring t5 := ? length (1..4) ifpresent implies (? length (2..3) ifpresent) length (3) ifpresent; //^In template definition// //^In list item// //`ifpresent' is not allowed here//
// same as t4, but more readable (also not allowed according to the BNF in the standard)
template charstring t6 := (? length (1..4) ifpresent implies ? length (2..3) ifpresent) length (3) ifpresent;
function f_f() {
// OK (the type identifier refers to the first operand, not the resulting template)
log(match(3, integer: (1..3) implies integer: 3));
// according to the BNF in the standard this should be allowed,
// but the parser cannot handle two type identifiers one after the other
//log(match(3, integer: integer: (1..3) implies integer: 3)); parser error
}
}
...@@ -311,7 +311,7 @@ public class OOP_Semantic_tests { ...@@ -311,7 +311,7 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Class functions cannot have a `system` clause", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Class functions cannot have a `system` clause", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Class functions cannot have an `mtc` clause", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Class functions cannot have an `mtc` clause", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 18; lineNum += 18;
markersToCheck.add(new MarkerToCheck("Invalid `value` reference", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Reference to `value` is not allowed here", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 11; lineNum += 11;
markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", lineNum, IMarker.SEVERITY_ERROR)); markersToCheck.add(new MarkerToCheck("Type mismatch: a value of type `charstring' was expected instead of `integer'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 9; lineNum += 9;
......
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.regressiontests.designer.statictests.Basic_tests.templates;
import java.util.ArrayList;
import org.eclipse.core.resources.IMarker;
import org.eclipse.titan.regressiontests.designer.Designer_plugin_tests;
import org.eclipse.titan.regressiontests.library.MarkerToCheck;
import org.junit.Test;
public class DynamicMatchTemplateTest {
//TempDynamic_SE_ttcn
@Test
public void TempImplication_SE_ttcn() throws Exception {
Designer_plugin_tests.checkSemanticMarkersOnFile(TempDynamic_SE_ttcn_initializer(), "src/Basic_tests/templates/TempDynamic_SE.ttcn");
}
private ArrayList<MarkerToCheck> TempDynamic_SE_ttcn_initializer() {
//TempDynamic_SE.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(8);
int lineNum = 17;
markersToCheck.add(new MarkerToCheck("Reference to `value` is not allowed here", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3;
markersToCheck.add(new MarkerToCheck("The dynamic template's statement block does not have a return statement", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Missing return value. The dynamic template's statement block should return a boolean value", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("boolean value was expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("A specific value without matching symbols was expected as return value", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Control might leave the dynamic template's statement block without reaching a return statement", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 18;
markersToCheck.add(new MarkerToCheck("Restriction 'value' or 'omit' on template does not allow usage of `dynamic match'", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Restriction 'value' or 'omit' on template does not allow usage of `dynamic match'", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.regressiontests.designer.statictests.Basic_tests.templates;
import java.util.ArrayList;
import org.eclipse.core.resources.IMarker;
import org.eclipse.titan.regressiontests.designer.Designer_plugin_tests;
import org.eclipse.titan.regressiontests.library.MarkerToCheck;
import org.junit.Test;
public class ImplicationMatchTemplateTest {
//TempImplication_SE_ttcn
@Test
public void TempImplication_SE_ttcn() throws Exception {
Designer_plugin_tests.checkSemanticMarkersOnFile(TempImplication_SE_ttcn_initializer(), "src/Basic_tests/templates/TempImplication_SE.ttcn");
}
private ArrayList<MarkerToCheck> TempImplication_SE_ttcn_initializer() {
//TempImplication_SE.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(1);
int lineNum = 25;
markersToCheck.add(new MarkerToCheck("`ifpresent' is not allowed here", lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
}
}
...@@ -12,6 +12,7 @@ import org.junit.runners.Suite; ...@@ -12,6 +12,7 @@ import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ AllFromTest.class, TemplateRestrictionTest.class }) @SuiteClasses({ AllFromTest.class, TemplateRestrictionTest.class,
ImplicationMatchTemplateTest.class, DynamicMatchTemplateTest.class })
public class TemplateTestSuite { public class TemplateTestSuite {
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment