From 67847a1ebbcfc82e632a62ac6a9631c6bab4cad1 Mon Sep 17 00:00:00 2001 From: Reinhard Budde Date: Fri, 27 Sep 2024 14:07:06 +0200 Subject: [PATCH] Issue #1688: improvements of commit 55fb0372e12fcdff814cb9e24801a6d05596455e --- .../roberta/textly/generated/TextlyJava.g4 | 6 +- .../iais/roberta/typecheck/BlocklyType.java | 35 +- .../de/fhg/iais/roberta/typecheck/Sig.java | 82 ++- .../roberta/util/syntax/FunctionNames.java | 2 +- .../TypecheckCommonLanguageVisitor.java | 15 +- .../ReuseIntegrationAsUnitTest.java | 4 +- .../TestTypecheckUtilModifyXmlProgram.java | 92 --- .../TestTypecheck.java | 681 ++++++++---------- .../typecheck/TestTypecheckUtil.java | 74 ++ .../ev3c4ev3/textlyJava_expressions.ast | 2 +- .../ev3dev/textlyJava_expressions.ast | 2 +- .../ev3lejosv1/textlyJava_expressions.ast | 2 +- .../xNN/textlyJava_expressions.ast | 2 +- .../ev3c4ev3/textlyJava_expressions.cpp | 2 +- .../ev3dev/textlyJava_expressions.py | 2 +- .../ev3lejosv1/textlyJava_expressions.java | 2 +- .../xNN/textlyJava_expressions.java | 4 +- .../ev3/textlyJava_expressions.xml | 411 ++++++++++- .../textly/templateProgramExprEval.xml | 282 ++++++-- .../textly/templateProgramStmtExpr.xml | 2 +- .../microbitv2/textly/testTextRep.xml | 183 ----- .../microbitv2/textly/testTextlyExpr.xml | 55 -- .../microbitv2/textly/testTextlyStmt.xml | 237 ------ .../wedo/textly/templateProgramExprEval.xml | 2 +- .../wedo/textly/templateProgramStmtExpr.xml | 98 ++- .../wedo/textly/testTextlyStmt.xml | 1 - .../xNN/textlyJava_expressions.xml | 40 +- .../staticResources/xmlTest/index.html | 39 - .../staticResources/xmlTest/roberta_test.js | 137 ---- .../staticResources/xmlTest/test_1.xml | 34 - .../staticResources/xmlTest/test_3.xml | 92 --- .../staticResources/xmlTest/test_4.xml | 221 ------ .../staticResources/xmlTest/test_5.xml | 172 ----- .../staticResources/xmlTest/test_6.xml | 90 --- .../staticResources/xmlTest/test_7.xml | 64 -- .../staticResources/xmlTest/test_8.xml | 100 --- .../visitor/validate/Ev3TypecheckVisitor.java | 1 + .../validate/MicrobitV2TypecheckVisitor.java | 2 +- .../validate/WedoTypecheckVisitor.java | 1 + 39 files changed, 1220 insertions(+), 2053 deletions(-) delete mode 100644 OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheckUtilModifyXmlProgram.java rename OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/{integrationTest => typecheck}/TestTypecheck.java (64%) create mode 100644 OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheckUtil.java delete mode 100644 OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextRep.xml delete mode 100644 OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyExpr.xml delete mode 100644 OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyStmt.xml delete mode 100644 OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/testTextlyStmt.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/index.html delete mode 100644 OpenRobertaServer/staticResources/xmlTest/roberta_test.js delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_1.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_3.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_4.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_5.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_6.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_7.xml delete mode 100644 OpenRobertaServer/staticResources/xmlTest/test_8.xml diff --git a/OpenRobertaRobot/src/main/antlr4/de/fhg/iais/roberta/textly/generated/TextlyJava.g4 b/OpenRobertaRobot/src/main/antlr4/de/fhg/iais/roberta/textly/generated/TextlyJava.g4 index 0811717802..ada7a50cb8 100644 --- a/OpenRobertaRobot/src/main/antlr4/de/fhg/iais/roberta/textly/generated/TextlyJava.g4 +++ b/OpenRobertaRobot/src/main/antlr4/de/fhg/iais/roberta/textly/generated/TextlyJava.g4 @@ -98,7 +98,7 @@ microbitv2SensorExpr : ACCELEROMETER_SENSOR '(' NAME ')' | COMPASS_SENSOR '.' 'getAngle' '(' ')' | GESTURE_SENSOR '.' 'currentGesture' '(' NAME ')' | KEYS_SENSOR '.' 'isPressed' '(' NAME ')' - | LIGHT_SENSOR '.' 'getLevel' '('')' + | LIGHT_SENSOR '.' 'getLevel' '(' ')' | PIN_GET_VALUE_SENSOR '(' NAME ',' op = ('analog'|'digital'|'pulseHigh'|'pulseLow') ')' | PIN_TOUCH_SENSOR '.' 'isPressed' '(' INT ')' | SOUND_SENSOR '.' 'microphone' '.' 'soundLevel' '(' ')' @@ -159,8 +159,8 @@ robotEv3Expr : 'ev3' '.' ev3SensorExpr # Rob ev3SensorExpr : GETSPEEDMOTOR '(' NAME ')' | GETVOLUME '(' ')' | TOUCH_SENSOR '.' 'isPressed' '(' INT ')' - | ULTRASONIC_SENSOR '.' 'getDistance''(' INT ')' - | ULTRASONIC_SENSOR '.''getPresence''(' INT ')' + | ULTRASONIC_SENSOR '.' 'getDistance' '(' INT ')' + | ULTRASONIC_SENSOR '.' 'getPresence' '(' INT ')' | COLOR_SENSOR '(' NAME ',' INT ')' | INFRARED_SENSOR '.' 'getDistance' '(' INT ')' | INFRARED_SENSOR '.' 'getPresence' '(' INT ')' diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/BlocklyType.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/BlocklyType.java index 8e62b80b6a..fa0b397bdd 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/BlocklyType.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/BlocklyType.java @@ -13,16 +13,20 @@ * ANY * I * +---------+--------+-------+ - * I I I I - * STRING COLOR NUMERIC BOOL - * I I I I - * +---------+ I I - * I I I - * NULL +-------+ - * I I - * REF PRIM - * I I - * +--------+-------+ + * I I I + * I I PRIM + * I I I + * I I +-------+-------+ + * I I I I I + * STRING COLOR NUMERIC BOOL STRING + * I I I I I + * +---------+ I I I + * I I I I + * NULL I I I + * I I I I + * REF I I I + * I I I I + * +--------+-------+-------+ * I * NOTHING * @@ -47,11 +51,12 @@ public enum BlocklyType { ANY(""), COMPARABLE("",ANY), ADDABLE("",ANY), + PRIM("", ANY), - BOOLEAN("Boolean",COMPARABLE), - NUMBER("Number",COMPARABLE, ADDABLE), + BOOLEAN("Boolean",COMPARABLE, PRIM), + NUMBER("Number",COMPARABLE, ADDABLE, PRIM), NUMBER_INT("Number", COMPARABLE, ADDABLE), - STRING("String",COMPARABLE, ADDABLE), + STRING("String",COMPARABLE, ADDABLE, PRIM), COLOR("Colour",ANY), // IMAGE("Image", ANY), CONNECTION("Connection", ANY), @@ -59,7 +64,7 @@ public enum BlocklyType { NULL("",STRING, COLOR, CONNECTION), REF("",NULL), - PRIM("", NUMBER, BOOLEAN), + NOTHING("Void", REF, PRIM), VOID(""), CAPTURED_TYPE(""), @@ -109,6 +114,8 @@ public BlocklyType[] getSuperTypes() { public boolean hasAsSuperType(BlocklyType potentialSuperType) { if ( this.equalAsTypes(potentialSuperType) ) { return true; + } else if ( this.equals(BlocklyType.NOTHING) || potentialSuperType.equals(BlocklyType.NOTHING) ) { + return false; } else if ( this.superTypes.length == 0 ) { return false; } else { diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/Sig.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/Sig.java index 62a3f42efb..e8ed9ce598 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/Sig.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/typecheck/Sig.java @@ -50,18 +50,19 @@ public static Sig ofParamList(BlocklyType returnType, List paramLis } /** - * for a given AST-object {@link phraseWhoseSignaturIsChecked}, that has a signature object of {@link Sig} (a return type and its parameter types), - * check that the parameter types of the signature are consistent with the actual parameter types as defined by {@link paramTypes} - * If they are not consistent, add an error annoation to the AST-object. + * for a given AST-object phraseToCheck, that has a signature object of class Sig (a return type and its parameter types), + * check that the parameter types of the signature are consistent with the actual parameter types as defined by actualParamTypes + * If they are not consistent, add an error annotation to the AST-object. * - * @param phraseWhoseSignaturIsChecked the (parent) AST-object whose parameters are to be checked. It is needed only to add the error annotation. + * @param phraseToCheck the (parent) AST-object whose parameters are to be checked. It is needed only to add the error annotation. * @param actualParamTypes the actual parameter types derived from the actual AST-object (by typechecking, of course) * @return the result type from the signature; never null */ - private BlocklyType typeCheck(Phrase phraseWhoseSignaturIsChecked, List actualParamTypes) { + private BlocklyType typeCheck(Phrase phraseToCheck, List actualParamTypes) { + BlocklyType returnTypeIfError = this.returnType; // before: BlocklyType.NOTHING if ( varargParamType == null && actualParamTypes.size() != this.paramTypes.length ) { - phraseWhoseSignaturIsChecked.addTextlyError("number of parameters don't match", true); - return BlocklyType.NOTHING; + phraseToCheck.addTextlyError("number of parameters don't match", true); + return returnTypeIfError; } int i = 0; BlocklyType capturedType = null; @@ -71,9 +72,9 @@ private BlocklyType typeCheck(Phrase phraseWhoseSignaturIsChecked, List 0 ) { formatted = formatted.substring(0, 1).toUpperCase() + formatted.substring(1); @@ -144,6 +152,14 @@ private static String formatName(String input) { return formatted; } + /** + * format a BlocklyType to be usable as part of a message + * @param blocklyType the BlocklyType to be formatted + * @return the formatted BlocklyType + */private static String b2m(BlocklyType blocklyType) { + return String.valueOf(blocklyType).toLowerCase(); + } + public BlocklyType typeCheckPhraseList(Phrase phraseToCheck, IVisitor visitor, List phrases) { List parameterTypes = new ArrayList<>(); for ( Phrase phrase : phrases ) { diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/syntax/FunctionNames.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/syntax/FunctionNames.java index 97021a63a7..866a8e7e5d 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/syntax/FunctionNames.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/util/syntax/FunctionNames.java @@ -139,7 +139,7 @@ public String getOpSymbol() { * get function from {@link FunctionNames} from string parameter. It is possible for one function to have multiple string mappings. Throws exception if the * operator does not exists. * - * @param s of the function + * @param s name of the function * @return function from the enum {@link FunctionNames} */ diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/validate/TypecheckCommonLanguageVisitor.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/validate/TypecheckCommonLanguageVisitor.java index 7a2d912c45..dbe9882b98 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/validate/TypecheckCommonLanguageVisitor.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/visitor/validate/TypecheckCommonLanguageVisitor.java @@ -154,6 +154,7 @@ public BlocklyType visitColorConst(ColorConst colorConst) { @Override public BlocklyType visitDebugAction(DebugAction debugAction) { + // really ANY, not PRIM only return Sig.of(BlocklyType.VOID, BlocklyType.ANY).typeCheckPhrases(debugAction, this, debugAction.value); } @@ -471,16 +472,16 @@ public BlocklyType visitRepeatStmt(RepeatStmt repeatStmt) { case "FOR_EACH": Binary exprBinary = (Binary) repeatStmt.expr; BlocklyType listType = typeCheckPhrase(repeatStmt, exprBinary.right, BlocklyType.CAPTURED_TYPE); - BlocklyType varType = typeCheckPhrase(repeatStmt, exprBinary.left, BlocklyType.CAPTURED_TYPE); + BlocklyType varType = exprBinary.left instanceof VarDeclaration ? exprBinary.left.getBlocklyType() : BlocklyType.NOTHING; if ( listType.isArray() ) { - if ( listType.getMatchingElementTypeForArrayType().equalAsTypes(((VarDeclaration) exprBinary.left).getBlocklyType()) ) { + if ( listType.getMatchingElementTypeForArrayType().equalAsTypes(varType) ) { break; } else { - repeatStmt.addTextlyError("A list of " + exprBinary.left.getBlocklyType().getBlocklyName() + " was expected but it was found a " + listType.getMatchingElementTypeForArrayType().toString().toLowerCase(), true); + repeatStmt.addTextlyError("a list of " + exprBinary.left.getBlocklyType().getBlocklyName() + " was expected but it was found a list of " + listType.getMatchingElementTypeForArrayType().toString().toLowerCase(), true); break; } } else { - repeatStmt.addTextlyError("This control statement is only for a list of numbers, images, strings or booleans", true); + repeatStmt.addTextlyError("this control statement is only for a list of numbers, images, strings or booleans", true); break; } case "WAIT": @@ -488,7 +489,7 @@ public BlocklyType visitRepeatStmt(RepeatStmt repeatStmt) { break; default: - repeatStmt.addTextlyError("Invalid repeat mode. Expected 'TIMES', 'FOR', 'UNTIL', 'WHILE', 'FOREVER', 'FOR_EACH', or 'WAIT'.", true); + repeatStmt.addTextlyError("invalid repeat mode. Expected 'TIMES', 'FOR', 'UNTIL', 'WHILE', 'FOREVER', 'FOR_EACH', or 'WAIT'.", true); } typeCheckPhrase(repeatStmt, repeatStmt.list, BlocklyType.VOID); return BlocklyType.VOID; @@ -544,7 +545,7 @@ public BlocklyType visitStringConst(StringConst stringConst) { @Override public BlocklyType visitTextAppendStmt(TextAppendStmt textAppendStmt) { - return Sig.of(BlocklyType.VOID, BlocklyType.STRING, BlocklyType.STRING).typeCheckPhrases(textAppendStmt, this, textAppendStmt.var, textAppendStmt.text); + return Sig.of(BlocklyType.VOID, BlocklyType.STRING, BlocklyType.PRIM).typeCheckPhrases(textAppendStmt, this, textAppendStmt.var, textAppendStmt.text); } @Override @@ -554,7 +555,7 @@ public BlocklyType visitTextCharCastNumberFunct(TextCharCastNumberFunct textChar @Override public BlocklyType visitTextJoinFunct(TextJoinFunct textJoinFunct) { - return Sig.of(BlocklyType.STRING, BlocklyType.VARARGS, BlocklyType.ANY).typeCheckPhraseList(textJoinFunct, this, textJoinFunct.param.el); + return Sig.of(BlocklyType.STRING, BlocklyType.VARARGS, BlocklyType.PRIM).typeCheckPhraseList(textJoinFunct, this, textJoinFunct.param.el); } @Override diff --git a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/ReuseIntegrationAsUnitTest.java b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/ReuseIntegrationAsUnitTest.java index b5ae5c6b70..e0c64c3c84 100644 --- a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/ReuseIntegrationAsUnitTest.java +++ b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/ReuseIntegrationAsUnitTest.java @@ -314,8 +314,8 @@ public void testAllRobotSpecificProgramsAsUnitTests() throws Exception { @Ignore @Test public void testOneRobotSpecificProgramAsUnitTests() throws Exception { - String robotName = "ev3lejosv1"; - String programName = "textlyJava_expressions"; + String robotName = "microbitv2"; + String programName = "for_loop"; LOG.info("========= testing program " + programName + " for robot " + robotName); final String resourceDirectory = setupRobotFactoryAndGetResourceDirForRobotSpecificTests(robotName); runRegenerateAndCodeGenerationForOneRobotSpecificProgram(resourceDirectory, programName + ".xml", robotName, Collections.emptyList()); diff --git a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheckUtilModifyXmlProgram.java b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheckUtilModifyXmlProgram.java deleted file mode 100644 index 51ff694638..0000000000 --- a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheckUtilModifyXmlProgram.java +++ /dev/null @@ -1,92 +0,0 @@ -package de.fhg.iais.roberta.javaServer.integrationTest; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.util.EnumMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import de.fhg.iais.roberta.typecheck.BlocklyType; -import de.fhg.iais.roberta.util.Util; - -public class TestTypecheckUtilModifyXmlProgram { - private static final Pattern STMTEXPRESSION_PATTERN = Pattern.compile("(.*?)"); - private static final Pattern TYPE_PATTERN = Pattern.compile("--TYPE--"); - private static final Pattern VAR_NAME_PATTERN = Pattern.compile("--VAR-NAME--"); - private static final Pattern EVAL_PATTERN = Pattern.compile("--EVAL--"); - - private static final Map VAR_NAME_MAP = new EnumMap<>(BlocklyType.class); - - static { - VAR_NAME_MAP.put(BlocklyType.BOOLEAN, "boolT"); - VAR_NAME_MAP.put(BlocklyType.NUMBER, "num"); - VAR_NAME_MAP.put(BlocklyType.STRING, "str"); - VAR_NAME_MAP.put(BlocklyType.ARRAY_NUMBER, "listN2"); - VAR_NAME_MAP.put(BlocklyType.IMAGE, "img"); - VAR_NAME_MAP.put(BlocklyType.COLOR, "color"); - } - - public static void newProgramStmtExpr(String newExpression, String nameForXml, String robot) { - - String filePath = "/crossCompilerTests/robotSpecific/" + robot + "/textly/templateProgramStmtExpr.xml"; - String outputFilePath = "src/test/resources/crossCompilerTests/robotSpecific/" + robot + "/textly/" + nameForXml + ".xml"; - try { - - String xmlContent = Util.readResourceContent(filePath); - String escapedExpression = escapeXmlSpecialCharacters(newExpression); - Matcher matcher = STMTEXPRESSION_PATTERN.matcher(xmlContent); - - String modifiedXML = matcher.replaceAll("" + escapedExpression + ""); - - BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath)); - writer.write(modifiedXML); - writer.close(); - - - } catch ( IOException e ) { - e.printStackTrace(); - } - } - - public static void newProgramEvalExpr(BlocklyType newDataType, String evalExpression, String nameForXml) { - String filePath = "/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramExprEval.xml"; - String outputFilePath = "src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/" + nameForXml + ".xml"; - try { - String xmlContent = Util.readResourceContent(filePath); - - - String varName = VAR_NAME_MAP.getOrDefault(newDataType, "unknownVar"); - - String varType = newDataType.getBlocklyName(); - String escapedVarType = escapeXmlSpecialCharacters(varType); - String escapedVarName = escapeXmlSpecialCharacters(varName); - String escapedEvalExpression = escapeXmlSpecialCharacters(evalExpression); - - Matcher typeMatcher = TYPE_PATTERN.matcher(xmlContent); - String modifiedXML = typeMatcher.replaceAll(escapedVarType); - - Matcher varNameMatcher = VAR_NAME_PATTERN.matcher(modifiedXML); - modifiedXML = varNameMatcher.replaceAll(escapedVarName); - - Matcher evalMatcher = EVAL_PATTERN.matcher(modifiedXML); - modifiedXML = evalMatcher.replaceAll(escapedEvalExpression); - - BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath)); - writer.write(modifiedXML); - writer.close(); - - } catch ( IOException e ) { - e.printStackTrace(); - } - } - - private static String escapeXmlSpecialCharacters(String input) { - return input - .replace("&", "&") - .replace("<", "<") - .replace(">", ">"); - } - -} diff --git a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheck.java b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheck.java similarity index 64% rename from OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheck.java rename to OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheck.java index f7dac4bdcf..8a7100dea6 100644 --- a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/integrationTest/TestTypecheck.java +++ b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheck.java @@ -1,15 +1,11 @@ -package de.fhg.iais.roberta.javaServer.integrationTest; +package de.fhg.iais.roberta.javaServer.typecheck; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.apache.commons.lang3.tuple.Triple; import org.json.JSONObject; import org.junit.Assert; import org.junit.BeforeClass; @@ -25,7 +21,6 @@ import de.fhg.iais.roberta.typecheck.BlocklyType; import de.fhg.iais.roberta.typecheck.InfoCollector; import de.fhg.iais.roberta.typecheck.NepoInfo; -import de.fhg.iais.roberta.util.PluginProperties; import de.fhg.iais.roberta.util.Util; import de.fhg.iais.roberta.util.ast.AstFactory; import de.fhg.iais.roberta.util.test.UnitTestHelper; @@ -71,19 +66,23 @@ */ public class TestTypecheck { private static final Logger LOG = LoggerFactory.getLogger(TestTypecheck.class); - private static RobotFactory testFactory; + private static final boolean SHOW_MESSAGES = true; + + public static final String TEST_SPEC_YML = "classpath:/crossCompilerTests/testSpec.yml"; private static JSONObject robotsFromTestSpec; private static JSONObject progDeclsFromTestSpec; - private static final String CROSS_COMPILER_TESTS = "/crossCompilerTests/"; - private static final String ROBOT_SPECIFIC = "robotSpecific/"; - public static final String TEST_SPEC_YML = "classpath:/crossCompilerTests/testSpec.yml"; + + private RobotFactory testFactory; + private int typecheckErrorCount = 0; private int parserErrorCount = 0; + private List messages = null; - private static final Pattern EXPRESSION_PATTERN = Pattern.compile("([^<]+)"); - private static final Pattern STMTEXPRESSION_PATTERN = Pattern.compile("([^<]+)"); - + /** + * tests common to all robot plugins (as implemented in TypecheckCommonLanguageVisitor) + * executed for the microbitv2 plugin + */ public static final List NUMBER_EXPRESSIONS = Arrays.asList( "sin(num) + cos(num) + tan(num)", "exp(2) + square(4) + sqrt(9) + abs(-5) + log10(100) + log(2)", @@ -96,8 +95,6 @@ public class TestTypecheck { "castToNumber(\"2\")", "castStringToNumber(str,1)" ); - public static final List NUMBER_STATEMENTS = convertToStatements(NUMBER_EXPRESSIONS, "num"); - public static final List BOOLEAN_EXPRESSIONS = Arrays.asList( "isEven(10) && isOdd(7) || isPrime(11) && isWhole(8)", @@ -128,12 +125,6 @@ public class TestTypecheck { "castToChar(65)" ); - public static final List COLOR_EXPRESSIONS = Arrays.asList( - "#yellow", - "#black", - "#rgb(FF0000)" - ); - public static final List STMT_FUNC = Arrays.asList( "set(listN, 1000,0);", "setFromEnd(listN, 1000,0);", @@ -151,27 +142,135 @@ public class TestTypecheck { "removeLast(listN);", "changeBy(num,2);", - "appendText(str, \"aaa\");" + "appendText(str, \"aaa\");", + "appendText(str, str);", + "appendText(str, 1-4);", + "appendText(str, true||false);" ); - public static final List STMT_FUNC_FAIL = Arrays.asList( - //FNAMESTMT: - "set(listN, \"hola\",0);", - "setFromEnd(listN, 1000,0,2);", - "setFirst(listN,false);", - "setLast(listN);", - "insert(listN, true,0);", - "insertFromEnd(listN, 1000);", - "insertFirst(listN,666,9);", - "insertLast(listN,666,true);", - "remove(listN,0,0);", - "removeFromEnd(listN);", - "removeFirst(listN,true);", - "removeLast();", + public static final List STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS = Arrays.asList( + // very simple cases + ";", + "// comment", + // Number expressions + "num = num;", + "num = 1;", + "num = 1.4;", + "num = pi;", + "num = sqrt_1_2;", + "num = randomInt(1, 100);", + "num = randomFloat();", + "num = sin(num);", + "num = (sin(45) + cos(45)) * tan(60);", + "num = exp(num);", + "num = log10(num) * (square(10));", + "num = ceil(3.782) + floor(3.1782);", + "num = round(phi);", + "num = min(listN);", + "num = max(listN) * average(listN);", + "num = sum(listN);", + "num = randomItem(listN);", + "num = size(listN);", + "num = indexOfFirst(listN, 2);", + "num = indexOfLast(listN, 2);", + "num = getFirst(listN);", + "num = getAndRemove(listN, 2);", + "num = constrain(102, 1, 100);", + "num = ((((3))));", + "num = 2^2;", + "num = num^num;", + "num = 5%2;", + "num = 10*10;", + "num = 100/10;", + "num = 1+2;", + "num = pi + e;", + "num = pi + 4.5;", + "num = randomFloat() + cos(num);", + "num = +-1;", + "num = -+1;", + "num = true ? 1 : 2;", - "set(4, 1000,0);", - "removeFromEnd(3,0);", - "insert(3, 1000,0);" + // Boolean expressions + "boolT = boolF;", + "boolT = true;", + "boolT = !!!!true;", + "boolT = (num > 4) ? (num == 2) : (num + 1 == num + 3);", + "boolT = isPositive(----6);", + "boolT = isDivisibleBy(6, 2);", + "boolT = isWhole(6.21234);", + "boolT = isPrime(6);", + "boolT = isEmpty(listN);", + "boolT = !boolF;", + "boolT = boolT || true;", + "boolT = num == num;", + "boolT = 7 == 7;", + "boolT = str == str;", + "boolT = num > 0;", + "boolT = pi > 20;", + "boolT = num >= num;", + "boolT = 10 > 0;", + "boolT = true || false;", + "boolT = num > 4;", + "boolT = num != 5;", + "boolT = (num == 10) || (num != 5);", + "boolT = 1 < 20;", + "boolT = 2 <= 3;", + + // String expressions + "str = \"OpenRoberta is awesome!\";", + "str = createTextWith(str, 12, true);", + "str = createTextWith(true, 'true', 12);" + ); + + public static final List STMT_VAR_ASSIGN = Arrays.asList( + //EXPRESSIONS: + "num=sin(num)+cos(num)+tan(num)+asin(num)+acos(num)+atan(num);", + "num=exp(2) + square(4) + sqrt(9) + abs(-5) + log10(100) + log(2);", + "num=randomInt(1,10)+ randomFloat();", + "num= floor(3.7) + ceil(2.3) + round(4.6);", + "boolT = isEven(10) && isOdd(7) || isPrime(11) && isWhole(8) || isEmpty(listN) && isPositive(5) || isNegative(-3) && isDivisibleBy(10, 5);", + + "num = sum(listN) + max(listN) - min(listN) * average(listN) / median(listN) + stddev(listN) % size(listN) + randomItem(listN);", + "num = indexOfFirst(listN, 0);", + "num = indexOfLast(listN, 0);", + "num= getFirst(listN)+get(listN,1)+ getFromEnd(listN,0)+ getLast(listN);", + + "str = createTextWith(getFirst(listN), get(listN,1), getFromEnd(listN,2), get(listN,3), getLast(listN));", + + "num = getAndRemoveFirst(listN2) + getAndRemove(listN2, 1) + getAndRemoveFromEnd(listN2, 0) + getAndRemoveLast(listN2);", + + "listN2 = subList(listN, 0, 3);", + "listN2 = subListFromIndexToEnd(listN, 0, 1);", + "listN2 = subListFromEndToIndex(listN, 1, 1);", + "listN2 = subListFromEndToEnd(listN, 4, 2);", + "listN2 = subListFromIndexToLast(listN, 1);", + "listN2 = subListFromFirstToIndex(listN, 2);", + "listN2 = subListFromFirstToLast(listN);", + "listN2 = subListFromFirstToIndex(listN, 3);", + "listN2 = subListFromEndToLast(listN, 3);", + "str = castToString(5);", + "str = castToChar(65);", + "num = castToNumber(\"2\");", + "num = castStringToNumber(str,1);" + ); + + public static final List STMT_CONTROLS_STATEMENTS = Arrays.asList( + "for ( Number i=1; i<10; i++){};", + "for ( Number i=1; i<10; i=i+1){};", + "for ( Number i=1; i<10; i=i+2+4){};", + "for ( Number i=1; i<10; i=num+1){};", + "for each( Number item: listN){num=1;};", + "if(true){num=1;} else if(false){num=2;} else{num=5;};", + "if(boolT||boolF){num=1;} else if(false){num=2;} else{num=5;};", + "while(true){num=1;};", + "while(boolT==true){num=2;};", + "while((boolT==true) && (boolF==false)){num=2;};", + "for (Number i = 0; i < 10; i = i + 2) { if (isEven(i)) {insertLast(listN, i * 2);} else {insertFirst(listN, i);}; };", + "waitUntil(average(listN) == 5) {insertLast(listN, 7);} orWaitFor(average(listN) == 2) {insertFirst(listN, 666);};", + "waitUntil(false) {num=1;} orWaitFor(true) {num=2;};", + "wait ms(500);", + "while(true){break;};", + "while(true){continue;};" ); public static final List MICROBITV2_SPECIFIC = Arrays.asList( @@ -262,6 +361,7 @@ public class TestTypecheck { ); public static final List WEDO_SPECIFIC = Arrays.asList( + "color = color;", "color = #rgb(ff1493); color = #pink;", "color = #rgb(800080); color = #purple;", "color = #rgb(4876ff); color = #blue;", @@ -290,79 +390,10 @@ public class TestTypecheck { "wedo.turnRgbOn(R,#pink);", "wedo.turnRgbOff(R);" ); - public static final List STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS = Arrays.asList( - // Number expressions - "num = num;", - "num = 1;", - "num = 1.4;", - "num = pi;", - "num = sqrt_1_2;", - "num = randomInt(1, 100);", - "num = randomFloat();", - "num = sin(num);", - "num = (sin(45) + cos(45)) * tan(60);", - "num = exp(num);", - "num = log10(num) * (square(10));", - "num = ceil(3.782) + floor(3.1782);", - "num = round(phi);", - "num = min(listN);", - "num = max(listN) * average(listN);", - "num = sum(listN);", - "num = randomItem(listN);", - "num = size(listN);", - "num = indexOfFirst(listN, 2);", - "num = indexOfLast(listN, 2);", - "num = getFirst(listN);", - "num = getAndRemove(listN, 2);", - "num = constrain(102, 1, 100);", - "num = ((((3))));", - "num = 2^2;", - "num = num^num;", - "num = 5%2;", - "num = 10*10;", - "num = 100/10;", - "num = 1+2;", - "num = pi + e;", - "num = pi + 4.5;", - "num = randomFloat() + cos(num);", - "num = +-1;", - "num = -+1;", - "num = true ? 1 : 2;", - - // Boolean expressions - "boolT = boolF;", - "boolT = true;", - "boolT = !!!!true;", - "boolT = (num > 4) ? (num == 2) : (num + 1 == num + 3);", - "boolT = isPositive(----6);", - "boolT = isDivisibleBy(6, 2);", - "boolT = isWhole(6.21234);", - "boolT = isPrime(6);", - "boolT = isEmpty(listN);", - "boolT = !boolF;", - "boolT = b || true;", - "boolT = num == num;", - "boolT = 7 == 7;", - "boolT = str == str;", - "boolT = num > 0;", - "boolT = pi > 20;", - "boolT = num >= num;", - "boolT = 10 > 0;", - "boolT = true || false;", - "boolT = num > 4;", - "boolT = num != 5;", - "boolT = (num == 10) || (num != 5);", - "boolT = 1 < 20;", - "boolT = 2 <= 3;", - - // String expressions - "str = \"OpenRoberta is awesome!\";", - "str = createTextWith(str, 12, true);", - "str = createTextWith(true, 'true', 12);" - ); List STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS_ERROR_PARSER = Arrays.asList( "num = 1,,;", + "num = 1", "num = randomInt(1,,100);", "num = pi +;", "boolT = (num > );", @@ -380,42 +411,37 @@ public class TestTypecheck { "num = pi + sqrt(,2);", "boolT = !;", "num = 2 *;", - "boolT = (7 == );" + "boolT = (7 == );", + "undefinedVar = ;" ); - public static final List STMT_VAR_ASSIGN = Arrays.asList( - //EXPRESSIONS: - "num=sin(num)+cos(num)+tan(num)+asin(num)+acos(num)+atan(num);", - "num=exp(2) + square(4) + sqrt(9) + abs(-5) + log10(100) + log(2);", - "num=randomInt(1,10)+ randomFloat();", - "num= floor(3.7) + ceil(2.3) + round(4.6);", - "boolT = isEven(10) && isOdd(7) || isPrime(11) && isWhole(8) || isEmpty(listN) && isPositive(5) || isNegative(-3) && isDivisibleBy(10, 5);", - - "num = sum(listN) + max(listN) - min(listN) * average(listN) / median(listN) + stddev(listN) % size(listN) + randomItem(listN);", - "num = indexOfFirst(listN, 0);", - "num = indexOfLast(listN, 0);", - "num= getFirst(listN)+get(listN,1)+ getFromEnd(listN,0)+ getLast(listN);", - - "str = createTextWith(getFirst(listN), get(listN,1), getFromEnd(listN,2), get(listN,3), getLast(listN));", + public static final List STMT_FUNC_FAIL = Arrays.asList( + //FNAMESTMT: + "set(listN, \"hola\",0);", + "setFromEnd(listN, 1000,0,2);", + "setFirst(listN,false);", + "setLast(listN);", + "insert(listN, true,0);", + "insertFromEnd(listN, 1000);", + "insertFirst(listN,666,9);", + "insertLast(listN,666,true);", + "remove(listN,0,0);", + "removeFromEnd(listN);", + "removeFirst(listN,true);", + "removeLast();", - "num = getAndRemoveFirst(listN2) + getAndRemove(listN2, 1) + getAndRemoveFromEnd(listN2, 0) + getAndRemoveLast(listN2);", + "set(4, 1000,0);", + "removeFromEnd(3,0);", + "insert(3, 1000,0);", - "listN2 = subList(listN, 0, 3);", - "listN2 = subListFromIndexToEnd(listN, 0, 1);", - "listN2 = subListFromEndToIndex(listN, 1, 1);", - "listN2 = subListFromEndToEnd(listN, 4, 2);", - "listN2 = subListFromIndexToLast(listN, 1);", - "listN2 = subListFromFirstToIndex(listN, 2);", - "listN2 = subListFromFirstToLast(listN);", - "listN2 = subListFromFirstToIndex(listN, 3);", - "listN2 = subListFromEndToLast(listN, 3);", - "str = castToString(5);", - "str = castToChar(65);", - "num = castToNumber(\"2\");", - "num = castStringToNumber(str,1);" + "appendText(str, listN);", + "appendText(str, ima);" ); + public static final List STMT_VAR_ASSIGN_FAIL = Arrays.asList( //EXPRESSIONS: + "num=true;", + "num=str;", "num=sin(num+true)+cos(num)+tan(num)+asin(num)+acos(num)+atan(num);", "num=exp(2) + square(#black) + sqrt(9) + abs(-5) + log10(100) + log(2);", "num=randomInt(1,10,0)+ randomFloat(1);", @@ -436,25 +462,12 @@ public class TestTypecheck { "listN = subListFromFirstToIndex();", "listN = subListFromFirstToLast(listN2,2);", "listN = subListFromFirstToIndex(listN2,false);", - "listN = subListFromEndToLast(listN2,3,3);" - ); - public static final List STMT_CONTROLS_STATEMENTS = Arrays.asList( - "for ( Number i=1; i<10; i++){};", - "for ( Number i=1; i<10; i=i+1){};", - "for ( Number i=1; i<10; i=i+2+4){};", - "for ( Number i=1; i<10; i=num+1){};", - "for each( Number item: listN){num=1;};", - "if(true){num=1;} else if(false){num=2;} else{num=5;};", - "if(boolT||boolF){num=1;} else if(false){num=2;} else{num=5;};", - "while(true){num=1;};", - "while(boolT==true){num=2;};", - "while((boolT==true) && (boolF==false)){num=2;};", - "for (Number i = 0; i < 10; i = i + 2) { if (isEven(i)) {insertLast(listN, i * 2);} else {insertFirst(listN, i);}; };", - "waitUntil(average(listN) == 5) {insertLast(listN, 7);} orWaitFor(average(listN) == 2) {insertFirst(listN, 666);};", - "waitUntil(false) {num=1;} orWaitFor(true) {num=2;};", - "wait ms(500);", - "while(true){break;};", - "while(true){continue;};" + "listN = subListFromEndToLast(listN2,3,3);", + + "undefinedVariable = \"str\";", + "num = undefinedVariable;", + "undefinedVariable = undefinedVariable;", + "appendText(str, undefinedVariable);" ); public static final List STMT_CONTROLS_STATEMENTS_FAIL = Arrays.asList( @@ -479,17 +492,9 @@ public class TestTypecheck { "wait ms(false);" ); - private static List convertToStatements(List expressions, String variableName) { - return expressions.stream() - .map(expr -> variableName + " = " + expr + ";") - .collect(Collectors.toList()); - } - @BeforeClass public static void setup() { AstFactory.loadBlocks(); - Properties properties = Util.loadPropertiesRecursively("classpath:/microbitv2.properties"); - testFactory = new RobotFactory(new PluginProperties("microbitv2", "", "", properties)); JSONObject testSpecification = Util.loadYAML(TEST_SPEC_YML); progDeclsFromTestSpec = testSpecification.getJSONObject("progs"); robotsFromTestSpec = testSpecification.getJSONObject("robots"); @@ -500,218 +505,157 @@ private void setupRobotFactoryForRobot(String robotName) { testFactory = Util.configureRobotPlugin(robotName, "", "", pluginDefines); } - protected String setupRobotFactoryAndGetResourceDirForRobotSpecificTests(String robotName) { - setupRobotFactoryForRobot(robotName); - JSONObject robot = robotsFromTestSpec.getJSONObject(robotName); - final String robotDir = robot.getString("dir"); - return CROSS_COMPILER_TESTS + ROBOT_SPECIFIC + robotDir + (robotDir.endsWith("/") ? "" : "/"); - } - @Test - public void testExpr() throws Exception { - String robotName = "microbitv2"; - final String resourceDirectory = setupRobotFactoryAndGetResourceDirForRobotSpecificTests(robotName); - String folderPath = resourceDirectory + "textly/"; - - System.out.println("========= EVALUATING NUMBER EXPRESSIONS ========="); - for ( String expression : NUMBER_EXPRESSIONS ) { - - TestTypecheckUtilModifyXmlProgram.newProgramEvalExpr(BlocklyType.NUMBER, expression, "testTextlyExpr"); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyExpr.xml", EXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println("========= EVALUATING BOOLEAN EXPRESSIONS ========="); - for ( String expression : BOOLEAN_EXPRESSIONS ) { - - TestTypecheckUtilModifyXmlProgram.newProgramEvalExpr(BlocklyType.BOOLEAN, expression, "testTextlyExpr"); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyExpr.xml", EXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println("========= EVALUATING LIST EXPRESSIONS ========="); - for ( String expression : LIST_EXPRESSIONS ) { - - TestTypecheckUtilModifyXmlProgram.newProgramEvalExpr(BlocklyType.ARRAY_NUMBER, expression, "testTextlyExpr"); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyExpr.xml", EXPRESSION_PATTERN); - checkTypecheckGoodResults(); + public void testSuccessExpr() throws Exception { + List>> toBeTested = new ArrayList<>(); + toBeTested.add(Triple.of("microbitv2", BlocklyType.NUMBER, NUMBER_EXPRESSIONS)); + toBeTested.add(Triple.of("microbitv2", BlocklyType.BOOLEAN, BOOLEAN_EXPRESSIONS)); + toBeTested.add(Triple.of("microbitv2", BlocklyType.ARRAY_NUMBER, LIST_EXPRESSIONS)); + toBeTested.add(Triple.of("microbitv2", BlocklyType.STRING, STRING_EXPRESSIONS)); + + for ( Triple> testSpec : toBeTested ) { + String robotName = testSpec.getLeft(); + setupRobotFactoryForRobot(robotName); + LOG.info(""); + LOG.info("========= EVALUATING for robot " + robotName + " expressions of type " + testSpec.getMiddle()); + for ( String expression : testSpec.getRight() ) { + LOG.info(expression); + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalExpr(testSpec.getMiddle(), expression); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkMustSucceed(); + } } - System.out.println("========= EVALUATING STRING EXPRESSIONS ========="); - for ( String expression : STRING_EXPRESSIONS ) { - - TestTypecheckUtilModifyXmlProgram.newProgramEvalExpr(BlocklyType.STRING, expression, "testTextlyExpr"); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyExpr.xml", EXPRESSION_PATTERN); - checkTypecheckGoodResults(); + for ( Triple> testSpec : toBeTested ) { + String robotName = testSpec.getLeft(); + setupRobotFactoryForRobot(robotName); + LOG.info(""); + LOG.info("========= EVALUATING for robot " + robotName + " assignments of expressions of type " + testSpec.getMiddle()); + for ( String expression : testSpec.getRight() ) { + LOG.info(expression); + String statement = TestTypecheckUtil.convertToStatement(expression, testSpec.getMiddle()); + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalStmt(robotName, statement); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkMustSucceed(); + } } - } @Test - public void testStmtsExpr() throws Exception { - String robotName = "microbitv2"; - final String resourceDirectory = setupRobotFactoryAndGetResourceDirForRobotSpecificTests(robotName); - String folderPath = resourceDirectory + "textly/"; - - - System.out.println("========= EVALUATING MICROBITV2 SPECIFIC STATEMENTS ========="); - for ( String stmts : MICROBITV2_SPECIFIC ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING FUNCTION STATEMENTS ========="); - for ( String stmts : STMT_FUNC ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING VAR ASSIGNMENT SINGLE EXPRESSIONS STATEMENTS ========="); - for ( String stmts : STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING VAR ASSIGNMENT WITH PARSER ERRORS ========="); - for ( String stmts : STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS_ERROR_PARSER ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkParserFailResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING VAR ASSIGNMENT STATEMENTS ========="); - for ( String stmts : STMT_VAR_ASSIGN ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING CONTROL STATEMENTS ========="); - for ( String stmts : STMT_CONTROLS_STATEMENTS ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING CONTROL STATEMENTS ========="); - for ( String stmts : STMT_CONTROLS_STATEMENTS_FAIL ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckFailResults(); - } - - System.out.println(" "); - System.out.println("========= EVALUATING CONTROL STATEMENTS ========="); - for ( String stmts : STMT_FUNC_FAIL ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckFailResults(); + public void testSuccessStmts() throws Exception { + List>> toBeTested = new ArrayList<>(); + toBeTested.add(Triple.of("microbitv2", "microbitv2 specific functions", MICROBITV2_SPECIFIC)); + toBeTested.add(Triple.of("microbitv2", "generic function calls", STMT_FUNC)); + toBeTested.add(Triple.of("microbitv2", "simple assignments", STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS)); + toBeTested.add(Triple.of("microbitv2", "assignments", STMT_VAR_ASSIGN)); + toBeTested.add(Triple.of("microbitv2", "control statements", STMT_CONTROLS_STATEMENTS)); + toBeTested.add(Triple.of("wedo", "wedo specigic functions", WEDO_SPECIFIC)); + + for ( Triple> testSpec : toBeTested ) { + String robotName = testSpec.getLeft(); + setupRobotFactoryForRobot(robotName); + LOG.info(""); + LOG.info("========= EVALUATING for robot " + robotName + " statements of kind: " + testSpec.getMiddle()); + for ( String expression : testSpec.getRight() ) { + LOG.info(expression); + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalStmt(testSpec.getLeft(), expression); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkMustSucceed(); + } } + } - System.out.println(" "); - System.out.println("========= EVALUATING CONTROL STATEMENTS ========="); - for ( String stmts : STMT_VAR_ASSIGN_FAIL ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckFailResults(); + @Test + public void testParserErrors() throws Exception { + List>> toBeTested = new ArrayList<>(); + toBeTested.add(Triple.of("microbitv2", "microbitv2 parser errors", STMT_VAR_ASSIGN_SIMPLE_EXPRESSIONS_ERROR_PARSER)); + + for ( Triple> testSpec : toBeTested ) { + String robotName = testSpec.getLeft(); + setupRobotFactoryForRobot(robotName); + LOG.info(""); + LOG.info("========= EVALUATING for robot " + robotName + " parser errors of kind: " + testSpec.getMiddle()); + for ( String expression : testSpec.getRight() ) { + LOG.info(expression); + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalStmt(testSpec.getLeft(), expression); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkParserFailResults(); + } } + } - String robotNameWedo = "wedo"; - final String resourceDirectoryWedo = setupRobotFactoryAndGetResourceDirForRobotSpecificTests(robotNameWedo); - String folderPathWedo = resourceDirectoryWedo + "textly/"; - System.out.println(" "); - System.out.println("========= EVALUATING SPECIFIC STATEMENTS FOR WEDO ========="); - for ( String stmts : WEDO_SPECIFIC ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotNameWedo); - getProgramAstFromExportXmlAndExpr(testFactory, folderPathWedo + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); + @Test + public void testTypecheckErrors() throws Exception { + List>> toBeTested = new ArrayList<>(); + toBeTested.add(Triple.of("microbitv2", "control statements", STMT_CONTROLS_STATEMENTS_FAIL)); + toBeTested.add(Triple.of("microbitv2", "function calls", STMT_FUNC_FAIL)); + toBeTested.add(Triple.of("microbitv2", "assignments", STMT_VAR_ASSIGN_FAIL)); + + + for ( Triple> testSpec : toBeTested ) { + String robotName = testSpec.getLeft(); + setupRobotFactoryForRobot(robotName); + LOG.info(""); + LOG.info("========= EVALUATING for robot " + robotName + " typecheck errors of kind: " + testSpec.getMiddle()); + for ( String expression : testSpec.getRight() ) { + LOG.info(expression); + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalStmt(testSpec.getLeft(), expression); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkMustHaveTypeErrors(); + } } } @Ignore @Test - public void testSingleStmtExpr() throws Exception { + public void testSingleStmt() throws Exception { String robotName = "microbitv2"; - final String resourceDirectory = setupRobotFactoryAndGetResourceDirForRobotSpecificTests(robotName); - String folderPath = resourceDirectory + "textly/"; - - String expression = "microbitv2.showOnSerial(\"Halloooo\");"; - - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(expression, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - //checkTypecheckFailResults(); // check if the stmt should fail - checkTypecheckGoodResults(); // check if the stmt should not fail - - System.out.println("========= EVALUATING MICROBITV2 SPECIFIC STATEMENTS ========="); - for ( String stmts : MICROBITV2_SPECIFIC ) { - TestTypecheckUtilModifyXmlProgram.newProgramStmtExpr(stmts, "testTextlyStmt", robotName); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyStmt.xml", STMTEXPRESSION_PATTERN); - checkTypecheckGoodResults(); - } + setupRobotFactoryForRobot(robotName); + String expression = "listN = subList(listN2,0,true);"; + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalStmt(robotName, expression); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkMustHaveTypeErrors(); // check if the stmt should fail + //checkMustSucceed(); // check if the stmt should not fail } @Ignore @Test public void testSingleExpression() throws Exception { String robotName = "microbitv2"; - final String resourceDirectory = setupRobotFactoryAndGetResourceDirForRobotSpecificTests(robotName); - String folderPath = resourceDirectory + "textly/"; + setupRobotFactoryForRobot(robotName); String expression = "sin(num) + cos(num) + tan(num)"; - TestTypecheckUtilModifyXmlProgram.newProgramEvalExpr(BlocklyType.NUMBER, expression, "testTextlyExpr"); - getProgramAstFromExportXmlAndExpr(testFactory, folderPath + "testTextlyExpr.xml", EXPRESSION_PATTERN); - checkTypecheckFailResults(); // check if the expression should fail + String xmlUnderTest = TestTypecheckUtil.getProgramUnderTestForEvalExpr(BlocklyType.NUMBER, expression); + typecheckAndCollectInfosForProgram(testFactory, xmlUnderTest); + checkMustHaveTypeErrors(); // check if the expression should fail //checkTypecheckGoodResults(); // check if the expression should not fail } - private static List typecheckAndCollectInfos(Phrase ast, UsedHardwareBean usedHardwareBean, String robotName) throws Exception { - - if ( robotName.equals("wedo") ) { - WedoTypecheckVisitor visitor = new WedoTypecheckVisitor(usedHardwareBean); - ast.accept(visitor); - return InfoCollector.collectInfos(ast); - } else if ( robotName.equals("microbitv2") ) { - MicrobitV2TypecheckVisitor visitor = new MicrobitV2TypecheckVisitor(usedHardwareBean); - ast.accept(visitor); - return InfoCollector.collectInfos(ast); - } else { - LOG.info("Invalid Robot name" + robotName); - return null; - } - } - - public void getProgramAstFromExportXmlAndExpr(RobotFactory factory, String xml, Pattern pattern) throws Exception { - String exportedProgram = new String(Files.readAllBytes(Paths.get("src/test/resources/" + xml))); - Project.Builder builder = UnitTestHelper.setupWithExportXML(factory, exportedProgram); + private void typecheckAndCollectInfosForProgram(RobotFactory factory, String xmlUnderTest) throws Exception { + typecheckErrorCount = 0; + parserErrorCount = 0; + messages = new ArrayList<>(); - List expression = extractExpression(factory, exportedProgram, pattern); + Project.Builder builder = UnitTestHelper.setupWithExportXML(factory, xmlUnderTest); Project project = builder.build(); UnitTestHelper.executeWorkflow("showsource", testFactory, project); UsedHardwareBean usedHardwareBean = project.getWorkerResult(UsedHardwareBean.class); - LOG.info("========= Evaluating the expression\n " + expression); for ( List listOfPhrases : project.getProgramAst().getTree() ) { for ( Phrase phrase : listOfPhrases ) { - List infos = typecheckAndCollectInfos(phrase, usedHardwareBean, factory.getPluginProperties().getRobotName()); + List infos = typecheckAndCollectInfosForPhrase(phrase, usedHardwareBean, factory.getPluginProperties().getRobotName()); for ( NepoInfo info : infos ) { if ( info.getSeverity() == NepoInfo.Severity.ERROR ) { if ( info.getMessage().contains("PARSE") ) { + messages.add(info.getMessage()); parserErrorCount++; } if ( info.getMessage().contains("TYPECHECK") ) { + messages.add(info.getMessage()); typecheckErrorCount++; } } @@ -720,52 +664,47 @@ public void getProgramAstFromExportXmlAndExpr(RobotFactory factory, String xml, } } - private void checkTypecheckGoodResults() { - LOG.info("Typecheck errors: " + typecheckErrorCount); - if ( parserErrorCount > 0 ) { - Assert.fail("Parser errors found: " + parserErrorCount); + private static List typecheckAndCollectInfosForPhrase(Phrase ast, UsedHardwareBean usedHardwareBean, String robotName) throws Exception { + if ( robotName.equals("wedo") ) { + WedoTypecheckVisitor visitor = new WedoTypecheckVisitor(usedHardwareBean); + ast.accept(visitor); + return InfoCollector.collectInfos(ast); + } else if ( robotName.equals("microbitv2") ) { + MicrobitV2TypecheckVisitor visitor = new MicrobitV2TypecheckVisitor(usedHardwareBean); + ast.accept(visitor); + return InfoCollector.collectInfos(ast); + } else { + LOG.info("Invalid Robot name" + robotName); + return null; } - Assert.assertTrue("There should not be any errors", typecheckErrorCount == 0); - typecheckErrorCount = 0; - parserErrorCount = 0; } - private void checkTypecheckFailResults() { - LOG.info("Typecheck errors: " + typecheckErrorCount); - if ( parserErrorCount > 0 ) { - Assert.fail("Parser errors found: " + parserErrorCount); + private void checkMustSucceed() { + if (parserErrorCount > 0 || typecheckErrorCount > 0 || SHOW_MESSAGES) { + for ( String message : messages ) { + LOG.info(message); + } } - Assert.assertTrue("There should be typecheck errors", typecheckErrorCount > 0); - typecheckErrorCount = 0; - parserErrorCount = 0; + Assert.assertEquals("Unexpected parser error", 0, parserErrorCount); + Assert.assertEquals("Unexpected typecheck error", 0, typecheckErrorCount); } - private void checkParserFailResults() { - LOG.info("Parser errors: " + parserErrorCount); - Assert.assertTrue("There should be parser errors", parserErrorCount > 0); - parserErrorCount = 0; - typecheckErrorCount = 0; - } - - - public static List extractExpression(RobotFactory factory, String exportXmlAsString, Pattern pattern) { - List expressions = new ArrayList<>(); - String[] parts = exportXmlAsString.split("\\s*\\s*\\s*"); - String[] programParts = parts[0].split(""); - String program = programParts[1]; - - Matcher matcher = pattern.matcher(program); - - - while ( matcher.find() ) { - String expressionValue = matcher.group(1); - expressions.add(expressionValue); + private void checkMustHaveTypeErrors() { + if (SHOW_MESSAGES) { + for ( String message : messages ) { + LOG.info(message); + } } + Assert.assertEquals("Unexpected parser error", 0, parserErrorCount); + Assert.assertNotEquals("typecheck error was expected", 0, typecheckErrorCount); + } - if ( expressions.isEmpty() ) { - System.out.println("Expression not found in the program"); + private void checkParserFailResults() { + if (SHOW_MESSAGES) { + for ( String message : messages ) { + LOG.info(message); + } } - return expressions; + Assert.assertNotEquals("parse error was expeced", 0, parserErrorCount); } - } diff --git a/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheckUtil.java b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheckUtil.java new file mode 100644 index 0000000000..004f7a036a --- /dev/null +++ b/OpenRobertaServer/src/test/java/de/fhg/iais/roberta/javaServer/typecheck/TestTypecheckUtil.java @@ -0,0 +1,74 @@ +package de.fhg.iais.roberta.javaServer.typecheck; + +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.junit.Assert; + +import de.fhg.iais.roberta.typecheck.BlocklyType; +import de.fhg.iais.roberta.util.Util; + +public class TestTypecheckUtil { + private static final Pattern TYPE_PATTERN = Pattern.compile("--TYPE--"); + private static final Pattern VAR_NAME_PATTERN = Pattern.compile("--VAR-NAME--"); + private static final Pattern TO_BE_TESTED_PATTERN = Pattern.compile("--TO-BE-TESTED--"); + + private static final Map VAR_NAME_MAP = new EnumMap<>(BlocklyType.class); + static { + VAR_NAME_MAP.put(BlocklyType.BOOLEAN, "boolT"); + VAR_NAME_MAP.put(BlocklyType.NUMBER, "num"); + VAR_NAME_MAP.put(BlocklyType.STRING, "str"); + VAR_NAME_MAP.put(BlocklyType.ARRAY_NUMBER, "listN2"); + VAR_NAME_MAP.put(BlocklyType.IMAGE, "img"); + VAR_NAME_MAP.put(BlocklyType.COLOR, "color"); + } + + public static String getProgramUnderTestForEvalStmt(String robot, String stmt) { + String filePath = "/crossCompilerTests/robotSpecific/" + robot + "/textly/templateProgramStmtExpr.xml"; + String xmlContent = Util.readResourceContent(filePath); + + Matcher matcher = TO_BE_TESTED_PATTERN.matcher(xmlContent); + String modifiedXML = matcher.replaceAll(escapeXmlSpecialCharacters(stmt)); + return modifiedXML; + } + + public static String getProgramUnderTestForEvalExpr(BlocklyType expectedType, String toBeTested) { + String filePath = "/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramExprEval.xml"; + String xmlContent = Util.readResourceContent(filePath); + + String varName = VAR_NAME_MAP.get(expectedType); + Assert.assertNotNull(varName, "Variable of type " + expectedType + " not found"); + String varType = expectedType.getBlocklyName(); + String escapedVarType = escapeXmlSpecialCharacters(varType); + String escapedVarName = escapeXmlSpecialCharacters(varName); + String escapedtoBeTested = escapeXmlSpecialCharacters(toBeTested); + + Matcher matcher = TYPE_PATTERN.matcher(xmlContent); + xmlContent = matcher.replaceAll(escapedVarType); + + matcher = VAR_NAME_PATTERN.matcher(xmlContent); + xmlContent = matcher.replaceAll(escapedVarName); + + matcher = TO_BE_TESTED_PATTERN.matcher(xmlContent); + xmlContent = matcher.replaceAll(escapedtoBeTested); + return xmlContent; + } + + public static String convertToStatement(String expression, BlocklyType expectedType) { + String varName = VAR_NAME_MAP.get(expectedType); + Assert.assertNotNull(varName, "Variable of type " + expectedType + " not found"); + return varName + " = " + expression + ";"; + } + + + private static String escapeXmlSpecialCharacters(String input) { + return input + .replace("&", "&") + .replace("<", "<") + .replace(">", ">"); + } +} diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3c4ev3/textlyJava_expressions.ast b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3c4ev3/textlyJava_expressions.ast index 9b79bcc165..53f854c9c1 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3c4ev3/textlyJava_expressions.ast +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3c4ev3/textlyJava_expressions.ast @@ -8,7 +8,7 @@ Var [num] := Binary [MINUS, Binary [ADD, Binary [ADD, Binary [ADD, FunctionExpr Var [boolT] := Binary [OR, Binary [OR, Binary [OR, Binary [AND, FunctionExpr [MathNumPropFunct [EVEN, [NumConst[value: 10]]]], FunctionExpr [MathNumPropFunct [ODD, [NumConst[value: 7]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [PRIME, [NumConst[value: 11]]]], FunctionExpr [MathNumPropFunct [WHOLE, [NumConst[value: 8]]]]]], Binary [AND, FunctionExpr [IsListEmptyFunct[value: Var [listN]]], FunctionExpr [MathNumPropFunct [POSITIVE, [NumConst[value: 5]]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [NEGATIVE, [Unary [NEG, NumConst[value: 3]]]]], FunctionExpr [MathNumPropFunct [DIVISIBLE_BY, [NumConst[value: 10], NumConst[value: 5]]]]]] -Var [str] := FunctionExpr [TextJoinFunct [FunctionExpr [ListGetIndex [GET, FIRST, [Var [listColor]]]], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]]]] +Var [str] := FunctionExpr [TextJoinFunct [NumConst[value: 5], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]], BoolConst[value: true]]] Var [listN2] := FunctionExpr [GetSubFunct [GET_SUBLIST, [FROM_START, FROM_START], [Var [listN], NumConst[value: 0], NumConst[value: 3]]]] diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3dev/textlyJava_expressions.ast b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3dev/textlyJava_expressions.ast index 9b79bcc165..53f854c9c1 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3dev/textlyJava_expressions.ast +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3dev/textlyJava_expressions.ast @@ -8,7 +8,7 @@ Var [num] := Binary [MINUS, Binary [ADD, Binary [ADD, Binary [ADD, FunctionExpr Var [boolT] := Binary [OR, Binary [OR, Binary [OR, Binary [AND, FunctionExpr [MathNumPropFunct [EVEN, [NumConst[value: 10]]]], FunctionExpr [MathNumPropFunct [ODD, [NumConst[value: 7]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [PRIME, [NumConst[value: 11]]]], FunctionExpr [MathNumPropFunct [WHOLE, [NumConst[value: 8]]]]]], Binary [AND, FunctionExpr [IsListEmptyFunct[value: Var [listN]]], FunctionExpr [MathNumPropFunct [POSITIVE, [NumConst[value: 5]]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [NEGATIVE, [Unary [NEG, NumConst[value: 3]]]]], FunctionExpr [MathNumPropFunct [DIVISIBLE_BY, [NumConst[value: 10], NumConst[value: 5]]]]]] -Var [str] := FunctionExpr [TextJoinFunct [FunctionExpr [ListGetIndex [GET, FIRST, [Var [listColor]]]], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]]]] +Var [str] := FunctionExpr [TextJoinFunct [NumConst[value: 5], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]], BoolConst[value: true]]] Var [listN2] := FunctionExpr [GetSubFunct [GET_SUBLIST, [FROM_START, FROM_START], [Var [listN], NumConst[value: 0], NumConst[value: 3]]]] diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3lejosv1/textlyJava_expressions.ast b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3lejosv1/textlyJava_expressions.ast index 9b79bcc165..53f854c9c1 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3lejosv1/textlyJava_expressions.ast +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/ev3lejosv1/textlyJava_expressions.ast @@ -8,7 +8,7 @@ Var [num] := Binary [MINUS, Binary [ADD, Binary [ADD, Binary [ADD, FunctionExpr Var [boolT] := Binary [OR, Binary [OR, Binary [OR, Binary [AND, FunctionExpr [MathNumPropFunct [EVEN, [NumConst[value: 10]]]], FunctionExpr [MathNumPropFunct [ODD, [NumConst[value: 7]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [PRIME, [NumConst[value: 11]]]], FunctionExpr [MathNumPropFunct [WHOLE, [NumConst[value: 8]]]]]], Binary [AND, FunctionExpr [IsListEmptyFunct[value: Var [listN]]], FunctionExpr [MathNumPropFunct [POSITIVE, [NumConst[value: 5]]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [NEGATIVE, [Unary [NEG, NumConst[value: 3]]]]], FunctionExpr [MathNumPropFunct [DIVISIBLE_BY, [NumConst[value: 10], NumConst[value: 5]]]]]] -Var [str] := FunctionExpr [TextJoinFunct [FunctionExpr [ListGetIndex [GET, FIRST, [Var [listColor]]]], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]]]] +Var [str] := FunctionExpr [TextJoinFunct [NumConst[value: 5], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]], BoolConst[value: true]]] Var [listN2] := FunctionExpr [GetSubFunct [GET_SUBLIST, [FROM_START, FROM_START], [Var [listN], NumConst[value: 0], NumConst[value: 3]]]] diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/xNN/textlyJava_expressions.ast b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/xNN/textlyJava_expressions.ast index a5d125a9e0..767fcf9674 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/xNN/textlyJava_expressions.ast +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/astGenerated/xNN/textlyJava_expressions.ast @@ -8,7 +8,7 @@ Var [num] := Binary [MINUS, Binary [ADD, Binary [ADD, Binary [ADD, FunctionExpr Var [boolT] := Binary [OR, Binary [OR, Binary [OR, Binary [AND, FunctionExpr [MathNumPropFunct [EVEN, [NumConst[value: 10]]]], FunctionExpr [MathNumPropFunct [ODD, [NumConst[value: 7]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [PRIME, [NumConst[value: 11]]]], FunctionExpr [MathNumPropFunct [WHOLE, [NumConst[value: 8]]]]]], Binary [AND, FunctionExpr [IsListEmptyFunct[value: Var [listN]]], FunctionExpr [MathNumPropFunct [POSITIVE, [NumConst[value: 5]]]]]], Binary [AND, FunctionExpr [MathNumPropFunct [NEGATIVE, [Unary [NEG, NumConst[value: 3]]]]], FunctionExpr [MathNumPropFunct [DIVISIBLE_BY, [NumConst[value: 10], NumConst[value: 5]]]]]] -Var [str] := FunctionExpr [TextJoinFunct [FunctionExpr [ListGetIndex [GET, FIRST, [Var [listColor]]]], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]]]] +Var [str] := FunctionExpr [TextJoinFunct [NumConst[value: 5], StringConst[value: Hello], FunctionExpr [MathCastCharFunct[value: NumConst[value: 65]]], BoolConst[value: true]]] Var [listN2] := FunctionExpr [GetSubFunct [GET_SUBLIST, [FROM_START, FROM_START], [Var [listN], NumConst[value: 0], NumConst[value: 3]]]] diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3c4ev3/textlyJava_expressions.cpp b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3c4ev3/textlyJava_expressions.cpp index 4333234dd1..83bea5ed9c 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3c4ev3/textlyJava_expressions.cpp +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3c4ev3/textlyJava_expressions.cpp @@ -32,7 +32,7 @@ int main () { ___num = ( exp(2) + sin(M_PI / 180.0 * (90)) ) - ( ((rand() % (int) ((1) - (10))) + (1)) * ceil(2.3) ); ___num = ( ( ( _getListSum(___listN) + _getListElementByIndex(___listN, 0) ) + _getFirstOccuranceOfElement(___listN, 0) ) + _getListElementByIndex(___listN, 0) ) - _getAndRemoveListElementByIndex(___listN2, 1); ___boolT = ( ( ( (fmod(10, 2) == 0) && (fmod(7, 2) != 0) ) || ( _isPrime(11) && (8 == floor(8)) ) ) || ( ___listN.empty() && (5 > 0) ) ) || ( (- (3) < 0) && (fmod(10,5) == 0) ); - ___str = ToString(_getListElementByIndex(___listColor, 0)) + ToString("Hello") + ToString((char)(int)(65)); + ___str = ToString(5) + ToString("Hello") + ToString((char)(int)(65)) + ToString(true); ___listN2 = _getSubList(___listN, 0, 3); ___color = Blue; ___color = Green; diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3dev/textlyJava_expressions.py b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3dev/textlyJava_expressions.py index 6569d579ad..193f8ea638 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3dev/textlyJava_expressions.py +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3dev/textlyJava_expressions.py @@ -39,7 +39,7 @@ def run(): ___num = ( math.exp(2) + math.sin(90) ) - ( _randInt(1, 10) * math.ceil(float(2.3)) ) ___num = ( ( ( sum(___listN) + ___listN[0] ) + ___listN.index(0) ) + ___listN[0] ) - ___listN2.pop(1) ___boolT = ( ( ( (10 % 2) == 0 and (7 % 2) == 1 ) or ( _isPrime(11) and (8 % 1) == 0 ) ) or ( not ___listN and 5 > 0 ) ) or ( - (3) < 0 and (10 % 5) == 0 ) - ___str = "".join(str(arg) for arg in [___listColor[0], "Hello", chr((int)(65))]) + ___str = "".join(str(arg) for arg in [5, "Hello", chr((int)(65)), True]) ___listN2 = ___listN[0:3] ___color = 'blue' ___color = 'green' diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3lejosv1/textlyJava_expressions.java b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3lejosv1/textlyJava_expressions.java index 0e364ef3e0..af2a04a116 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3lejosv1/textlyJava_expressions.java +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/ev3lejosv1/textlyJava_expressions.java @@ -60,7 +60,7 @@ public void run() throws Exception { ___num = ( (float) Math.exp(2) + (float) Math.sin(90) ) - ( ( Math.round(Math.random() * ((10) - (1))) + (1) ) * (float) Math.ceil(((float) 2.3)) ); ___num = ( ( ( _sum(___listN) + ___listN.get(0) ) + ___listN.indexOf( (float) 0) ) + ___listN.get( (int) (0)) ) - ___listN2.remove( (int) (1)); ___boolT = ( ( ( (10 % 2 == 0) && (7 % 2 == 1) ) || ( _isPrime( (int) 11) && (8 % 1 == 0) ) ) || ( ___listN.isEmpty() && (5 > 0) ) ) || ( (- (3) < 0) && (10 % 5 == 0) ); - ___str = String.valueOf(___listColor.get( (int) (0))) + String.valueOf("Hello") + String.valueOf(String.valueOf((char)(int)(65))); + ___str = String.valueOf(5) + String.valueOf("Hello") + String.valueOf(String.valueOf((char)(int)(65))) + String.valueOf(true); ___listN2 = new ArrayList<>(___listN.subList((int) 0, (int) 3)); ___color = PickColor.BLUE; ___color = PickColor.GREEN; diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/xNN/textlyJava_expressions.java b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/xNN/textlyJava_expressions.java index 0e364ef3e0..5ab9f81b2f 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/xNN/textlyJava_expressions.java +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/_expected/robotSpecific/targetLanguage/xNN/textlyJava_expressions.java @@ -30,7 +30,7 @@ public class NEPOprog { public static void main(String[] args) { try { - brickConfiguration = new EV3Configuration.Builder() + brickConfiguration = new EV3Configuration.Builder() .setWheelDiameter(5.6) .setTrackWidth(18.0) .addActor(ActorPort.B, new Actor(ActorType.LARGE, true, DriveDirection.FOREWARD, MotorSide.RIGHT)) @@ -60,7 +60,7 @@ public void run() throws Exception { ___num = ( (float) Math.exp(2) + (float) Math.sin(90) ) - ( ( Math.round(Math.random() * ((10) - (1))) + (1) ) * (float) Math.ceil(((float) 2.3)) ); ___num = ( ( ( _sum(___listN) + ___listN.get(0) ) + ___listN.indexOf( (float) 0) ) + ___listN.get( (int) (0)) ) - ___listN2.remove( (int) (1)); ___boolT = ( ( ( (10 % 2 == 0) && (7 % 2 == 1) ) || ( _isPrime( (int) 11) && (8 % 1 == 0) ) ) || ( ___listN.isEmpty() && (5 > 0) ) ) || ( (- (3) < 0) && (10 % 5 == 0) ); - ___str = String.valueOf(___listColor.get( (int) (0))) + String.valueOf("Hello") + String.valueOf(String.valueOf((char)(int)(65))); + ___str = String.valueOf(5) + String.valueOf("Hello") + String.valueOf(String.valueOf((char)(int)(65))) + String.valueOf(true); ___listN2 = new ArrayList<>(___listN.subList((int) 0, (int) 3)); ___color = PickColor.BLUE; ___color = PickColor.GREEN; diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/ev3/textlyJava_expressions.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/ev3/textlyJava_expressions.xml index 4a93ef782d..5af32c7269 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/ev3/textlyJava_expressions.xml +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/ev3/textlyJava_expressions.xml @@ -1,35 +1,376 @@ -FALSE{"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]}numNumber0boolTBooleanTRUEstrStringcolorColour#FFFFFFboolFBooleanFALSEconnConnectionlistNArray_NumberNumber000listN2Array_NumberNumber000listConnArray_ConnectionConnectionlistColorArray_ColourColour#FFFFFF#FFFFFF#FFFFFFnumexp(2) + sin(90) - randomInt(1,10) * ceil(2.3)Numbernumsum(listN) + randomItem(listN) + indexOfFirst(listN, 0)+ getFirst(listN) - getAndRemove(listN2, 1)NumberboolTisEven(10) && isOdd(7) || isPrime(11) && isWhole(8) || isEmpty(listN) && isPositive(5) || isNegative(-3) && isDivisibleBy(10, 5) BooleanstrcreateTextWith(getFirst(listColor), "Hello", castToChar(65))StringlistN2subList(listN, 0, 3)Array_Numbercolor#rgb(0057a6)Colourcolor#greenColournumev3.getSpeedMotor(B)NumberboolTev3.ultrasonicSensor.getPresence(4)BooleanlistN2ev3.colorSensor(rgb, 3)Array_NumberboolTev3.keysSensor.isPressed(up)Booleannumev3.gyroSensor.getAngle(2)Numberconnev3.connectToRobot("hola")Connectionstrev3.receiveMessage(conn)Stringconnev3.waitForConnection()Connection - - - 5.6 - 18 - - - - - - - - - - - - - - - TRUE - OFF - RIGHT - - - - - TRUE - OFF - LEFT - - - - - - \ No newline at end of file + + + + + + + FALSE + + {"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]} + + + + + num + Number + + + 0 + + + + + + boolT + Boolean + + + TRUE + + + + + + str + String + + + + + + + + + color + Colour + + + #FFFFFF + + + + + + boolF + Boolean + + + FALSE + + + + + + conn + Connection + + + + + + + listN + Array_Number + + + + Number + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + listN2 + Array_Number + + + + Number + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + listConn + Array_Connection + + + + Connection + + + + + + + + + + + + + + + listColor + Array_Colour + + + + Colour + + + #FFFFFF + + + + + #FFFFFF + + + + + #FFFFFF + + + + + + + + + + num + + + + exp(2) + sin(90) - randomInt(1,10) * ceil(2.3) + Number + + + + + + num + + + + sum(listN) + randomItem(listN) + indexOfFirst(listN, 0)+ getFirst(listN) - getAndRemove(listN2, 1) + Number + + + + + + boolT + + + + isEven(10) && isOdd(7) || isPrime(11) && isWhole(8) || isEmpty(listN) && + isPositive(5) || isNegative(-3) && isDivisibleBy(10, 5) + + Boolean + + + + + + str + + + + createTextWith(5, "Hello", castToChar(65), true) + String + + + + + + listN2 + + + + subList(listN, 0, 3) + Array_Number + + + + + + color + + + + #rgb(0057a6) + Colour + + + + + + color + + + + #green + Colour + + + + + + num + + + + ev3.getSpeedMotor(B) + Number + + + + + + boolT + + + + ev3.ultrasonicSensor.getPresence(4) + Boolean + + + + + + listN2 + + + + ev3.colorSensor(rgb, 3) + Array_Number + + + + + + boolT + + + + ev3.keysSensor.isPressed(up) + Boolean + + + + + + num + + + + ev3.gyroSensor.getAngle(2) + Number + + + + + + conn + + + + ev3.connectToRobot("hola") + Connection + + + + + + str + + + + ev3.receiveMessage(conn) + String + + + + + + conn + + + + ev3.waitForConnection() + Connection + + + + + + + + + + + 5.6 + 18 + + + + + + + + + + + + + + + TRUE + OFF + RIGHT + + + + + TRUE + OFF + LEFT + + + + + + + \ No newline at end of file diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramExprEval.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramExprEval.xml index b689f176f3..e36e96f64f 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramExprEval.xml +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramExprEval.xml @@ -1,55 +1,227 @@ -TRUE{"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]}numNumber0boolTBooleanTRUEboolFBooleanFALSElistNArray_NumberNumber000strStringlistN2Array_NumberNumber000000imaImageHEARTlistImaArray_ImageImageHEARTHEARTHEART--VAR-NAME----EVAL----TYPE-- - - - _S - - - - - undefined - - - - - _LO - - - - - _T - - - - - A - A - - - - - _B - - - - - B - B - - - - - _A - - - - - _C - - - - - _L - - - - \ No newline at end of file + + + + + + + TRUE + + {"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]} + + + + + num + Number + + + 0 + + + + + + boolT + Boolean + + + TRUE + + + + + + boolF + Boolean + + + FALSE + + + + + + listN + Array_Number + + + + Number + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + str + String + + + + + + + + + listN2 + Array_Number + + + + Number + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + 0 + + + + + + + + ima + Image + + + HEART + + + + + + listIma + Array_Image + + + + Image + + + HEART + + + + + HEART + + + + + HEART + + + + + + + + + + --VAR-NAME-- + + + + --TO-BE-TESTED-- + --TYPE-- + + + + + + + + + + + _S + + + + + undefined + + + + + _LO + + + + + _T + + + + + A + A + + + + + _B + + + + + B + B + + + + + _A + + + + + _C + + + + + _L + + + + + \ No newline at end of file diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramStmtExpr.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramStmtExpr.xml index 28211de6f5..c158b25c76 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramStmtExpr.xml +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/templateProgramStmtExpr.xml @@ -155,7 +155,7 @@ - + --TO-BE-TESTED-- diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextRep.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextRep.xml deleted file mode 100644 index 531fee4b04..0000000000 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextRep.xml +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - TRUE - - {"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]} - - - - - s - Number - - - 0 - - - - - - bt - Boolean - - - TRUE - - - - - - bf - Boolean - - - FALSE - - - - - - listN - Array_Number - - - - Number - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - t - String - - - - - - - - - listN2 - Array_Number - - - - Number - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - - for ( Boolean i=1; i<10; i++){}; - - - - - - - - - _S - - - - - undefined - - - - - _LO - - - - - _T - - - - - A - A - - - - - _B - - - - - B - B - - - - - _A - - - - - _C - - - - - _L - - - - - diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyExpr.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyExpr.xml deleted file mode 100644 index 769d4334d3..0000000000 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyExpr.xml +++ /dev/null @@ -1,55 +0,0 @@ -TRUE{"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]}numNumber0boolTBooleanTRUEboolFBooleanFALSElistNArray_NumberNumber000strStringlistN2Array_NumberNumber000000imaImageHEARTlistImaArray_ImageImageHEARTHEARTHEARTstrcastToChar(65)String - - - _S - - - - - undefined - - - - - _LO - - - - - _T - - - - - A - A - - - - - _B - - - - - B - B - - - - - _A - - - - - _C - - - - - _L - - - - diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyStmt.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyStmt.xml deleted file mode 100644 index b81bc8e964..0000000000 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/microbitv2/textly/testTextlyStmt.xml +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - TRUE - - {"learningRate":0.03,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]} - - - - - num - Number - - - 0 - - - - - - boolT - Boolean - - - TRUE - - - - - - boolF - Boolean - - - FALSE - - - - - - listN - Array_Number - - - - Number - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - str - String - - - - - - - - - listN2 - Array_Number - - - - Number - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - ima - Image - - - HEART - - - - - - listIma - Array_Image - - - - Image - - - HEART - - - - - HEART - - - - - HEART - - - - - - - - - listN = subListFromEndToLast(listN2,3,3); - - - - - - - - - _S - - - - - undefined - - - - - _LO - - - - - _T - - - - - A - A - - - - - _B - - - - - B - B - - - - - _A - - - - - _C - - - - - _L - - - - - A2 - 10 - - - - - S - 0 - - - - - S2 - 1 - - - - - diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramExprEval.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramExprEval.xml index 9faed542c7..012f2c8b1f 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramExprEval.xml +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramExprEval.xml @@ -56,7 +56,7 @@ - --EVAL-- + --TO-BE-TESTED-- --TYPE-- diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramStmtExpr.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramStmtExpr.xml index 8e4cdd3783..b3e3ef9bd1 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramStmtExpr.xml +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/templateProgramStmtExpr.xml @@ -1 +1,97 @@ -FALSEnumNumber0strStringboolTBooleanTRUEcolorColour#FFFFFEWSWRTWIW2T2W1 \ No newline at end of file + + + + + + + FALSE + + + + num + Number + + + 0 + + + + + + str + String + + + + + + + + + boolT + Boolean + + + TRUE + + + + + + color + Colour + + + #FFFFFE + + + + + + + --TO_BE-TESTED-- + + + + + + + + + W + + + + + S + W + + + + + R + + + + + T + W + + + + + I + W + 2 + + + + + T2 + W + 1 + + + + + \ No newline at end of file diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/testTextlyStmt.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/testTextlyStmt.xml deleted file mode 100644 index 80d01a7d0d..0000000000 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/wedo/textly/testTextlyStmt.xml +++ /dev/null @@ -1 +0,0 @@ -FALSEnumNumber0strStringboolTBooleanTRUEcolorColour#FFFFFEwedo.turnRgbOff(R);WSWRTWIW2T2W1 diff --git a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/xNN/textlyJava_expressions.xml b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/xNN/textlyJava_expressions.xml index c1c249aead..f8ff39c410 100644 --- a/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/xNN/textlyJava_expressions.xml +++ b/OpenRobertaServer/src/test/resources/crossCompilerTests/robotSpecific/xNN/textlyJava_expressions.xml @@ -1,3 +1,39 @@ FALSE - {"learningRate":0.00003,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]} - numNumber0boolTBooleanTRUEstrStringcolorColour#FFFFFFboolFBooleanFALSEconnConnectionlistNArray_NumberNumber000listN2Array_NumberNumber000listConnArray_ConnectionConnectionlistColorArray_ColourColour#FFFFFF#FFFFFF#FFFFFFnumexp(2) + sin(90) - randomInt(1,10) * ceil(2.3)Numbernumsum(listN) + randomItem(listN) + indexOfFirst(listN, 0)+ getFirst(listN) - getAndRemove(listN2, 1)NumberboolTisEven(10) && isOdd(7) || isPrime(11) && isWhole(8) || isEmpty(listN) && isPositive(5) || isNegative(-3) && isDivisibleBy(10, 5) BooleanstrcreateTextWith(getFirst(listColor), "Hello", castToChar(65))StringlistN2subList(listN, 0, 3)Array_Numbercolor#rgb(0057a6)Colourcolor#greenColournumev3.getSpeedMotor(B)NumberboolTev3.ultrasonicSensor.getPresence(4)BooleanlistN2ev3.colorSensor(rgb, 3)Array_NumberboolTev3.keysSensor.isPressed(up)Booleannumev3.gyroSensor.getAngle(2)Numberconnev3.connectToRobot("hola")Connectionstrev3.receiveMessage(conn)Stringconnev3.waitForConnection()Connection5.618TRUEOFFRIGHTTRUEOFFLEFT \ No newline at end of file + {"learningRate":0.00003,"regularizationRate":0,"noise":0,"batchSize":10,"discretize":false,"percTrainData":50,"activationKey":"linear","activation":{},"regularization":null,"initUntil":null,"collectStats":false,"numHiddenLayers":0,"networkShape":[],"weights":[[["1"]],[[]]],"biases":[["0"],["0"]],"precision":"2","weightArcMaxSize":8,"weightSuppressMultOp":true,"inputs":["n1"],"outputs":["n2"],"hiddenNeurons":[]} + numNumber0boolTBooleanTRUEstrStringcolorColour#FFFFFFboolFBooleanFALSEconnConnectionlistNArray_NumberNumber000listN2Array_NumberNumber000listConnArray_ConnectionConnectionlistColorArray_ColourColour#FFFFFF#FFFFFF#FFFFFFnumexp(2) + sin(90) - randomInt(1,10) * ceil(2.3)Numbernumsum(listN) + randomItem(listN) + indexOfFirst(listN, 0)+ getFirst(listN) - getAndRemove(listN2, 1)NumberboolTisEven(10) && isOdd(7) || isPrime(11) && isWhole(8) || isEmpty(listN) && + isPositive(5) || isNegative(-3) && isDivisibleBy(10, 5) + BooleanstrcreateTextWith(5, "Hello", castToChar(65),true)StringlistN2subList(listN, 0, 3)Array_Numbercolor#rgb(0057a6)Colourcolor#greenColournumev3.getSpeedMotor(B)NumberboolTev3.ultrasonicSensor.getPresence(4)BooleanlistN2ev3.colorSensor(rgb, 3)Array_NumberboolTev3.keysSensor.isPressed(up)Booleannumev3.gyroSensor.getAngle(2)Numberconnev3.connectToRobot("hola")Connectionstrev3.receiveMessage(conn)Stringconnev3.waitForConnection()Connection + + + 5.6 + 18 + + + + + + + + + + + + + + + TRUE + OFF + RIGHT + + + + + TRUE + OFF + LEFT + + + + + + \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/index.html b/OpenRobertaServer/staticResources/xmlTest/index.html deleted file mode 100644 index 2714a4f790..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/index.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - XML Unit Tests - - -
-
- - - - - - - - - -
TEST 1 (explanation)
TEST 2 (explanation)
TEST 3 (explanation)
TEST 4 (explanation)
TEST 5 (explanation)
TEST 6 (explanation)
TEST 7 (explanation)
TEST 8 (explanation)
-
-
- Status -
-
- Outcome -
-
-
    -
