@naanlang/naan 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +46 -0
  3. package/dist/env_web.js +431 -0
  4. package/dist/naan.min.js +73 -0
  5. package/frameworks/browser/browser.nlg +30 -0
  6. package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
  7. package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
  8. package/frameworks/browser/sworker.js +192 -0
  9. package/frameworks/browser/terminals.nlg +787 -0
  10. package/frameworks/browser/workers.nlg +386 -0
  11. package/frameworks/client/apiclient.nlg +183 -0
  12. package/frameworks/client/client.nlg +29 -0
  13. package/frameworks/client/psm_client.nlg +572 -0
  14. package/frameworks/common/common.nlg +464 -0
  15. package/frameworks/common/preferences.nlg +131 -0
  16. package/frameworks/common/repltools.nlg +100 -0
  17. package/frameworks/common/watching.nlg +97 -0
  18. package/frameworks/node/apiserver.nlg +399 -0
  19. package/frameworks/node/filesystem.nlg +1012 -0
  20. package/frameworks/node/gitter.nlg +234 -0
  21. package/frameworks/node/node.nlg +81 -0
  22. package/frameworks/node/psm_server.nlg +465 -0
  23. package/frameworks/node/worker.nlg +560 -0
  24. package/frameworks/project/build.nlg +1229 -0
  25. package/frameworks/project/jszip.js +30 -0
  26. package/frameworks/project/jszip.nlg +87 -0
  27. package/frameworks/project/proj_cliser.nlg +139 -0
  28. package/frameworks/project/proj_console.nlg +137 -0
  29. package/frameworks/project/proj_folder.nlg +143 -0
  30. package/frameworks/project/proj_lambda.nlg +137 -0
  31. package/frameworks/project/proj_static.nlg +138 -0
  32. package/frameworks/project/project.nlg +29 -0
  33. package/frameworks/project/projects.nlg +587 -0
  34. package/frameworks/project/uglifyjs.js +1 -0
  35. package/frameworks/project/uglifyjs.nlg +79 -0
  36. package/frameworks/running/debugcom.nlg +163 -0
  37. package/frameworks/running/debugnub.nlg +565 -0
  38. package/frameworks/running/debugutil.nlg +510 -0
  39. package/frameworks/running/executors.nlg +767 -0
  40. package/frameworks/running/running.nlg +151 -0
  41. package/frameworks/running/sourcecode.nlg +346 -0
  42. package/frameworks/running/taskexec.nlg +196 -0
  43. package/frameworks/storage/dbt_pouch.nlg +773 -0
  44. package/frameworks/storage/file_manager.nlg +772 -0
  45. package/frameworks/storage/psm.nlg +326 -0
  46. package/frameworks/storage/psm_dbtables.nlg +814 -0
  47. package/frameworks/storage/resources.nlg +445 -0
  48. package/frameworks/storage/storage.nlg +52 -0
  49. package/lib/browser/env_web.js +431 -0
  50. package/lib/browser/env_webworker.js +146 -0
  51. package/lib/browser/require.js +1653 -0
  52. package/lib/core/naanlib.js +73 -0
  53. package/lib/env_node.js +282 -0
  54. package/lib/env_nodeworker.js +165 -0
  55. package/lib/node_repl.js +25 -0
  56. package/lib/node_repl_init.nlg +52 -0
  57. package/package.json +13 -0
  58. package/plugins/gitClient/clientops.nlg +317 -0
  59. package/plugins/gitClient/gitClient.nlg +63 -0
  60. package/plugins/gitClient/gitutils.nlg +1331 -0
  61. package/plugins/gitClient/minimatch.js +945 -0
  62. package/plugins/gitClient/minimatch_license.txt +15 -0
  63. package/plugins/gitClient/minimatch_readme.md +208 -0
  64. package/plugins/nodeLib/nodeLib.nlg +26 -0
  65. package/plugins/nodeLib/node_cp.nlg +65 -0
  66. package/plugins/nodeLib/node_fs.nlg +137 -0
  67. package/plugins/nodeLib/node_https.nlg +172 -0
  68. package/plugins/nodeLib/node_util.nlg +180 -0
  69. package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
  70. package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
  71. package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
  72. package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
  73. package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
  74. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
  75. package/plugins/serviceAws/aws_cognito.nlg +76 -0
  76. package/plugins/serviceAws/aws_dynamo.nlg +509 -0
  77. package/plugins/serviceAws/aws_lambda.nlg +95 -0
  78. package/plugins/serviceAws/aws_s3.nlg +134 -0
  79. package/plugins/serviceAws/aws_utils.nlg +86 -0
  80. package/plugins/serviceAws/dbt_aws.nlg +769 -0
  81. package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
  82. package/plugins/serviceAws/psm_aws.nlg +258 -0
  83. package/plugins/serviceAws/serviceAws.nlg +38 -0
  84. package/plugins/serviceGitHub/gitops.nlg +522 -0
  85. package/plugins/serviceGitHub/psm_github.nlg +205 -0
  86. package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
  87. package/plugins/serviceGitLab/gitops.nlg +528 -0
  88. package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
  89. package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
  90. package/test/harness.nlg +312 -0
  91. package/test/node_test.js +33 -0
  92. package/test/test_01_core.nlg +768 -0
  93. package/test/test_02_context.nlg +269 -0
  94. package/test/test_03_jsinterop.nlg +137 -0
  95. package/test/test_04_numerics.nlg +450 -0
  96. package/test/test_05_strings.nlg +63 -0
  97. package/test/test_06_lingoparse.nlg +500 -0
  98. package/test/test_07_lingo.nlg +623 -0
