Skip to content

Commit f5af5f8

Browse files
committed
mocking supports data namespaces within the global namespace
1 parent 90f27c7 commit f5af5f8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/mock.q

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ mock:{[name;newVal];
99
name:$[1 = c: count ` vs name;
1010
/ Create fully qualified name if given a local one
1111
` sv .tst.context,name;
12+
not ` ~ first ` vs name;
13+
` sv .tst.context,name;
1214
(2 = c) and ` ~ first ` vs name;
1315
'"Can't mock top-level namespaces!";
1416
name];

test/test_mock.q

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@
2323
should["refuse to mock a top level namespace"]{
2424
mustthrow[()] { `.tst mock ` };
2525
};
26+
should["support data namespaces within the global namespace"]{
27+
`..ns.foo set 0;
28+
`ns.foo mock 1;
29+
`ns.bar mock 2;
30+
ns.foo musteq 1;
31+
.tst.restore[];
32+
(get `..ns.foo) musteq 0;
33+
mustthrow["..ns.bar"] {get `..ns.bar};
34+
delete ns from `.;
35+
};
2636
};

0 commit comments

Comments
 (0)