Pārlūkot izejas kodu

More built-in tests for allInstances: give error when type undefined

Yentl Van Tendeloo 8 gadi atpakaļ
vecāks
revīzija
ae5111a881

BIN
bootstrap/bootstrap.m.gz


+ 13 - 9
bootstrap/object_operations.alc

@@ -11,17 +11,21 @@ Element function allInstances(model : Element, type_name : String):
 	Element keys
 
 	keys = dict_keys(model["model"])
-	type = model["metamodel"]["model"][type_name]
-	result = create_node()
+	if (dict_in(model["metamodel"]["model"], type_name)):
+		type = model["metamodel"]["model"][type_name]
+		result = create_node()
 
-	// TODO more efficient to work backwards: find all instances of an element through the type mapping directly
-	//      must then take into account all inheritance links ourselves...
-	while (0 < list_len(keys)):
-		key = set_pop(keys)
-		if (is_nominal_instance(model, key, type_name)):
-			set_add(result, key)
+		// TODO more efficient to work backwards: find all instances of an element through the type mapping directly
+		//      must then take into account all inheritance links ourselves...
+		while (0 < list_len(keys)):
+			key = set_pop(keys)
+			if (is_nominal_instance(model, key, type_name)):
+				set_add(result, key)
 
-	return result!
+		return result!
+	else:
+		log("No such type in the metamodel!")
+		return create_node()!
 
 Element function selectPossibleIncoming(model : Element, target : String, limit_set : Element):
 	// Find all possible incoming link types for the target model

+ 0 - 1
integration/test_binary2decimal.py

@@ -2,7 +2,6 @@ import unittest
 
 from utils import run_file
 
-
 class TestBinary2Decimal(unittest.TestCase):
     def test_po_binary2decimal(self):
         self.binary2decimal("PO")