Browse Source

Added ~ syntax for home folder expansion (+ test)

Yentl Van Tendeloo 7 years ago
parent
commit
6d9a771fd3
2 changed files with 10 additions and 0 deletions
  1. 4 0
      bootstrap/core_algorithm.alc
  2. 6 0
      unit/test_all.py

+ 4 - 0
bootstrap/core_algorithm.alc

@@ -234,6 +234,10 @@ String function get_entry_id(name : String):
 	if (string_get(name, string_len(name) - 1) == "/"):
 		name = string_substr(name, 0, string_len(name) - 1)
 
+	log("Got location: " + name)
+	name = string_replace(name, "~", "users/" + cast_string(read_attribute(core, current_user_id, "name")))
+	log("Rewrote: " + name)
+
 	if (dict_in(caches["models"], name)):
 		if (dict_in(core, caches["models"])):
 			if (full_name(caches["models"][name]) == name):

+ 6 - 0
unit/test_all.py

@@ -5606,6 +5606,12 @@ class TestModelverse(unittest.TestCase):
                           (148.4, "displayYellow"),
                          ]
 
+    def test_userhome_expand(self):
+        assert "my_model" not in model_list("~/test")
+        model_add("~/test/my_model", "formalisms/SimpleClassDiagrams")
+        assert "my_model" in model_list("~/test")
+        assert model_list("~/test") == model_list("users/user/test")
+
     def test_switch_MM(self):
         model_add("users/user/test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
         model_add("users/user/test/my_pn", "users/user/test/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())