-
- - \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/roberta_test.js b/OpenRobertaServer/staticResources/xmlTest/roberta_test.js deleted file mode 100644 index 2efe5c6e2a..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/roberta_test.js +++ /dev/null @@ -1,137 +0,0 @@ -function removeAttributeDom(xmlDom) { - for (var i = 0, x; x = xmlDom.childNodes[i]; i++) { - if (x.nodeName == "#text") - continue; - x.removeAttribute("id"); - removeAttributeDom(x); - } -} - -function start() { - var toolbox = document.getElementById('toolbox'); - Blockly.inject(document.getElementById('blocklyDiv'), { - path : '../', - toolbox : toolbox, - realtime : false, - realtimeOptions : { - clientId : 'YOUR CLIENT ID GOES HERE', - chatbox : { - elementId : 'chatbox' - }, - collabElementId : 'collaborators' - } - }); -} - -var setReady = function(value) { - $('#ready').text(value); -}; - -var setResultOk = function() { - $('#result').text('asExpected'); -}; - -var setResultError = function() { - $('#result').text('error'); -}; -var loadXMLString = function(xmlPath) { - if (window.XMLHttpRequest) { - xhttp = new XMLHttpRequest(); - } else { - xhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } - - xhttp.open("GET", xmlPath, false); - xhttp.send(); - - return xhttp.responseText; -}; - -var DomToString = function(xmlDoc) { - var oSerializer = new XMLSerializer(); - return oSerializer.serializeToString(xmlDoc); -}; - -var wrapOn = function(id, callback) { - var wrapped = function(e) { - setReady('running'); - callback(e); - }; - $(id).on('click', wrapped); -}; - -function test(path) { - var xmlTextSource = loadXMLString(path); - var xmlDomSource = Blockly.Xml.textToDom(xmlTextSource); - removeAttributeDom(xmlDomSource); - xmlTextSource = DomToString(xmlDomSource); - - Blockly.mainWorkspace.clear(); - Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xmlDomSource); - - var xmlDomResult = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace); - removeAttributeDom(xmlDomResult); - var xmlTextResult = Blockly.Xml.domToPrettyText(xmlDomResult); - console.log(xmlTextSource.trim()); - console.log(xmlTextResult.trim()); - if (xmlTextSource.trim() == xmlTextResult.trim()) - setResultOk(); - else - setResultError(); - setReady('ready'); -} - -var test1 = function() { - test('test_1.xml'); -}; - -var test2 = function() { - var xmlTextSource = loadXMLString('test_1.xml'); - var xmlDomSource = Blockly.Xml.textToDom(xmlTextSource); - // removeAttributeDom(xmlDomSource); - xmlTextSource = DomToString(xmlDomSource); - - Blockly.mainWorkspace.clear(); - Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xmlDomSource); - - var xmlDomResult = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace); - // removeAttributeDom(xmlDomResult); - var xmlTextResult = Blockly.Xml.domToPrettyText(xmlDomResult); - if (xmlTextSource == xmlTextResult) - setResultOk(); - else - setResultError(); - setReady('ready'); -}; - -var test3 = function() { - test('test_3.xml'); -}; - -var test4 = function() { - test('test_4.xml'); -}; -var test5 = function() { - test('test_5.xml'); -}; -var test6 = function() { - test('test_6.xml'); -}; -var test7 = function() { - test('test_7.xml'); -}; -var test8 = function() { - test('test_8.xml'); -}; -var init = function() { - wrapOn('#test1', test1); - wrapOn('#test2', test2); - wrapOn('#test3', test3); - wrapOn('#test4', test4); - wrapOn('#test5', test5); - wrapOn('#test6', test6); - wrapOn('#test7', test7); - wrapOn('#test8', test8); -}; - -$(document).ready(init); diff --git a/OpenRobertaServer/staticResources/xmlTest/test_1.xml b/OpenRobertaServer/staticResources/xmlTest/test_1.xml deleted file mode 100644 index c38697e8a9..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_1.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - B - - - 30 - - - - - - - 1 - - - - - item - - - - - - - - - - GREEN - ON - - - diff --git a/OpenRobertaServer/staticResources/xmlTest/test_3.xml b/OpenRobertaServer/staticResources/xmlTest/test_3.xml deleted file mode 100644 index 1e97e1f0aa..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_3.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - B - ROTATIONS - - - 30 - - - - - 1 - - - - - FOREWARD - - - 50 - - - - - 20 - - - - - A - FLOAT - - - - - 300 - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - - EQ - - - - TOUCH_PRESSED - 1 - - - - - TRUE - - - - - - - - - \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/test_4.xml b/OpenRobertaServer/staticResources/xmlTest/test_4.xml deleted file mode 100644 index 74db029347..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_4.xml +++ /dev/null @@ -1,221 +0,0 @@ - - - - - - SET - FROM_START - - - liste - - - - - 30 - - - - - 30 - - - - - item - - - - - - - - liste - - - FIRST - - - text - - - - - - - - - - - - i - - - FOREWARD - - - 50 - - - - - 20 - - - - - A - FLOAT - - - - - 300 - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - - EQ - - - - TOUCH_PRESSED - 1 - - - - - TRUE - - - - - - - - - B - ROTATIONS - - - 30 - - - - - 1 - - - - - - - - - - - EQ - - - 4 - - - - - 30 - - - - - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/test_5.xml b/OpenRobertaServer/staticResources/xmlTest/test_5.xml deleted file mode 100644 index c39072f13a..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_5.xml +++ /dev/null @@ -1,172 +0,0 @@ - - - - - FOREWARD - - - 50 - - - - - 20 - - - - - A - FLOAT - - - - - 300 - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - - EQ - - - - TOUCH_PRESSED - 1 - - - - - TRUE - - - - - - - - - B - ROTATIONS - - - 30 - - - - - 1 - - - - - - - - - - - EQ - - - 4 - - - - - 30 - - - - - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - - - - EQ - - - 300 - - - - - 100 - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/test_6.xml b/OpenRobertaServer/staticResources/xmlTest/test_6.xml deleted file mode 100644 index b7b3aa15be..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_6.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - B - - - 30 - - - - - B - ROTATIONS - - - 30 - - - - - 1 - - - - - B - - - 30 - - - - - A - FLOAT - - - item - - - B - - - - - FOREWARD - - - 50 - - - - - RIGHT - - - 50 - - - - - RIGHT - - - 50 - - - - - 90 - - - - - - FOREWARD - - - 50 - - - - - 20 - - - - - \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/test_7.xml b/OpenRobertaServer/staticResources/xmlTest/test_7.xml deleted file mode 100644 index 98cbfa12f4..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_7.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - Hallo - - - - - 0 - - - - - 0 - - - - - SMILEY1 - - - 0 - - - - - 0 - - - - - - - - 300 - - - - - 100 - - - - - SOUNDFILE1 - - - GREEN - ON - - - - - 50 - - - - - - - \ No newline at end of file diff --git a/OpenRobertaServer/staticResources/xmlTest/test_8.xml b/OpenRobertaServer/staticResources/xmlTest/test_8.xml deleted file mode 100644 index 42256ced7f..0000000000 --- a/OpenRobertaServer/staticResources/xmlTest/test_8.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - 1 - - - - - item - - - - - - - - item - - - - - - - - - - - - item - - - - - - - - - - - - - - 1 - - - - - item - - - - - - - - - - item - - - - - - - - - - - i - - - 1 - - - - - 10 - - - - - 1 - - - - - item - - - - - - - - - - \ No newline at end of file diff --git a/RobotEV3/src/main/java/de/fhg/iais/roberta/visitor/validate/Ev3TypecheckVisitor.java b/RobotEV3/src/main/java/de/fhg/iais/roberta/visitor/validate/Ev3TypecheckVisitor.java index 87f1cc3131..3d7639e586 100644 --- a/RobotEV3/src/main/java/de/fhg/iais/roberta/visitor/validate/Ev3TypecheckVisitor.java +++ b/RobotEV3/src/main/java/de/fhg/iais/roberta/visitor/validate/Ev3TypecheckVisitor.java @@ -143,6 +143,7 @@ public BlocklyType visitColorSensor(ColorSensor colorSensor) { @Override public BlocklyType visitShowTextAction(ShowTextAction showTextAction) { + // really ANY, not PRIM only return Sig.of(BlocklyType.VOID, BlocklyType.ANY, BlocklyType.NUMBER, BlocklyType.NUMBER).typeCheckPhrases(showTextAction, this, showTextAction.msg, showTextAction.x, showTextAction.y); } diff --git a/RobotMbed/src/main/java/de/fhg/iais/roberta/visitor/validate/MicrobitV2TypecheckVisitor.java b/RobotMbed/src/main/java/de/fhg/iais/roberta/visitor/validate/MicrobitV2TypecheckVisitor.java index 2bcd74949a..5ddc4c21d9 100644 --- a/RobotMbed/src/main/java/de/fhg/iais/roberta/visitor/validate/MicrobitV2TypecheckVisitor.java +++ b/RobotMbed/src/main/java/de/fhg/iais/roberta/visitor/validate/MicrobitV2TypecheckVisitor.java @@ -50,7 +50,7 @@ public BlocklyType visitClearDisplayAction(ClearDisplayAction clearDisplayAction @Override public BlocklyType visitDisplayTextAction(DisplayTextAction displayTextAction) { - return Sig.of(BlocklyType.VOID, BlocklyType.ANY).typeCheckPhrases(displayTextAction, this, displayTextAction.msg); + return Sig.of(BlocklyType.VOID, BlocklyType.PRIM).typeCheckPhrases(displayTextAction, this, displayTextAction.msg); } @Override diff --git a/RobotWeDo/src/main/java/de/fhg/iais/roberta/visitor/validate/WedoTypecheckVisitor.java b/RobotWeDo/src/main/java/de/fhg/iais/roberta/visitor/validate/WedoTypecheckVisitor.java index 0fd8acd69f..608760d137 100644 --- a/RobotWeDo/src/main/java/de/fhg/iais/roberta/visitor/validate/WedoTypecheckVisitor.java +++ b/RobotWeDo/src/main/java/de/fhg/iais/roberta/visitor/validate/WedoTypecheckVisitor.java @@ -28,6 +28,7 @@ public BlocklyType visitClearDisplayAction(ClearDisplayAction clearDisplayAction @Override public BlocklyType visitShowTextAction(ShowTextAction showTextAction) { + // really ANY, not PRIM only return Sig.of(BlocklyType.VOID, BlocklyType.ANY).typeCheckPhrases(showTextAction, this, showTextAction.msg); }