Browse Source

Patch conformance_delete with new corner cases

Yentl Van Tendeloo 7 years ago
parent
commit
1de1cc0f38
2 changed files with 49 additions and 22 deletions
  1. 31 17
      bootstrap/core_algorithm.alc
  2. 18 5
      unit/test_all.py

+ 31 - 17
bootstrap/core_algorithm.alc

@@ -2363,25 +2363,39 @@ String function cmd_conformance_delete(model_name : String, metamodel_name : Str
 	// Remove an existing instanceOf relation
 	if (get_entry_id(model_name) != ""):
 		if (get_entry_id(metamodel_name) != ""):
-			Element links
-			String link
-			String found_typing_name
+			if (bool_not(read_type(core, get_entry_id(model_name)) == "Folder")):
+				if (bool_not(read_type(core, get_entry_id(metamodel_name)) == "Folder")):
+					Element links
+					String link
+					String found_typing_name
+					Element typings
+
+					links = get_instanceOf_links(get_entry_id(model_name), get_entry_id(metamodel_name))
+					while (set_len(links) > 0):
+						// Iterate over each link and remove if type mapping matches
+						link = set_pop(links)
+						typings = allAssociationDestinations(core, link, "typing")
+						if (set_len(typings) > 0):
+							found_typing_name = set_pop(typings)
+						else:
+							found_typing_name = ""
 
-			links = get_instanceOf_links(get_entry_id(model_name), get_entry_id(metamodel_name))
-			while (set_len(links) > 0):
-				// Iterate over each link and remove if type mapping matches
-				link = set_pop(links)
-				found_typing_name = anAssociationDestination(core, link, "typing")
-				if (bool_and(typemapping_name == "", found_typing_name == "")):
-					// Remove only the link
-					model_delete_element(core, link)
+						if (bool_and(typemapping_name == "", found_typing_name == "")):
+							// Remove only the link
+							model_delete_element(core, link)
+						elif found_typing_name == "":
+							continue!
+						else:
+							found_typing_name = read_attribute(core, found_typing_name, "name")
+							if (found_typing_name == typemapping_name):
+								// Type mappings match, so remove link
+								// Optional: type mapping model can also be removed, but is potentially in use as it is itself a model!
+								model_delete_element(core, link)
+					return "Success"!
 				else:
-					found_typing_name = read_attribute(core, anAssociationDestination(core, link, "typing"), "name")
-					if (found_typing_name == typemapping_name):
-						// Type mappings match, so remove link
-						// Optional: type mapping model can also be removed, but is potentially in use as it is itself a model!
-						model_delete_element(core, link)
-			return "Success"!
+					return "Not a model: " + metamodel_name!
+			else:
+				return "Not a model: " + model_name!
 		else:
 			return "Model not found: " + metamodel_name!
 	else:

+ 18 - 5
unit/test_all.py

@@ -3446,7 +3446,7 @@ class TestModelverse(unittest.TestCase):
             assert t[2] == None
 
         # Now try one with the actual name
-        actual_name = [i for i in model_types("users/user/test/a") if i[0] == "formalisms/Bottom" and i[1] != None][0]
+        actual_name = [i for i in model_types("users/user/test/a") if i[0] == "formalisms/Bottom" and i[1] != None][0][1]
 
         assert len(model_types("users/user/test/a")) == 3
         conformance_delete("users/user/test/a", "formalisms/SimpleClassDiagrams", actual_name)
@@ -3467,10 +3467,9 @@ class TestModelverse(unittest.TestCase):
                 assert t[1] == None
             assert t[2] == None
 
-
-        # Check add of non-existing model
+        # Check non-existing model
         try:
-            conformance_add("users/user/test/b", "formalisms/Bottom")
+            conformance_delete("users/user/test/b", "formalisms/Bottom", "")
             self.fail()
         except UnknownModel:
             pass
@@ -3479,11 +3478,25 @@ class TestModelverse(unittest.TestCase):
         model_add("users/user/test/b", "formalisms/SimpleClassDiagrams")
         before = model_types("users/user/test/b")
         try:
-            conformance_add("users/user/test/b", "formalisms/Bottom2")
+            conformance_delete("users/user/test/b", "formalisms/Bottom2", "")
             self.fail()
         except UnknownModel:
             assert model_types("users/user/test/b") == before
 
+        # Check folder as model
+        try:
+            conformance_delete("users/user/test", "formalisms/Bottom", "")
+            self.fail()
+        except NotAModel:
+            pass
+
+        # Check folder as metamodel
+        try:
+            conformance_delete("users/user/test/a", "formalisms", "")
+            self.fail()
+        except NotAModel:
+            pass
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):