Browse Source

Add test for AL_text, which seemingly found a bug for HUTN-uploaded code

Yentl Van Tendeloo 7 years ago
parent
commit
0aaf005fd0
2 changed files with 30 additions and 1 deletions
  1. 2 0
      bootstrap/core_algorithm.alc
  2. 28 1
      unit/test_all.py

+ 2 - 0
bootstrap/core_algorithm.alc

@@ -1068,9 +1068,11 @@ Void function enact_PM(pm : Element, mapping : Element):
 	return !
 
 String function cmd_AL_text(location : String):
+	log("Reading location " + cast_string(location))
 	if location == "":
 		return "Success: \n"!
 	else:
+		log("Code there: " + cast_string(import_node(location + "/__text")))
 		return "Success: " + cast_string(import_node(location + "/__text"))!
 
 String function cmd_help():

+ 28 - 1
unit/test_all.py

@@ -1531,6 +1531,34 @@ class TestModelverse(unittest.TestCase):
         except UnknownElement:
             assert element_list_nice("users/user/test/d") == [{"__type" : "Class", "__id": "A", "lower_cardinality": None, "upper_cardinality": None, "constraint": {"AL": ""}, "name": None, "abstract": None}]
 
+    def test_op_AL_text(self):
+        # Test normal situation with code provided by assignment
+        model_add("users/user/test/b", "formalisms/SimpleClassDiagrams", """
+            Class A {}
+            """)
+        attr_assign_code("users/user/test/b", "A", "constraint", """
+            String function main(value : Element):
+                return "OK"!
+            """)
+        assert AL_text(read_attrs("users/user/test/b", "A")["constraint"]["AL"]).strip() == """
+            String function main(value : Element):
+                return "OK"!
+            """.strip()
+
+        # Test normal situation with code provided by HUTN parser (model)
+        model_add("users/user/test/a", "formalisms/SimpleClassDiagrams", """
+            Class A {
+                constraint = $
+                        String function main(value : Element):
+                            return "OK"!
+                    $
+            }
+            """)
+        assert AL_text(read_attrs("users/user/test/a", "A")["constraint"]["AL"]).strip() == """
+            String function main(value : Element):
+                return "OK"!
+            """.strip()
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):
@@ -1553,7 +1581,6 @@ class TestModelverse(unittest.TestCase):
     def test_op_group_list(self):
     def test_op_conformance_delete(self):
     def test_op_conformance_add(self):
-    def test_op_AL_text(self):
     def test_op_read_outgoing(self):
     def test_op_read_incoming(self):
     def test_op_read_association_source(self):