From f5af5f82021f54e62bd82482427684fb100d70a0 Mon Sep 17 00:00:00 2001 From: Daniel Krizian Date: Fri, 1 Jan 2021 12:46:55 -0600 Subject: [PATCH] mocking supports data namespaces within the global namespace --- lib/mock.q | 2 ++ test/test_mock.q | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/mock.q b/lib/mock.q index cfd04c8..0139e2f 100644 --- a/lib/mock.q +++ b/lib/mock.q @@ -9,6 +9,8 @@ mock:{[name;newVal]; name:$[1 = c: count ` vs name; / Create fully qualified name if given a local one ` sv .tst.context,name; + not ` ~ first ` vs name; + ` sv .tst.context,name; (2 = c) and ` ~ first ` vs name; '"Can't mock top-level namespaces!"; name]; diff --git a/test/test_mock.q b/test/test_mock.q index 54e651c..2402ba6 100644 --- a/test/test_mock.q +++ b/test/test_mock.q @@ -23,4 +23,14 @@ should["refuse to mock a top level namespace"]{ mustthrow[()] { `.tst mock ` }; }; + should["support data namespaces within the global namespace"]{ + `..ns.foo set 0; + `ns.foo mock 1; + `ns.bar mock 2; + ns.foo musteq 1; + .tst.restore[]; + (get `..ns.foo) musteq 0; + mustthrow["..ns.bar"] {get `..ns.bar}; + delete ns from `.; + }; };