Przeglądaj źródła

Add test for removing AL code attribute

Yentl Van Tendeloo 7 lat temu
rodzic
commit
65caa46695
2 zmienionych plików z 44 dodań i 2 usunięć
  1. 0 2
      bootstrap/mini_modify.alc
  2. 44 0
      unit/test_all.py

+ 0 - 2
bootstrap/mini_modify.alc

@@ -133,9 +133,7 @@ String function cmd_attr_add_code(write : Boolean, model : Element, element_name
 			if (set_in(dict_keys(attrs), attr_name)):
 				output("Waiting for code constructors...")
 				Element compiled
-				log("Wait...")
 				compiled = compile_code(input())
-				log("Compiled!")
 				if (is_physical_string(compiled)):
 					return "Compilation error: " + cast_string(compiled)!
 

+ 44 - 0
unit/test_all.py

@@ -1162,6 +1162,50 @@ class TestModelverse(unittest.TestCase):
         except UnknownAttribute:
             pass
 
+    def test_op_attr_delete_code(self):
+        model_add("users/user/test/a", "formalisms/SimpleClassDiagrams", """
+            SimpleAttribute Natural {
+                name = "natural"
+            }
+            SimpleAttribute String {
+                name = "string"
+            }
+
+            Class Place {
+                name = "Place"
+                name : String
+                capacity : Natural
+            }
+            Class Transition {
+                name = "Transition"
+                name : String
+            }
+            Association P2T (Place, Transition) {
+                name = "P2T"
+                weight : Natural
+            }
+            Association T2P (Transition, Place) {
+                name = "T2P"
+                weight : Natural
+            }
+            """)
+
+        # Test what happens if removing a non-existing AL attribute
+        assert read_attrs("users/user/test/a", "Place") == {"constraint": {"AL": ""}, "name": "Place", "abstract": None, "lower_cardinality": None, "upper_cardinality": None}
+        attr_delete("users/user/test/a", "Place", "constraint")
+        assert read_attrs("users/user/test/a", "Place") == {"constraint": {"AL": ""}, "name": "Place", "abstract": None, "lower_cardinality": None, "upper_cardinality": None}
+
+        # Test what happens if removing an existing AL attribute
+        attr_assign_code("users/user/test/a", "Place", "constraint", """
+            String function a(value : Element):
+                return "OK"!
+            """)
+        attrs = read_attrs("users/user/test/a", "Place")
+        assert "AL" in attrs["constraint"]
+        assert attrs["constraint"]["AL"] != ""
+        attr_delete("users/user/test/a", "Place", "constraint")
+        assert read_attrs("users/user/test/a", "Place") == {"constraint": {"AL": ""}, "name": "Place", "abstract": None, "lower_cardinality": None, "upper_cardinality": None}
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):