@@ -0,0 +1,269 @@
1
+ /*
2
+ * test_02_context.nlg
3
+ * Test
4
+ *
5
+ * Perform basic unit tests for Naan.
6
+ *
7
+ * column positioning: // // !
8
+ *
9
+ * Copyright (c) 2017-2021 by Richard C. Zulch
10
+ *
11
+ */
12
+
13
+
14
+ /*
15
+ * Test Category 2 - Context
16
+ *
17
+ */
18
+
19
+ RegisterTestCategory("context", [
20
+ [ "4+3;", "7" ], // generic first test
21
+
22
+ //
23
+ // rights
24
+ //
25
+
26
+ [ "nsrights();", "Namespace<Test-context>" ],
27
+ [ "nsactive().1;", "Namespace<Lang_Lingo>" ],
28
+ [ "nsrights(nsactive().1);", "Namespace<Test-context>" ],
29
+ [ "list(nsrights(nsactive().1),nsrights());>", "(Namespace<Test-context> Namespace<Test-context>)" ],
30
+ [ "list(sudo(nsrights(nsactive().1)),nsrights());>", "(Namespace<NaanRoot> Namespace<Test-context>)" ],
31
+ [ "sudo(list(nsrights(nsactive().1),nsrights()));>", "(Namespace<NaanRoot> Namespace<Lang_Lingo>)" ],
32
+
33
+ //
34
+ // namespaces
35
+ //
36
+
37
+ [ "defNS=nsactive();>", "(Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
38
+ [ "function setNS(ns) { ns=reverse(ns),sudo(nsactive(reverse(ns, defNS))) };", "setNS" ],
39
+ [ "x;", "x" ],
40
+ [ "y;", "y" ],
41
+ [ "length(symlist(nsactive(true).0));", "170"],
42
+ [ "testvar;", "testvar" ],
43
+ [ "function setTestvar(v) { testvar=v };", "setTestvar" ],
44
+ [ "naanvar;", "naanvar" ],
45
+ [ "namespace();", "Namespace<NaanRoot>" ],
46
+ [ "namespace(true);", "Namespace<NaanCore>" ],
47
+ [ "namespace(1.0);", "false" ],
48
+ [ "nine;", "nine" ],
49
+ [ "blue = new(namespace, \"blue\");", "Namespace<blue>" ],
50
+ // now in namespace blue
51
+ [ "setNS(list(blue));;setNS(list(false, blue));>", "(Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
52
+ // now in namespace NaanRoot
53
+ [ "setNS(list(false, blue));;nine = new(namespace, 9);", "Namespace<9>" ],
54
+ // now in namespace 9
55
+
56
+ [ "setNS(list(nine, false, blue));;namespace(blue);", "\"blue\"" ],
57
+ [ "setNS(list(nine, false, blue));;nsactive();>", "(Namespace<9> Namespace<NaanRoot> Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
58
+ [ "setNS(list(nine, false, blue));;setNS(list(blue));>", "(Namespace<9> Namespace<NaanRoot> Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
59
+ // now in namespace blue
60
+ [ "setNS(list(blue));;hidevar;", "hidevar" ],
61
+ [ "setNS(list(blue));;nsactive();>", "(Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
62
+
63
+ [ "setNS(list(blue));;setNS(list(nine));>", "(Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
64
+ // now in namespace 9
65
+ [ "setNS(list(nine));;hidevar;", "hidevar" ],
66
+ [ "setNS(list(nine));;setTestvar(hidevar);", "hidevar" ],
67
+ [ "setNS(list(nine));;setNS(list(nine, blue));>", "(Namespace<9> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
68
+ [ "setNS(list(nine, blue));;testvar;", "hidevar" ],
69
+ [ "setNS(list(nine, blue));;setNS(list(blue, nine));>", "(Namespace<9> Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
70
+ // now in namespace blue
71
+ [ "setNS(list(blue, nine));;printq(testvar);", "9::hidevar|hidevar" ],
72
+ [ "setNS(list(blue, nine));;setNS(list(blue));>", "(Namespace<blue> Namespace<9> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
73
+ [ "setNS(list(blue));;printq(testvar);", "9::hidevar|hidevar" ],
74
+
75
+ [ "setNS(list(blue));;function () { moveproc(false, testvar) }();", { errors: "can't modify 9::hidevar from blue" } ],
76
+ [ "setNS(list(blue));;closure () { function inner() { moveproc(false, testvar) }, inner(), }();", { errors: "can't modify 9::hidevar from blue" } ],
77
+ [ "setNS(list(blue));;function fromblue1() { moveproc(false, testvar) };", "fromblue1" ],
78
+ [ "setNS(list(blue));;fromblue1();", { errors: "can't modify 9::hidevar from blue" } ],
79
+ [ "setNS(list(blue));;function fromblue2() { moveproc(false, `testvar) };", "fromblue2" ],
80
+ [ "setNS(list(blue));;fromblue2();", { errors: "can't modify Test-context::testvar from blue" } ],
81
+ [ "setNS(list(blue));;function fromblue3() { testvar=17 };", "fromblue3" ],
82
+ [ "setNS(list(blue));;fromblue3();", { errors: "can't modify Test-context::testvar from blue" } ],
83
+ [ "setNS(list(blue));;function fromblue4(first) { 18 };", "fromblue4" ],
84
+ [ "setNS(list(blue));;getproc(car);", "[Builtin car]" ],
85
+ [ "setNS(list(blue));;fromblue4 = cons(`function, cons(false, cons(list(ba), list(list(`+,1,18)))));>", "(function false (ba) (+ 1 18))" ],
86
+ [ "setNS(list(blue));;fromblue4();", "18" ],
87
+
88
+ [ "setNS(list(blue));;function fromblue5 testvar { first };", "fromblue5" ],
89
+ [ "setNS(list(blue));;function fromblue5(testvar) { first };", "==> redefined: fromblue5|fromblue5" ],
90
+
91
+ [ "setNS(list(blue));;function& fromblue5(ba) { eval(ba) };", "==> redefined: fromblue5|fromblue5" ],
92
+ [ "setNS(list(blue));;fromblue5(quote(setNS(list(blue, nine))));>", "(Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
93
+ [ "setNS(list(blue, nine));;fromblue5(quote(setNS(list(blue))));>", "(Namespace<blue> Namespace<9> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
94
+ [ "setNS(list(blue));;fromblue5(quote(nsactive(cons(false, nsactive(true)))));>", { errors: "Namespace<blue>: no privileges to activate NaanRoot" } ],
95
+ [ "setNS(list(blue));;fromblue5(quote(nsactive(cons(nine, nsactive(true)))));", { errors: "Namespace<blue>: no privileges to activate 9" } ],
96
+ [ "setNS(list(blue));;fromblue5(quote(function () { ba }()));>", "(Lib::call (function lambda false ba))" ],
97
+
98
+ [ "setNS(list(blue));;fromblue5(quote(nsactive()));>", "(Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
99
+ [ "setNS(list(blue));;fromblue5(quote(nsactive(true))) == nsactive(true);", "true" ],
100
+
101
+ [ "setNS(list(blue));;function () { testvar=17 }();", { errors: "can't modify Test-context::testvar from blue" } ],
102
+
103
+ [ "setNS(list(blue));;closure (ba) { function inner(x) { naanvar = x }, inner(ba) }(37);", { errors: "can't modify Test-context::naanvar from blue" } ],
104
+ [ "setNS(list(blue));;function (ba) { ba=17 }();", "17" ],
105
+
106
+ [ "setNS(list(blue));;function nospreader ba { car(ba) };", "nospreader" ],
107
+ [ "setNS(list(blue));;nospreader(39);", "39" ],
108
+ [ "setNS(list(blue));;function (x, y) { x*y, }(11, 17);", "187" ],
109
+
110
+ [ "setNS(list(blue));;closure nestest1(ba) { function inner(bx) { blueref = bx }, inner(ba) };", "nestest1" ],
111
+ [ "setNS(list(blue));;nestest1(31);", "31" ],
112
+ [ "setNS(list(blue));;closure nestest2(ba) { function inner(x) { blueref = x }, inner(ba) };", "nestest2" ],
113
+ [ "setNS(list(blue));;nestest2(28);", "28" ],
114
+ [ "setNS(list(blue));;namespace(namespace(`testvar));", "\"Test-context\"" ],
115
+ [ "setNS(list(blue));;closure nestest3(bb) { function inner(ba) { blueref = ba }, inner(bb) };", "nestest3" ],
116
+ [ "setNS(list(blue));;nestest3(43);", "43" ],
117
+ [ "setNS(list(blue));;namespace(namespace(`testvar));", "\"Test-context\"" ],
118
+
119
+ [ "setNS(list(blue));;namespace(car(nsactive()));", "\"blue\"" ],
120
+ [ "setNS(list(blue));;macro repsymval(sym) { printline(\"value of \", namespace(namespace(sym)), \"::\", sym, \" is: \", car(sym)) };", "repsymval" ],
121
+ [ "setNS(list(blue));;namespace(namespace(`naanvar));", "\"Test-context\"" ],
122
+ [ "setNS(list(blue));;function (naanvar) { repsymval(naanvar) }(71);", "value of blue::naanvar is: 71|71" ],
123
+ [ "setNS(list(blue));;namespace(namespace(`naanvar));", "\"Test-context\"" ],
124
+ [ "setNS(list(blue));;function bluther() { naanvar = 73 };", "bluther" ],
125
+ [ "setNS(list(blue));;bluther();", { errors: "can't modify Test-context::naanvar from blue" } ],
126
+
127
+ [ "setNS(list(blue));;function () { nsrights() }();", "Namespace<blue>" ],
128
+ [ "setNS(list(blue));;function () { function () { nsrights() }(), }();", "Namespace<blue>" ],
129
+
130
+ [ "setNS(list(blue));;$$=function () { function t() { nsrights() }, t, }();>", "t" ],
131
+ [ "setNS(list(blue));;call($$,);", "Namespace<blue>" ],
132
+
133
+ [ "setNS(list(blue));;function () { function t() { nsrights() }, t(), }();", "Namespace<blue>" ],
134
+ [ "setNS(list(blue));;$$=function () { function t() { nsrights() }, `t, }();>", "t" ],
135
+ [ "setNS(list(blue));;call($$,);", "Namespace<blue>" ],
136
+
137
+ [ "setNS(list(blue));;ftemp = function () { function t ba { apply(car(ba), cdr(ba)) }, `t }();", "t" ],
138
+ [ "setNS(list(blue));;ftemp(function (x) { print(x), nsrights() }, \"hi-\");", "hi-|Namespace<blue>" ],
139
+ [ "setNS(list(blue));;ftemp(function (xy) { print(xy), nsrights() }, \"hi-\");", "hi-|Namespace<blue>" ],
140
+
141
+ [ "setNS(list(blue));;function bluert1() { function () { nsrights() }(), };", "bluert1" ],
142
+ [ "setNS(list(blue));;bluert1();", "Namespace<blue>" ],
143
+ [ "setNS(list(blue));;function bluert2() { function t() { nsrights() }, t() };", "bluert2" ],
144
+ [ "setNS(list(blue));;bluert2();", "Namespace<blue>" ],
145
+ [ "setNS(list(blue));;function bluert3() { function () { nsrights() }, };", "bluert3" ],
146
+ [ "setNS(list(blue));;$$=bluert3();>", "(function lambda false (nsrights))" ],
147
+ [ "setNS(list(blue));;call($$,);", "Namespace<blue>" ],
148
+
149
+ [ "setNS(list(blue));;nns=new(namespace, \"newblue\");", "Namespace<newblue>" ],
150
+ [ "setNS(list(blue));;setNS(list(nns, blue));;nsactive().0;", "Namespace<newblue>" ],
151
+ [ "setNS(list(blue));;setNS(list(nns, blue));;sadjoe;", "sadjoe" ],
152
+ [ "setNS(list(blue));;setNS(list(nns, blue));;namespace(sadjoe);", "Namespace<newblue>" ],
153
+ [ "setNS(list(blue));;setNS(list(nns, blue));;setNS(list(blue));>", "(Namespace<newblue> Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
154
+ [ "setNS(list(blue));;$$=symlist(nns);>", "(newblue::sadjoe)" ],
155
+ [ "setNS(list(blue));;joe=$$.0;", "sadjoe" ],
156
+ [ "setNS(list(blue));;namespace(joe);", "Namespace<newblue>" ],
157
+ [ "setNS(list(blue));;delete(nns);", "false" ],
158
+ [ "setNS(list(blue));;namespace(joe);", "false" ],
159
+ [ "setNS(list(blue));;interned(joe);", "false" ],
160
+ [ "setNS(list(blue));;nsactive().0;", "Namespace<blue>" ],
161
+
162
+ //
163
+ // additional security checks
164
+ //
165
+
166
+ [ "setNS(list(blue));;function sudo() { nsrights() };", { text: "cannot define function sudo in Namespace<blue>" } ],
167
+ [ "setNS(list(blue));;apply(`(function sudo false (nsrights)));", { errors: "privilege violation in (function sudo false (nsrights))" } ],
168
+
169
+ //
170
+ // xlock
171
+ //
172
+
173
+ [ "setNS(list(blue));;blueobj = new(object);", "Object{0}" ],
174
+ [ "setNS(list(blue));;blueobj.a=3;", "3" ],
175
+ [ "setNS(list(blue));;blueobj.b=4;", "4" ],
176
+ [ "setNS(list(blue));;blueobj.c=5;", "5" ],
177
+ [ "setNS(list(blue));;xlock(blueobj, car(nsactive(true)));", { errors: "can't lock Object{3} to NaanRoot" } ],
178
+ [ "setNS(list(blue));;xlock(blueobj, car(nsactive()));", "Object{3}" ],
179
+ [ "setNS(list(blue));;setNS(list(nine, blue));>", "(Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
180
+ [ "setNS(list(nine, blue));;blueobj.d=6;", { errors: "can't modify blue::Object{3} from 9" } ],
181
+ [ "setNS(list(nine, blue));;xlock(blueobj);", "false" ],
182
+
183
+ [ "setNS(list(nine, blue));;ninearray = new(array);", "[]" ],
184
+ [ "setNS(list(nine, blue));;xset(ninearray, 0, `a);", "a" ],
185
+ [ "setNS(list(nine, blue));;xset(ninearray, 1, `b);", "b" ],
186
+ [ "setNS(list(nine, blue));;xlock(ninearray, car(nsactive()));", "[a, b]" ],
187
+ [ "setNS(list(nine, blue));;setNS(list(blue, nine));>", "(Namespace<9> Namespace<blue> Namespace<Test-context> Namespace<Lang_Lingo> Namespace<NaanCore>)" ],
188
+ [ "setNS(list(blue, nine));;xset(ninearray, 2, `c);", { errors: "can't modify 9::Array[2] from blue" } ],
189
+ [ "setNS(list(blue, nine));;xlock(ninearray);", "false" ],
190
+ [ "delete(blue, nine);", "false" ],
191
+
192
+ //
193
+ // tail call optimization
194
+ //
195
+
196
+ [ "function testRecurCheck(x) { if stacktrace().length > 200 throw('recursed '.concat(x)) };", "testRecurCheck" ],
197
+
198
+ [ "function test1(x) { if x > 10000 printline(x) else test2(x+1) };", "test1" ],
199
+ [ "function test2(x) { testRecurCheck(x), test1(x+1) };", "test2" ],
200
+ [ "test2(4);", "10001|10001" ],
201
+
202
+ [ "function test1(x) { if x > 10000 printline(x) else test2(x+1), undefined() };", "==> redefined: test1|test1" ],
203
+ [ "test2(5);", { errors: "exception: recursed 101" } ],
204
+
205
+ [ "function test1(x) { if x > 10000 printline(x) else loop test2(x+1) };", "==> redefined: test1|test1" ],
206
+ [ "test2(6);", { errors: "exception: recursed 102" } ],
207
+
208
+ [ "function test1(x) { if x > 10000 printline(x) else 0+test2(x+1) };", "==> redefined: test1|test1" ],
209
+ [ "test2(7);", { errors: "exception: recursed 151" } ],
210
+
211
+ [ "function test2(x) { testRecurCheck(x), if true test1(x+1) else print(x) };", "==> redefined: test2|test2" ],
212
+ [ "test2(8);", { errors: "exception: recursed 152" } ],
213
+
214
+ [ "function test1(x) { if x > 10000 printline(x) else loop test2(x+1, 4, 5) };", "==> redefined: test1|test1" ],
215
+ [ "function test2(x,y,z) { testRecurCheck(x), loop if true { test1(x+1),break } else print(x) };", "==> redefined: test2|test2" ],
216
+ [ "test2(9);", { errors: "exception: recursed 51" } ],
217
+
218
+ [ "function test1 xt { if car(xt) > 10000 printline(xt) else test2(car(xt)+1) };", "==> redefined: test1|test1" ],
219
+ [ "function test2 xt { testRecurCheck(car(xt)), test1(car(xt)+1) };", "==> redefined: test2|test2" ],
220
+ [ "test2(10);", "(10001)|(10001)" ],
221
+
222
+ [ "oo=new(object);", "Object{0}"],
223
+ [ "oo.test1 = function test1(x) { if x > 10000 printline(x) else test2(x+1) };", "==> redefined: test1|test1"],
224
+ [ "oo.test2 = function test2 xt { testRecurCheck(car(xt)), oo.test1(car(xt)+1) };", "==> redefined: test2|test2"],
225
+ [ "oo.test1(11);", { errors: "exception: recursed 156" } ],
226
+
227
+ [ "function test1 xt { testRecurCheck(car(xt)), if car(xt) > 10000 printline(xt) else test1(car(xt)+1) };",
228
+ "==> redefined: test1|test1" ],
229
+ [ "test1(12);", "(10001)|(10001)" ],
230
+
231
+ [ "(function testnfs(a, b) { function inner() { print('a=', a) }, inner(), if a<2 { testnfs(a+1), inner() } else inner() })(0);",
232
+ "a=0a=1a=2a=2a=1a=0|0"],
233
+
234
+ //
235
+ // closure instances
236
+ //
237
+
238
+ [ "closure outer(x) {\n"
239
+ "closure inner(y) {\n"
240
+ " if !x\n"
241
+ " x = '-'\n"
242
+ " printline(x,y)\n"
243
+ " function() {\n"
244
+ " print(x, ':', y)\n"
245
+ " }.1\n"
246
+ "}.1\n"
247
+ "};", "outer" ],
248
+ [ "instances(outer);>", "(outer)" ],
249
+ [ "a1 = outer(1);", "inner" ],
250
+ [ "a2 = outer(2);", "inner" ],
251
+ [ "b1 = a1(3);", "13|lambda" ],
252
+ [ "b2 = a2(4);", "24|lambda" ],
253
+ [ "b2b = outer(6);", "inner" ],
254
+ [ "instances(b1);>", "(lambda lambda lambda lambda lambda lambda)" ],
255
+ [ "instances(b2);>", "(lambda lambda lambda lambda lambda lambda)" ],
256
+ [ "instances(outer);>", "(outer outer outer outer)" ],
257
+ [ "instances(outer).map(function(o) { car(o.proc.2.0) });>", "(6 2 1 x)"],
258
+ [ "a1=false;a2=false;b1=false;b2=false;", "false|false|false|false" ],
259
+ [ "instances(outer);>", "(outer outer)" ],
260
+
261
+ //
262
+ // closure-object integration
263
+ //
264
+
265
+ [ "closure Xx(y, local xx) { xx = new(object, this) };", "Xx" ],
266
+ [ "x = Xx(33);", "Object{0}" ],
267
+ [ "car(x@\\.closure.proc.2.0)", "33" ],
268
+ [ "new(object, 3)@*", "false" ]
269
+ ]);
@@ -0,0 +1,137 @@
1
+ /*
2
+ * test_03_jsinterop.nlg
3
+ * Test
4
+ *
5
+ * Perform basic unit tests for Naan.
6
+ *
7
+ * column positioning: // // !
8
+ *
9
+ * Copyright (c) 2020-2021 by Richard C. Zulch
10
+ *
11
+ */
12
+
13
+
14
+ /*
15
+ * Test Category 3 - JSinterop
16
+ *
17
+ */
18
+
19
+ RegisterTestCategory("JSinterop", [
20
+ [ "4+3;", "7" ], // generic first test
21
+
22
+
23
+ //
24
+ // external objects
25
+ //
26
+
27
+ [ "o=xnew();", "[object Object]" ],
28
+ [ "o.a=true;", "true" ],
29
+ [ "o.a;", "true" ],
30
+ [ "o.a=false;", "false" ],
31
+ [ "o.a;", "false" ],
32
+ [ "o.a=undefined;", "undefined" ],
33
+ [ "o.a;", "undefined" ],
34
+ [ "o.nodef;", "undefined" ],
35
+
36
+ [ "o(3);", { errors: "xcall \"[object Object]\": TypeError: e[3].apply is not a function" } ],
37
+ [ "o(Number);", { errors: "xcall \"[object Object]\": TypeError: e[3].apply is not a function" } ],
38
+ [ "Number(3);", "[Number 3]" ],
39
+ [ "Number(3).toString();", "\"3\"" ],
40
+ [ "tostring(Number(3));", "\"[Number 3]\"" ],
41
+ [ "tostring(Number(3), true);", "\"[Number 3]\"" ],
42
+ [ "call(Number, 3);", "[Number 3]" ],
43
+ [ "tostring(call(Number, 3));", "\"[Number 3]\"" ],
44
+ [ "String(\"hi there\");", "[String hi there]" ],
45
+ [ "String(\"hi there\").toString();", "\"hi there\"" ],
46
+ [ "tostring(String(\"hi there\"));", "\"[String hi there]\"" ],
47
+ [ "tostring(String(\"hi there\"), true);", "\"[String hi there]\"" ],
48
+ [ "xcall({});", "false" ],
49
+
50
+ [ "sqrt = false;", "false" ],
51
+ [ "Math.sqrt(9);", "3" ], // ensure method selector is not evalulated
52
+
53
+ [ "xnew(js.g.Promise, function() {});", "[object Promise]" ],
54
+
55
+
56
+ //
57
+ // child processes
58
+ // ### only on NodeJS
59
+ //
60
+
61
+ // [ "xnew(js.g.Promise, function() {});", "[object Promise]" ],
62
+ // [ "js.g.process.version;", "v12.18.2" ],
63
+ // [ "js.r(\"child_process\").spawnSync(\"node\", list(\"--version\")).output.1.toString();", "v12.18.2" ],
64
+
65
+
66
+ //
67
+ // stacktrap
68
+ //
69
+
70
+ [ "closure spread (nth) { stacktrap(nth,function&(x) { print(\"in-\",x,\"-\",nth) }) };", "spread" ],
71
+ [ "spread(0);", "in-Dictionary{0}-0|{ }" ],
72
+ [ "spread(1);", "in-Dictionary{0}-1|{ }" ],
73
+ [ "spread(2);", "in-Dictionary{0}-2|{ }" ],
74
+ [ "spread(3);", "in-Dictionary{0}-3|{ }" ],
75
+ [ "spread(4);", "in-Dictionary{0}-4|{ }" ],
76
+ [ "spread(5);", "in-Dictionary{0}-5|{ }" ],
77
+ [ "spread(6);", "in-Dictionary{0}-6|{ }" ],
78
+ [ "spread(7);", "in-1-7|{\n"
79
+ " trap: function& (x) {\n"
80
+ " print(\"in-\", x, \"-\", nth)\n"
81
+ " } }" ],
82
+ [ "spread(8);", "in-1-8|{\n"
83
+ " trap: function& (x) {\n"
84
+ " print(\"in-\", x, \"-\", nth)\n"
85
+ " } }" ],
86
+ [ "spread(9);", "{\n"
87
+ " trap: function& (x) {\n"
88
+ " print(\"in-\", x, \"-\", nth)\n"
89
+ " } }" ],
90
+
91
+ [ "closure nospread nthl { stacktrap(nthl.0,function&(x) { print(\"in-\",x,\"-\",nthl.0) }) };", "nospread" ],
92
+ [ "nospread(0);", "in-Dictionary{0}-0|{ }" ],
93
+ [ "nospread(1);", "in-Dictionary{0}-1|{ }" ],
94
+ [ "nospread(2);", "in-Dictionary{0}-2|{ }" ],
95
+ [ "nospread(3);", "in-Dictionary{0}-3|{ }" ],
96
+ [ "nospread(4);", "in-Dictionary{0}-4|{ }" ],
97
+ [ "nospread(5);", "in-Dictionary{0}-5|{ }" ],
98
+ [ "nospread(6);", "in-Dictionary{0}-6|{ }" ],
99
+ [ "nospread(7);", "in-1-7|{\n"
100
+ " trap: function& (x) {\n"
101
+ " print(\"in-\", x, \"-\", nthl.0)\n"
102
+ " } }" ],
103
+ [ "nospread(8);", "in-1-8|{\n"
104
+ " trap: function& (x) {\n"
105
+ " print(\"in-\", x, \"-\", nthl.0)\n"
106
+ " } }" ],
107
+ [ "nospread(9);", "{\n"
108
+ " trap: function& (x) {\n"
109
+ " print(\"in-\", x, \"-\", nthl.0)\n"
110
+ " } }" ],
111
+
112
+ [ "Array(0,1,2,3,4,5,6,7,8,9,10).filter(function&(nth) { stacktrap(nth,function&() { print(\"in-\",nth, \" \") }) });",
113
+ { text: "in-0 in-1 in-nth in-nth in-nth in-nth in-nth in-nth in-nth in-nth in-nth" } ],
114
+
115
+ [ "loop { stacktrap(0,function&(x) { print(\"loop-\",x) }), break };", "loop-Dictionary{0}|{ }" ],
116
+ [ "loop { stacktrap(1,function&(x) { print(\"loop-\",x) }), break };", "loop-Dictionary{0}|{ }" ],
117
+ [ "loop { stacktrap(2,function&(x) { print(\"loop-\",x) }), break };", "loop-Dictionary{0}|{ }" ],
118
+ [ "loop { stacktrap(3,function&(x) { print(\"loop-\",x) }), break };", "loop-Dictionary{0}|{ }" ],
119
+ [ "loop { stacktrap(4,function&(x) { print(\"loop-\",x) }), break };", "loop-Dictionary{0}|{ }" ],
120
+ [ "loop { stacktrap(5,function&(x) { print(\"loop-\",x) }), break };", "loop-Dictionary{0}|{ }" ],
121
+ [ "loop { stacktrap(6,function&(x) { print(\"loop-\",x) }), break };", "loop-1|{\n"
122
+ " trap: function& (x) {\n"
123
+ " print(\"loop-\", x)\n"
124
+ " } }" ],
125
+ [ "loop { stacktrap(7,function&(x) { print(\"loop-\",x) }), break };", "loop-1|{\n"
126
+ " trap: function& (x) {\n"
127
+ " print(\"loop-\", x)\n"
128
+ " } }" ],
129
+ [ "loop { stacktrap(8,function&(x) { print(\"loop-\",x) }), break };", "{\n"
130
+ " trap: function& (x) {\n"
131
+ " print(\"loop-\", x)\n"
132
+ " } }" ],
133
+
134
+ [ "function&(top,local nth){ nth=0, loop { print(nth), closure(nth) { stacktrap(nth,function&(x) { print(\" loop-\",x,\"-\",nth) }) }(nth), if nth >= top break else nth = nth+1 }, }(9);",
135
+ "0 loop-Dictionary{0}-01 loop-Dictionary{0}-123456789 loop-true-2 loop-true-3 loop-true-4 loop-true-5 loop-true-6 loop-true-7 loop-true-8 loop-true-9|true" ]
136
+
137
+ ]);