@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.
- package/LICENSE.md +21 -0
- package/README.md +46 -0
- package/dist/env_web.js +431 -0
- package/dist/naan.min.js +73 -0
- package/frameworks/browser/browser.nlg +30 -0
- package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
- package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
- package/frameworks/browser/sworker.js +192 -0
- package/frameworks/browser/terminals.nlg +787 -0
- package/frameworks/browser/workers.nlg +386 -0
- package/frameworks/client/apiclient.nlg +183 -0
- package/frameworks/client/client.nlg +29 -0
- package/frameworks/client/psm_client.nlg +572 -0
- package/frameworks/common/common.nlg +464 -0
- package/frameworks/common/preferences.nlg +131 -0
- package/frameworks/common/repltools.nlg +100 -0
- package/frameworks/common/watching.nlg +97 -0
- package/frameworks/node/apiserver.nlg +399 -0
- package/frameworks/node/filesystem.nlg +1012 -0
- package/frameworks/node/gitter.nlg +234 -0
- package/frameworks/node/node.nlg +81 -0
- package/frameworks/node/psm_server.nlg +465 -0
- package/frameworks/node/worker.nlg +560 -0
- package/frameworks/project/build.nlg +1229 -0
- package/frameworks/project/jszip.js +30 -0
- package/frameworks/project/jszip.nlg +87 -0
- package/frameworks/project/proj_cliser.nlg +139 -0
- package/frameworks/project/proj_console.nlg +137 -0
- package/frameworks/project/proj_folder.nlg +143 -0
- package/frameworks/project/proj_lambda.nlg +137 -0
- package/frameworks/project/proj_static.nlg +138 -0
- package/frameworks/project/project.nlg +29 -0
- package/frameworks/project/projects.nlg +587 -0
- package/frameworks/project/uglifyjs.js +1 -0
- package/frameworks/project/uglifyjs.nlg +79 -0
- package/frameworks/running/debugcom.nlg +163 -0
- package/frameworks/running/debugnub.nlg +565 -0
- package/frameworks/running/debugutil.nlg +510 -0
- package/frameworks/running/executors.nlg +767 -0
- package/frameworks/running/running.nlg +151 -0
- package/frameworks/running/sourcecode.nlg +346 -0
- package/frameworks/running/taskexec.nlg +196 -0
- package/frameworks/storage/dbt_pouch.nlg +773 -0
- package/frameworks/storage/file_manager.nlg +772 -0
- package/frameworks/storage/psm.nlg +326 -0
- package/frameworks/storage/psm_dbtables.nlg +814 -0
- package/frameworks/storage/resources.nlg +445 -0
- package/frameworks/storage/storage.nlg +52 -0
- package/lib/browser/env_web.js +431 -0
- package/lib/browser/env_webworker.js +146 -0
- package/lib/browser/require.js +1653 -0
- package/lib/core/naanlib.js +73 -0
- package/lib/env_node.js +282 -0
- package/lib/env_nodeworker.js +165 -0
- package/lib/node_repl.js +25 -0
- package/lib/node_repl_init.nlg +52 -0
- package/package.json +13 -0
- package/plugins/gitClient/clientops.nlg +317 -0
- package/plugins/gitClient/gitClient.nlg +63 -0
- package/plugins/gitClient/gitutils.nlg +1331 -0
- package/plugins/gitClient/minimatch.js +945 -0
- package/plugins/gitClient/minimatch_license.txt +15 -0
- package/plugins/gitClient/minimatch_readme.md +208 -0
- package/plugins/nodeLib/nodeLib.nlg +26 -0
- package/plugins/nodeLib/node_cp.nlg +65 -0
- package/plugins/nodeLib/node_fs.nlg +137 -0
- package/plugins/nodeLib/node_https.nlg +172 -0
- package/plugins/nodeLib/node_util.nlg +180 -0
- package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
- package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
- package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
- package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
- package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
- package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
- package/plugins/serviceAws/aws_cognito.nlg +76 -0
- package/plugins/serviceAws/aws_dynamo.nlg +509 -0
- package/plugins/serviceAws/aws_lambda.nlg +95 -0
- package/plugins/serviceAws/aws_s3.nlg +134 -0
- package/plugins/serviceAws/aws_utils.nlg +86 -0
- package/plugins/serviceAws/dbt_aws.nlg +769 -0
- package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
- package/plugins/serviceAws/psm_aws.nlg +258 -0
- package/plugins/serviceAws/serviceAws.nlg +38 -0
- package/plugins/serviceGitHub/gitops.nlg +522 -0
- package/plugins/serviceGitHub/psm_github.nlg +205 -0
- package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
- package/plugins/serviceGitLab/gitops.nlg +528 -0
- package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
- package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
- package/test/harness.nlg +312 -0
- package/test/node_test.js +33 -0
- package/test/test_01_core.nlg +768 -0
- package/test/test_02_context.nlg +269 -0
- package/test/test_03_jsinterop.nlg +137 -0
- package/test/test_04_numerics.nlg +450 -0
- package/test/test_05_strings.nlg +63 -0
- package/test/test_06_lingoparse.nlg +500 -0
- package/test/test_07_lingo.nlg +623 -0
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* test_01_core.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 1 - Core
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
RegisterTestCategory("core", [
|
|
20
|
+
[ "4+3;", "7" ], // generic first test
|
|
21
|
+
|
|
22
|
+
//
|
|
23
|
+
// booleans and/or undefined
|
|
24
|
+
//
|
|
25
|
+
|
|
26
|
+
[ "false;", "" ],
|
|
27
|
+
[ "true;", "true" ],
|
|
28
|
+
[ "not true;", "false" ],
|
|
29
|
+
[ "not false;", "true" ],
|
|
30
|
+
[ "not undefined;", "true" ],
|
|
31
|
+
|
|
32
|
+
[ "false and false;", "false" ],
|
|
33
|
+
[ "false and true;", "false" ],
|
|
34
|
+
[ "true and false;", "false" ],
|
|
35
|
+
[ "true and true;", "true" ],
|
|
36
|
+
[ "undefined and false;", "undefined" ],
|
|
37
|
+
[ "false and undefined;", "false" ],
|
|
38
|
+
[ "undefined and undefined;", "undefined" ],
|
|
39
|
+
[ "undefined and true;", "undefined" ],
|
|
40
|
+
[ "true and undefined;", "undefined" ],
|
|
41
|
+
[ "true and print(\"yes\");", "yes|\"yes\"" ],
|
|
42
|
+
|
|
43
|
+
[ "false or false;", "false" ],
|
|
44
|
+
[ "false or true;", "true" ],
|
|
45
|
+
[ "true or false;", "true" ],
|
|
46
|
+
[ "true or true;", "true" ],
|
|
47
|
+
[ "undefined or false;", "false" ],
|
|
48
|
+
[ "false or undefined;", "undefined" ],
|
|
49
|
+
[ "undefined or undefined;", "undefined" ],
|
|
50
|
+
[ "undefined or true;", "true" ],
|
|
51
|
+
[ "true or undefined;", "true" ],
|
|
52
|
+
[ "true or print(\"yes\");", "true" ],
|
|
53
|
+
|
|
54
|
+
[ "aaa=true;", "true" ],
|
|
55
|
+
[ "false=true;", { errors: "attempt to modify constant false" } ],
|
|
56
|
+
[ "undefined=true;", { errors: "attempt to modify constant undefined" } ],
|
|
57
|
+
[ "true=true;", { errors: "can't modify NaanCore::true from Test-core" } ],
|
|
58
|
+
|
|
59
|
+
[ "lambda();", "false" ],
|
|
60
|
+
[ "lambda(lambda);", "true" ],
|
|
61
|
+
[ "lambda(unintern(\"lambda\"));", "true" ],
|
|
62
|
+
|
|
63
|
+
[ "car(`;);", ";" ],
|
|
64
|
+
|
|
65
|
+
//
|
|
66
|
+
// basic lists and dotted pairs
|
|
67
|
+
//
|
|
68
|
+
|
|
69
|
+
[ "`();>", "false" ],
|
|
70
|
+
[ "`);>", ")" ],
|
|
71
|
+
[ "`(a `.);>", "(a `.)" ],
|
|
72
|
+
[ "`(a `. b);>", "(a `. b)" ],
|
|
73
|
+
[ "`(a ``);>", "(a ``)" ],
|
|
74
|
+
[ "`(a `();>", "(a `()" ],
|
|
75
|
+
[ "`(a `));>", "(a `))" ],
|
|
76
|
+
[ "`(a `,);>", "(a `,)" ],
|
|
77
|
+
[ "`(a . false);>", "(a)" ],
|
|
78
|
+
[ "`(a . b);>", "(a . b)" ],
|
|
79
|
+
[ "`(a b . c);>", "(a b . c)" ],
|
|
80
|
+
[ "`(a . (b c));>", "(a b c)" ],
|
|
81
|
+
[ "`((a b) . (c d));>", "((a b) c d)" ],
|
|
82
|
+
[ "`((a . b) . (c d));>", "((a . b) c d)" ],
|
|
83
|
+
[ "`((a b) . (c . d));>", "((a b) c . d)" ],
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
//
|
|
87
|
+
// assignment
|
|
88
|
+
//
|
|
89
|
+
|
|
90
|
+
[ "aa=13;", "13" ],
|
|
91
|
+
[ "aa;", "13" ],
|
|
92
|
+
[ "assign(bb, 23);", "23" ],
|
|
93
|
+
[ "bb;", "23" ],
|
|
94
|
+
[ "`(aa,bb) = `(17,19);>", "(17 19)" ],
|
|
95
|
+
[ "aa;", "17" ],
|
|
96
|
+
[ "bb;", "19" ],
|
|
97
|
+
[ "`(aa,bb,cc) = `(29);>", "(29)" ],
|
|
98
|
+
[ "aa;", "29" ],
|
|
99
|
+
[ "bb;", "false" ],
|
|
100
|
+
[ "cc;", "false" ],
|
|
101
|
+
[ "`(aa,bb,cc) = `31;", "31" ],
|
|
102
|
+
[ "aa;", "31" ],
|
|
103
|
+
[ "bb;", "31" ],
|
|
104
|
+
[ "cc;", "31" ],
|
|
105
|
+
[ "`(aa,bb,cc) = `(aa,bb,cc);>", "(aa bb cc)" ],
|
|
106
|
+
[ "assign(list(`aa,`bb), `(37 39));>", "(37 39)" ],
|
|
107
|
+
[ "aa;", "37" ],
|
|
108
|
+
[ "bb;", "39" ],
|
|
109
|
+
[ "aa=new(array).concat(1,2,3);", "[1, 2, 3]" ],
|
|
110
|
+
[ "assign(aa, 4);", { errors: "attempt to modify constant Array[3]" } ],
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//
|
|
114
|
+
// adjusters
|
|
115
|
+
//
|
|
116
|
+
|
|
117
|
+
[ "preadjust(bb,`+,1);", "40" ],
|
|
118
|
+
[ "bb;", "40" ],
|
|
119
|
+
[ "postadjust(bb,`+,1);", "40" ],
|
|
120
|
+
[ "bb;", "41" ],
|
|
121
|
+
[ "oo={aa:0};", "{ aa: 0 }" ],
|
|
122
|
+
[ "preadjust(oo.aa,`+,1);", "1" ],
|
|
123
|
+
[ "oo.aa;", "1" ],
|
|
124
|
+
[ "postadjust(oo.aa,`+,1);", "1" ],
|
|
125
|
+
[ "oo.aa;", "2" ],
|
|
126
|
+
[ "preadjust(`(a,b),`+,1);", "false" ],
|
|
127
|
+
[ "preadjust(false,`+,1);", { errors: "attempt to modify constant false" } ],
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
//
|
|
131
|
+
// symbols
|
|
132
|
+
//
|
|
133
|
+
|
|
134
|
+
[ "exists(`$);", "$" ],
|
|
135
|
+
[ "exists(\"$\");", "$" ],
|
|
136
|
+
[ "exists(`a);", "a" ],
|
|
137
|
+
[ "exists(\"a\");", "a" ],
|
|
138
|
+
[ "exists(RegExp(\"ss+\"));>", "(assign)" ],
|
|
139
|
+
[ "exists(RegExp(\"adj\"), car(nsactive()));>",
|
|
140
|
+
"(preadjust postadjust)" ],
|
|
141
|
+
[ "exists(RegExp(\"z\"), car(nsactive(true)));>", "(NaanRoot::zero)" ],
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
//
|
|
145
|
+
// accessors
|
|
146
|
+
//
|
|
147
|
+
|
|
148
|
+
[ "A=B=C=D=E=F=G=H=I=J=K=L=M=N=O=P=Q=R=1;", "1" ],
|
|
149
|
+
|
|
150
|
+
[ "alist=`(A,B, (C D E), F);>", "(A B (C D E) F)" ],
|
|
151
|
+
[ "`alist;", "alist" ],
|
|
152
|
+
[ "quote(alist);", "alist" ],
|
|
153
|
+
[ "first(alist);>", "A" ],
|
|
154
|
+
[ "ffirst(alist);>", "1" ],
|
|
155
|
+
[ "second(alist);>", "B" ],
|
|
156
|
+
[ "fsecond(alist);>", "1" ],
|
|
157
|
+
[ "third(alist);>", "(C D E)" ],
|
|
158
|
+
[ "rest(alist);>", "(B (C D E) F)" ],
|
|
159
|
+
[ "rrest(alist);>", "((C D E) F)" ],
|
|
160
|
+
[ "rrrest(alist);>", "(F)" ],
|
|
161
|
+
|
|
162
|
+
[ "blist=`(((((A),B),((C),D),E),((F),G,H),(I),J),((K,L),(M),N),(O,P),Q,R);>",
|
|
163
|
+
"(((((A) B) ((C) D) E) ((F) G H) (I) J) ((K L) (M) N) (O P) Q R)" ],
|
|
164
|
+
[ "car(blist);>", "((((A) B) ((C) D) E) ((F) G H) (I) J)" ],
|
|
165
|
+
[ "cdr(blist);>", "(((K L) (M) N) (O P) Q R)" ],
|
|
166
|
+
[ "caar(blist);>", "(((A) B) ((C) D) E)" ],
|
|
167
|
+
[ "cadr(blist);>", "((K L) (M) N)" ],
|
|
168
|
+
[ "cdar(blist);>", "(((F) G H) (I) J)" ],
|
|
169
|
+
[ "cddr(blist);>", "((O P) Q R)" ],
|
|
170
|
+
[ "caaar(blist);>", "((A) B)" ],
|
|
171
|
+
[ "caadr(blist);>", "(K L)" ],
|
|
172
|
+
[ "cadar(blist);>", "((F) G H)" ],
|
|
173
|
+
[ "caddr(blist);>", "(O P)" ],
|
|
174
|
+
[ "cdaar(blist);>", "(((C) D) E)" ],
|
|
175
|
+
[ "cdadr(blist);>", "((M) N)" ],
|
|
176
|
+
[ "cddar(blist);>", "((I) J)" ],
|
|
177
|
+
[ "cdddr(blist);>", "(Q R)" ],
|
|
178
|
+
[ "caaaar(blist);>", "(A)" ],
|
|
179
|
+
[ "caaadr(blist);>", "K" ],
|
|
180
|
+
[ "caadar(blist);>", "(F)" ],
|
|
181
|
+
[ "caaddr(blist);>", "O" ],
|
|
182
|
+
[ "cadaar(blist);>", "((C) D)" ],
|
|
183
|
+
[ "cadadr(blist);>", "(M)" ],
|
|
184
|
+
[ "caddar(blist);>", "(I)" ],
|
|
185
|
+
[ "cadddr(blist);>", "Q" ],
|
|
186
|
+
[ "cdaaar(blist);>", "(B)" ],
|
|
187
|
+
[ "cdaadr(blist);>", "(L)" ],
|
|
188
|
+
[ "cdadar(blist);>", "(G H)" ],
|
|
189
|
+
[ "cdaddr(blist);>", "(P)" ],
|
|
190
|
+
[ "cddaar(blist);>", "(E)" ],
|
|
191
|
+
[ "cddadr(blist);>", "(N)" ],
|
|
192
|
+
[ "cdddar(blist);>", "(J)" ],
|
|
193
|
+
[ "cddddr(blist);>", "(R)" ],
|
|
194
|
+
|
|
195
|
+
//
|
|
196
|
+
// tuple paths
|
|
197
|
+
//
|
|
198
|
+
|
|
199
|
+
[ "tetu = `(a,(3,4),c . d);>", "(a (3 4) c . d)" ],
|
|
200
|
+
[ "tuplepath(tetu, tetu)", "false" ],
|
|
201
|
+
[ "tuplepath(tetu, tetu.0)", "(0)" ],
|
|
202
|
+
[ "tuplepath(tetu, tetu.-1)", "(-1)" ],
|
|
203
|
+
[ "tuplepath(tetu, tetu.1)", "(1)" ],
|
|
204
|
+
[ "tuplepath(tetu, tetu.-2)", "(-2)" ],
|
|
205
|
+
[ "tuplepath(tetu, tetu.2)", "(2)" ],
|
|
206
|
+
[ "tuplepath(tetu, tetu.-3)", "(-3)" ],
|
|
207
|
+
[ "tuplepath(tetu, tetu.3)", "(-3)" ],
|
|
208
|
+
[ "tuplepath(tetu, tetu.-4)", "(-3)" ],
|
|
209
|
+
[ "tuplepath(tetu, tetu.-5)", "(-3)" ],
|
|
210
|
+
[ "tuplepath(tetu, tetu.1.0)", "(1, 0)" ],
|
|
211
|
+
[ "tuplepath(tetu, tetu.1.-1)", "(1, -1)" ],
|
|
212
|
+
[ "tuplepath(tetu, tetu.1.1)", "(1, 1)" ],
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
//
|
|
216
|
+
// builtins
|
|
217
|
+
//
|
|
218
|
+
|
|
219
|
+
[ "member(apple, `(grape, apple, plum));>", "(apple plum)" ],
|
|
220
|
+
[ "member(apples, `(grape, apple, plum));", "false" ],
|
|
221
|
+
|
|
222
|
+
[ "unicode(0x5a);", "\"Z\"" ],
|
|
223
|
+
[ "unicode(\"Z\");", "0x5a" ],
|
|
224
|
+
[ "unicode(0x2609);", "\"☉\"" ],
|
|
225
|
+
[ "unicode(\"☉\");", "0x2609" ],
|
|
226
|
+
[ "unicode(0x9962);", "\"饢\"" ], // "persian flatbread", i.e. naan
|
|
227
|
+
[ "unicode(\"饢\");", "0x9962" ],
|
|
228
|
+
[ "unicode(0x1f35e);", "\"🍞\"" ],
|
|
229
|
+
[ "unicode(\"🍞\");", "0x1f35e" ],
|
|
230
|
+
[ "unicode(0x1f95c);", "\"🥜\"" ], // peanut, UNICODE 9.0 2016
|
|
231
|
+
[ "unicode(\"🥜\");", "0x1f95c" ],
|
|
232
|
+
|
|
233
|
+
//
|
|
234
|
+
// special operators
|
|
235
|
+
//
|
|
236
|
+
|
|
237
|
+
[ "eval(`(+ 4 3));", "7" ],
|
|
238
|
+
|
|
239
|
+
[ "apply(`+, `(4 3));", "7" ],
|
|
240
|
+
|
|
241
|
+
[ "call(car(`+), 4, 3);", "7" ],
|
|
242
|
+
[ "call(getproc(`+), 4, 3);", "7" ], // ensures that call takes a builtin as function
|
|
243
|
+
|
|
244
|
+
[ "list();>", "false" ],
|
|
245
|
+
[ "list(3, 4, 5, `(6 7));>", "(3 4 5 (6 7))" ],
|
|
246
|
+
|
|
247
|
+
[ "apply(`and);", "true" ],
|
|
248
|
+
[ "apply(`and, list(true));", "true" ],
|
|
249
|
+
[ "apply(`and, list(false));", "false" ],
|
|
250
|
+
[ "true and true;", "true" ],
|
|
251
|
+
[ "true and false;", "false" ],
|
|
252
|
+
[ "false and true;", "false" ],
|
|
253
|
+
[ "false and false;", "false" ],
|
|
254
|
+
[ "0 and 1;", "1" ],
|
|
255
|
+
[ "false and print(3);", "false" ],
|
|
256
|
+
[ "true and print(3);", "3|3" ],
|
|
257
|
+
|
|
258
|
+
[ "apply(`or);", "false" ],
|
|
259
|
+
[ "apply(`or, list(true));", "true" ],
|
|
260
|
+
[ "apply(`or, list(false));", "false" ],
|
|
261
|
+
[ "true or true;", "true" ],
|
|
262
|
+
[ "true or false;", "true" ],
|
|
263
|
+
[ "false or true;", "true" ],
|
|
264
|
+
[ "false or false;", "false" ],
|
|
265
|
+
[ "0 or 1;", "0" ],
|
|
266
|
+
[ "false or print(3);", "3|3" ],
|
|
267
|
+
[ "true or print(3);", "true" ],
|
|
268
|
+
|
|
269
|
+
[ "loop { print(6), if true break };", "6|true" ],
|
|
270
|
+
|
|
271
|
+
[ "false=true;", { errors: "attempt to modify constant false" } ],
|
|
272
|
+
[ "print(testcore=`testcore);", "testcore|testcore" ],
|
|
273
|
+
[ "print(testcore=42);", "42|42" ],
|
|
274
|
+
|
|
275
|
+
[ "cond();", { errors: "cond( requires if expression at (1, 7) found )" } ],
|
|
276
|
+
[ "quote(cond(if false 3 else if true 4));>", "(cond ((identity false) 3) ((identity true) 4))" ],
|
|
277
|
+
[ "cond(if false 3 else if true 4);", "4" ],
|
|
278
|
+
[ "cond (if 1 and\n 2, 3);", "3" ],
|
|
279
|
+
[ "cond(print(false),print(\"hi\"));",
|
|
280
|
+
{ errors: "cond( requires if expression at (1, 7) found print" } ],
|
|
281
|
+
|
|
282
|
+
[ "body();", "false" ],
|
|
283
|
+
[ "quote(body(if false 3 else if true 4));>", "(body ((identity false) 3) ((identity true) 4))" ],
|
|
284
|
+
[ "body(if false 3 else if true 4);", "4" ],
|
|
285
|
+
[ "body(print(\"hi\"), print(\" there\"),4+3);>", "hi there|7" ],
|
|
286
|
+
[ "body(print(false),print(\"hi\"));", "falsehi|\"hi\"" ],
|
|
287
|
+
|
|
288
|
+
[ "push();>", { errors: "attempt to modify constant false" } ],
|
|
289
|
+
[ "push(true);>", { errors: "attempt to modify constant false" } ],
|
|
290
|
+
[ "push(true, 3);>", "false" ],
|
|
291
|
+
[ "testcore=false;", "false" ],
|
|
292
|
+
[ "push(11, testcore);>", "(11)" ],
|
|
293
|
+
[ "push(12, testcore);>", "(12 11)" ],
|
|
294
|
+
[ "push(`(a b c), testcore);>", "((a b c) 12 11)" ],
|
|
295
|
+
|
|
296
|
+
[ "testcore.1;", "12" ],
|
|
297
|
+
[ "testcore.2;", "11" ],
|
|
298
|
+
[ "testcore.3;", "false" ],
|
|
299
|
+
[ "testcore.0;>", "(a b c)" ],
|
|
300
|
+
[ "testcore.0.1;>", "b" ],
|
|
301
|
+
|
|
302
|
+
//
|
|
303
|
+
// property functions
|
|
304
|
+
//
|
|
305
|
+
|
|
306
|
+
[ "get();", "false" ],
|
|
307
|
+
[ "get(false);", "false" ],
|
|
308
|
+
[ "get(false);", "false" ],
|
|
309
|
+
[ "put();", { errors: "attempt to modify constant false" } ],
|
|
310
|
+
[ "put(false, true, 9);", { errors: "attempt to modify constant false" } ],
|
|
311
|
+
[ "cdr(false);", "false" ],
|
|
312
|
+
[ "testcore=`testcore;", "testcore" ],
|
|
313
|
+
[ "replacer(testcore, false);", "testcore" ],
|
|
314
|
+
[ "cdr(testcore);>", "false" ],
|
|
315
|
+
[ "put(testcore, \"abc\", 8);", "8" ],
|
|
316
|
+
[ "get(testcore, \"abc\");", "8" ],
|
|
317
|
+
[ "cdr(testcore);>", "Dictionary{1}" ],
|
|
318
|
+
[ "totuple(cdr(testcore));>", "((\"abc\" . 8))" ],
|
|
319
|
+
[ "put(testcore, true, 9);", "9" ],
|
|
320
|
+
[ "get(testcore, true);", "9" ],
|
|
321
|
+
[ "cdr(testcore);>", "Dictionary{2}" ],
|
|
322
|
+
[ "totuple(cdr(testcore));>", "((\"abc\" . 8) (\"true\" . 9))" ],
|
|
323
|
+
|
|
324
|
+
[ "put(testcore, true, 9);", "9" ],
|
|
325
|
+
[ "totuple(cdr(testcore));>", "((\"abc\" . 8) (\"true\" . 9))" ],
|
|
326
|
+
[ "put(testcore, true, false);", "false" ],
|
|
327
|
+
[ "totuple(cdr(testcore));>", "((\"abc\" . 8) (\"true\"))" ],
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
//
|
|
331
|
+
// function definitions
|
|
332
|
+
//
|
|
333
|
+
|
|
334
|
+
[ "quote(function& (x,y) { x+y });>", "(function\\& lambda (x y) (+ x y))" ],
|
|
335
|
+
[ "function (x,y) { x+y };>", "(function lambda (x y) (+ x y))" ],
|
|
336
|
+
[ "function (x,y) { x+y }(4,3);", "7" ],
|
|
337
|
+
[ "(function (x,y) { x+y })(4,3);", "7" ],
|
|
338
|
+
[ "function temp(ex1, lex1) { ex1+pop(lex1), print(lex1), lex1 };", "temp" ],
|
|
339
|
+
[ "temp.proc;>", "(function temp (ex1 lex1) (+ ex1 (pop lex1)) (print lex1) lex1)" ],
|
|
340
|
+
[ "interned(temp);>", "temp" ],
|
|
341
|
+
[ "interned(temp.proc.1);>", "false" ],
|
|
342
|
+
[ "temp(2, `(1 2 3));>", "(2 3)|(2 3)" ],
|
|
343
|
+
[ "function (ex1, lex1) { ex1+pop(lex1), print(lex1), lex1 }(2, `(1 2 3));>", "(2 3)|(2 3)" ],
|
|
344
|
+
[ "quote(function (a)\n { f(b)-\ng(c) * h(d)\n });>", "(function lambda (a) (- (f b) (* (g c) (h d))))" ],
|
|
345
|
+
[ "quote(function (a)\n { f(b)\n-g(c) * h(d)\n });>", "(function lambda (a) (- (f b) (* (g c) (h d))))" ],
|
|
346
|
+
|
|
347
|
+
[ "tempo = temp.proc;>", "(function temp (ex1 lex1) (+ ex1 (pop lex1)) (print lex1) lex1)" ],
|
|
348
|
+
[ "function temp(ex1) { ex1 * 2 };", "==> redefined: temp|temp" ],
|
|
349
|
+
[ "temp(4);", "8" ],
|
|
350
|
+
[ "tempo(2, `(1,2,3));>", "(2 3)|(2 3)" ],
|
|
351
|
+
|
|
352
|
+
[ "apply(`+,list(2,3));", "5" ],
|
|
353
|
+
[ "apply(getproc(`+),list(4,5));", "9" ],
|
|
354
|
+
[ "call(`+,5,6);", "11" ],
|
|
355
|
+
[ "call(getproc(`+),6,7);", "13" ],
|
|
356
|
+
[ "putproc(tost, temp);", "temp"],
|
|
357
|
+
[ "tost(5);", "10"],
|
|
358
|
+
[ "getproc(tost);", "temp"],
|
|
359
|
+
[ "tost.proc;", "temp"],
|
|
360
|
+
[ "putproc(tost, tost);", "tost"],
|
|
361
|
+
[ "tost(5);", "false"],
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
//
|
|
365
|
+
// nested functions
|
|
366
|
+
//
|
|
367
|
+
|
|
368
|
+
[ "function nesty1() { function inner(x) { x }, inner(7) };", "nesty1" ],
|
|
369
|
+
[ "nesty1();", "7" ],
|
|
370
|
+
[ "function nesty2() { inner(5), function inner(x) { x }, inner(7) };", "nesty2" ],
|
|
371
|
+
[ "nesty2();", "7" ],
|
|
372
|
+
[ "function test1(a, b) { function inner() { print(\"a=\", a) }, inner(), if a<2 { test1(a+1), inner() } else inner() };", "test1" ],
|
|
373
|
+
[ "test1(0);", "a=0a=1a=2a=2a=1a=0|0" ],
|
|
374
|
+
[ "function test2(a, b) { function inner2() { print(\"a=\", a) }, inner2(), if a<2 { test2(a+1), inner2() } else inner2() };", "test2" ],
|
|
375
|
+
[ "test2(0);", "a=0a=1a=2a=2a=1a=0|0" ],
|
|
376
|
+
[ "closure test3(a, b) { function inner() { print(\"a=\", a) }, inner(), if a<2 { test3(a+1), inner() } else inner() };", "test3" ],
|
|
377
|
+
[ "test3(0);", "a=0a=1a=2a=2a=1a=0|0" ],
|
|
378
|
+
[ "function () { function t(a) { print(a) }, t(2) }();>", "2|2" ],
|
|
379
|
+
|
|
380
|
+
[ "apply(function(x) { closure() { print(x) } }(33),`(22));", "x|x" ],
|
|
381
|
+
[ "apply(closure(x) { function() { print(x) } }(33),`(22));", "33|33" ],
|
|
382
|
+
|
|
383
|
+
[ "function(b) { function(a) { print(\"a-\",a) }(b) }(9);", "a-9|9" ],
|
|
384
|
+
[ "function testb(b) { function(a) { print(\"a-\",a) }(b) };", "testb" ],
|
|
385
|
+
[ "function testc() { testb(c) };", "testc" ],
|
|
386
|
+
[ "testc();", "a-c|c" ],
|
|
387
|
+
[ "closure (c) { testc() }(4);", "a-c|c" ],
|
|
388
|
+
[ "closure (c) { function(c) { print(c), testc() }(5) }();", "5a-c|c" ],
|
|
389
|
+
[ "closure (c) { function(d) { print(d), testc() }(6) }(7);", "6a-c|c" ],
|
|
390
|
+
[ "eval(`(\"-\" 4 3));", "(\"-\", 4, 3)" ],
|
|
391
|
+
[ "$$=closure (c) { function(d) { print(c, \"-\", d) } }(7);>",
|
|
392
|
+
"(function lambda (d) (print c \"-\" d))" ],
|
|
393
|
+
[ "call($$,3);", "7-3|3" ],
|
|
394
|
+
|
|
395
|
+
[ "$$=function (a) { innert(13), function innert(b) { print(\"b-\", b) }, a };>",
|
|
396
|
+
"(function lambda (a) (innert 13) (function innert (b) (print \"b-\" b)) a)" ],
|
|
397
|
+
[ "call($$,3);", "b-13|3" ],
|
|
398
|
+
[ "innert(7);", "(innert, 7)" ],
|
|
399
|
+
|
|
400
|
+
[ "closure (a) { function inner(b) { totuple(cdr(inner)) }() }(55);>", "((\".parent\" . lambda))" ],
|
|
401
|
+
[ "closure (a) { function inner(b, local par, var) { par=get(inner,\\.parent), var = getproc(par).2.0, list(par, var, car(var)) }() }(55);>", "(lambda a 55)" ],
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
//
|
|
405
|
+
// catch/throw/finally
|
|
406
|
+
//
|
|
407
|
+
|
|
408
|
+
[ "try { print(\"try\") } finally { print(\"finally\") };", "tryfinally|\"try\"" ],
|
|
409
|
+
[ "throw(\"badness\");", { errors: "exception: badness" } ],
|
|
410
|
+
[ "function looper(x) { x = 1, loop { x = x+1, print(x), spaces(1), if x > 3 throw(done) } };", "looper" ],
|
|
411
|
+
[ "looper();", { errors: "exception: done", text: "2 3 4" } ],
|
|
412
|
+
[ "try { looper() } catch { if true { print(\"caught: \"), printline(exception), \"xo\" } } finally { printline(cleanup) };",
|
|
413
|
+
"2 3 4 caught: done|cleanup|\"xo\"" ],
|
|
414
|
+
[ "try { looper() } catch { if true { print(\"caught: \"), printline(exception), \"xo\" } } finally { throw(3) };",
|
|
415
|
+
{ errors: "exception: 3", text: "2 3 4 caught: done" } ],
|
|
416
|
+
[ "try { looper() } catch { if true { print(\"caught: \"), printline(exception), \"xo\" } } finally { printline(cleanup) };",
|
|
417
|
+
"2 3 4 caught: done|cleanup|\"xo\"" ],
|
|
418
|
+
[ "try { looper() } catch { if false { print(\"caught: \"), printline(exception), \"xo\" } } finally { printline(cleanup) };",
|
|
419
|
+
{ errors: "exception: done", text: "2 3 4 cleanup" } ],
|
|
420
|
+
[ "try { looper() } catch { if false { print(\"caught: \"), printline(exception), \"xo\" } } finally { throw(3), printline(cleanup) };",
|
|
421
|
+
{ errors: "exception: 3", text: "2 3 4" } ],
|
|
422
|
+
[ "try { throw(blah) } catch { if true try { throw(needer) } catch { if true exception } };",
|
|
423
|
+
"needer" ],
|
|
424
|
+
[ "try { print(hello), spaces(1) } finally { print(world) };",
|
|
425
|
+
"hello world|6" ],
|
|
426
|
+
[ "function tester() { try { looper() } finally { print(\"tester clean\") } };",
|
|
427
|
+
"tester" ],
|
|
428
|
+
[ "tester();",
|
|
429
|
+
{ errors: "exception: done", text: "2 3 4 tester clean" } ],
|
|
430
|
+
[ "try { tester() } catch { if true { print(\"caught: \"), printline(exception), \"xo\" } } finally { printline(cleanup) };",
|
|
431
|
+
"2 3 4 tester cleancaught: done|cleanup|\"xo\"" ],
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
//
|
|
435
|
+
// return
|
|
436
|
+
//
|
|
437
|
+
|
|
438
|
+
[ "return(33);", "33" ],
|
|
439
|
+
[ "function(x) { loop { loop { return(55) } } }();", "55" ],
|
|
440
|
+
[ "function(x) { loop { loop { 44, return } } }();", "44" ],
|
|
441
|
+
[ "function(x) { loop { loop { 3+2, return } } }();", "5" ],
|
|
442
|
+
|
|
443
|
+
[ "function testret x { loop { loop { return(77) } } };", "testret" ],
|
|
444
|
+
[ "testret();", "77" ],
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
//
|
|
448
|
+
// objects
|
|
449
|
+
//
|
|
450
|
+
|
|
451
|
+
[ "new();", "false" ],
|
|
452
|
+
[ "testo=new(object);", "Object{0}" ],
|
|
453
|
+
[ "testo.a=3;", "3" ],
|
|
454
|
+
[ "testo;", "Object{1}" ],
|
|
455
|
+
[ "testo.b=4;", "4" ],
|
|
456
|
+
[ "b=a;", "a" ],
|
|
457
|
+
[ "testo.b;", "4" ],
|
|
458
|
+
[ "testo;", "Object{2}" ],
|
|
459
|
+
[ "totuple(testo);>", "((\"a\" . 3) (\"b\" . 4))" ],
|
|
460
|
+
[ "testo1=new(testo);", "Object{2}" ],
|
|
461
|
+
[ "totuple(testo1);>", "((\"a\" . 3) (\"b\" . 4))" ],
|
|
462
|
+
[ "testo1.b=5;", "5" ],
|
|
463
|
+
[ "testo.b;", "4" ],
|
|
464
|
+
[ "testo.\"b\";", "4" ],
|
|
465
|
+
[ "xget(testo,\"b\");", "4" ],
|
|
466
|
+
[ "xget(testo,b);", "3" ], // b has value `a, and test.a is 3
|
|
467
|
+
[ "testo.f = function(x) { x+1 };>", "(function lambda (x) (+ x 1))" ],
|
|
468
|
+
[ "testo.f(5);", "6" ],
|
|
469
|
+
[ "apply(deref(testo, \"f\"), list(6));", "7" ],
|
|
470
|
+
|
|
471
|
+
[ "testo.length = 5;", "5" ],
|
|
472
|
+
[ "testo.length;", "5" ],
|
|
473
|
+
[ "length(testo);", "4" ],
|
|
474
|
+
[ "xget(testo, length);", "5" ],
|
|
475
|
+
[ "xkeys(testo);>", "(\"a\" \"b\" \"f\" \"length\")" ],
|
|
476
|
+
[ "totuple(testo);>", "((\"a\" . 3) (\"b\" . 4) (\"f\" function lambda (x) (+ x 1)) (\"length\" . 5))" ],
|
|
477
|
+
|
|
478
|
+
[ "testo1.4=c;", "c" ],
|
|
479
|
+
[ "testo1.4;", "c" ],
|
|
480
|
+
|
|
481
|
+
[ "this = true;", { errors: "can't modify NaanCore::this from Test-core" } ],
|
|
482
|
+
|
|
483
|
+
[ "joe={};", "{ }" ],
|
|
484
|
+
[ "joe.sam=function(x) { print(x, \"|\", keys(joe)) };>", "(function lambda (x) (print x \"|\" (keys joe)))" ],
|
|
485
|
+
[ "joe.sam(joe);", "Dictionary{1}|(sam)|(\"sam\")" ],
|
|
486
|
+
[ "joe.nevil=function nevil x { print(x, \"|\", keys(joe)) };", "nevil" ],
|
|
487
|
+
[ "joe.nevil(joe);", "(Dictionary{2})|(sam nevil)|(\"sam\", \"nevil\")" ],
|
|
488
|
+
[ "joe.bill=getproc(`cons);", "[Builtin cons]" ],
|
|
489
|
+
[ "joe.bill(3,4);>", "(3 . 4)" ],
|
|
490
|
+
[ "joe;", "{\n"
|
|
491
|
+
" sam : function (x) {\n"
|
|
492
|
+
" print(x, \"|\", keys(joe))\n"
|
|
493
|
+
" },\n"
|
|
494
|
+
" nevil: nevil,\n"
|
|
495
|
+
" bill : [Builtin cons] }" ],
|
|
496
|
+
|
|
497
|
+
[ "bobby={};", "{ }" ],
|
|
498
|
+
[ "bobby.sue = 4;", "4" ],
|
|
499
|
+
[ "bobby.billy=function(y) { print(y, keys(bobby),\"/\"), joe.sam(bobby), print(\"/\", keys(bobby)) };",
|
|
500
|
+
"function (y) {\n"
|
|
501
|
+
" print(y, keys(bobby), \"/\")\n"
|
|
502
|
+
" joe.sam(bobby)\n"
|
|
503
|
+
" print(\"/\", keys(bobby))\n"
|
|
504
|
+
"}" ],
|
|
505
|
+
[ "bobby.sue=function sue yy { print(yy, keys(bobby), \"/\"), joe.sam(bobby), print(\"/\", keys(bobby)) };", "sue" ],
|
|
506
|
+
[ "bobby.billy(33);", "33(sue billy)/Dictionary{2}|(sam nevil bill)/(sue billy)|(\"sue\", \"billy\")" ],
|
|
507
|
+
[ "bobby.sue(44);", "(44)(sue billy)/Dictionary{2}|(sam nevil bill)/(sue billy)|(\"sue\", \"billy\")" ],
|
|
508
|
+
[ "keys(bobby);>", "(\"sue\" \"billy\")" ],
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
//
|
|
512
|
+
// object getters
|
|
513
|
+
//
|
|
514
|
+
|
|
515
|
+
[ "oo=new(object);", "Object{0}" ],
|
|
516
|
+
[ "oo['..prop'] = function(value) { oo.value };>", "(function lambda (value) (`. oo value))" ],
|
|
517
|
+
[ "oo['.=prop'] = function(value) { oo.value = value };>", "(function lambda (value) (Lib::set\\. oo (`` value) value))" ],
|
|
518
|
+
[ "oo.prop = 8;", "8" ],
|
|
519
|
+
[ "oo.prop;", "8" ],
|
|
520
|
+
[ "oo['prop'] = 9;", "9" ],
|
|
521
|
+
[ "oo['prop'];", "9" ],
|
|
522
|
+
[ "xget(oo, 'prop');", "false" ],
|
|
523
|
+
[ "xset(oo, 'value', 10);", "10" ],
|
|
524
|
+
[ "xget(oo, 'value');", "10" ],
|
|
525
|
+
[ "oo.prop;", "10" ],
|
|
526
|
+
[ "xset(oo, 'prop', 11);", "11" ],
|
|
527
|
+
[ "oo.prop;", "11" ],
|
|
528
|
+
[ "oo.value;", "10" ],
|
|
529
|
+
[ "oo.*;", '("..prop", ".=prop", "value", "prop")' ],
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
//
|
|
533
|
+
// object hooks
|
|
534
|
+
//
|
|
535
|
+
|
|
536
|
+
[ "oo=new(object);", "Object{0}" ],
|
|
537
|
+
[ "oo.v=4;", "4" ],
|
|
538
|
+
[ "oo.\\.negate = function \\.negate(o) { printline(\".negate \", o, \" \", o.v), -o.v };", "\\.negate" ],
|
|
539
|
+
[ "-oo;",
|
|
540
|
+
".negate Object{2} 4|-4" ],
|
|
541
|
+
|
|
542
|
+
[ "oo.\\.plus = function \\.plus vv { printline(\".plus \", vv), \\.plus };", "\\.plus" ],
|
|
543
|
+
[ "oo + 5;",
|
|
544
|
+
".plus (Object{3} 5)|\\.plus" ],
|
|
545
|
+
[ "5 + oo;",
|
|
546
|
+
".plus (5 Object{3})|\\.plus" ],
|
|
547
|
+
[ "plus(oo);", "Object{3}" ],
|
|
548
|
+
|
|
549
|
+
[ "oo.\\.difference = function \\.difference vv { printline(\".difference \", vv), \\.difference };", "\\.difference" ],
|
|
550
|
+
[ "oo - 6;",
|
|
551
|
+
".difference (Object{4} 6)|\\.difference" ],
|
|
552
|
+
[ "6 - oo;",
|
|
553
|
+
".difference (6 Object{4})|\\.difference" ],
|
|
554
|
+
[ "-oo;",
|
|
555
|
+
".negate Object{4} 4|-4" ],
|
|
556
|
+
[ "difference(oo);",
|
|
557
|
+
".negate Object{4} 4|-4" ],
|
|
558
|
+
|
|
559
|
+
[ "oo.\\.times = function \\.times vv { printline(\".times \", vv), \\.times };", "\\.times" ],
|
|
560
|
+
[ "oo * 7;",
|
|
561
|
+
".times (Object{5} 7)|\\.times" ],
|
|
562
|
+
[ "7 * oo;",
|
|
563
|
+
".times (7 Object{5})|\\.times" ],
|
|
564
|
+
|
|
565
|
+
[ "oo.\\.quotient = function \\.quotient vv { printline(\".quotient \", vv), \\.quotient };", "\\.quotient" ],
|
|
566
|
+
[ "oo / 8;",
|
|
567
|
+
".quotient (Object{6} 8)|\\.quotient" ],
|
|
568
|
+
[ "8 / oo;",
|
|
569
|
+
".quotient (8 Object{6})|\\.quotient" ],
|
|
570
|
+
|
|
571
|
+
[ "oo.\\.modulo = function \\.modulo vv { printline(\".modulo \", vv), \\.modulo };", "\\.modulo" ],
|
|
572
|
+
[ "mod(oo, 9);",
|
|
573
|
+
".modulo (Object{7} 9)|\\.modulo" ],
|
|
574
|
+
[ "mod(9, oo);",
|
|
575
|
+
".modulo (9 Object{7})|\\.modulo" ],
|
|
576
|
+
|
|
577
|
+
[ "oo.\\.divide = function \\.divide vv { printline(\".divide \", vv), \\.divide };", "\\.divide" ],
|
|
578
|
+
[ "divide(oo, 10);",
|
|
579
|
+
".divide (Object{8} 10)|\\.divide" ],
|
|
580
|
+
[ "divide(10, oo);",
|
|
581
|
+
".divide (10 Object{8})|\\.divide" ],
|
|
582
|
+
|
|
583
|
+
[ "oo.\\.greater = function \\.greater vv { printline(\".greater \", vv), \\.greater };", "\\.greater" ],
|
|
584
|
+
[ "oo > 11;",
|
|
585
|
+
".greater (Object{9} 11)|\\.greater" ],
|
|
586
|
+
[ "11 > oo;",
|
|
587
|
+
".greater (11 Object{9})|\\.greater" ],
|
|
588
|
+
|
|
589
|
+
[ "oo.\\.lesser = function \\.lesser vv { printline(\".lesser \", vv), \\.lesser };", "\\.lesser" ],
|
|
590
|
+
[ "oo < 12;",
|
|
591
|
+
".lesser (Object{10} 12)|\\.lesser" ],
|
|
592
|
+
[ "12 < oo;",
|
|
593
|
+
".lesser (12 Object{10})|\\.lesser" ],
|
|
594
|
+
|
|
595
|
+
[ "oo.\\.tofloat = function \\.tofloat vv { printline(\".tofloat \", vv), \\.tofloat };", "\\.tofloat" ],
|
|
596
|
+
[ "tofloat(oo);",
|
|
597
|
+
".tofloat (Object{11})|\\.tofloat" ],
|
|
598
|
+
|
|
599
|
+
[ "oo.\\.numeric = function \\.numeric vv { printline(\".numeric \", vv), \\.numeric };", "\\.numeric" ],
|
|
600
|
+
[ "numeric(oo, 14);",
|
|
601
|
+
".numeric (Object{12} 14)|\\.numeric" ],
|
|
602
|
+
[ "numeric(14, oo);",
|
|
603
|
+
".numeric (14 Object{12})|\\.numeric" ],
|
|
604
|
+
[ "numeric(14, oo, 15);",
|
|
605
|
+
".numeric (14 Object{12} 15)|\\.numeric" ],
|
|
606
|
+
|
|
607
|
+
[ "oo.\\.preadjust = function \\.preadjust vv { printline(\".preadjust \", vv), \\.preadjust };", "\\.preadjust" ],
|
|
608
|
+
[ "oo.\\.postadjust = function \\.postadjust vv { printline(\".postadjust \", vv), \\.postadjust };", "\\.postadjust" ],
|
|
609
|
+
[ "preadjust(oo, `+, 1);",
|
|
610
|
+
".preadjust (Object{14} + 1)|\\.preadjust" ],
|
|
611
|
+
[ "postadjust(oo, `+, 1);",
|
|
612
|
+
".postadjust (Object{14} + 1)|\\.postadjust" ],
|
|
613
|
+
[ "preadjust(oo.v, `+, 1);", "5" ],
|
|
614
|
+
[ "postadjust(oo.v, `+, 1);", "5" ],
|
|
615
|
+
[ "oo.v;", "6" ],
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
//
|
|
619
|
+
// arrays
|
|
620
|
+
//
|
|
621
|
+
|
|
622
|
+
[ "new();", "false" ],
|
|
623
|
+
[ "testa=new(array);", "[]" ],
|
|
624
|
+
[ "testa.0=2;", "2" ],
|
|
625
|
+
[ "testa;", "[2]" ],
|
|
626
|
+
[ "totuple(testa);>", "(2)" ],
|
|
627
|
+
[ "testa.2=5;", "5" ],
|
|
628
|
+
[ "testa.2;", "5" ],
|
|
629
|
+
[ "testa.1;", "false" ],
|
|
630
|
+
[ "totuple(testa);>", "(2 false 5)" ],
|
|
631
|
+
[ "testa1=new(testa);>", "Array[3]" ],
|
|
632
|
+
[ "totuple(testa1);>", "(2 false 5)" ],
|
|
633
|
+
[ "testa1.2=6;", "6" ],
|
|
634
|
+
[ "testa1.1;", "false" ],
|
|
635
|
+
[ "testa.2;", "5" ],
|
|
636
|
+
[ "xget(testa,testa.0);", "5" ], // testa.0 is 2, so this is returning testa.2, which is 5
|
|
637
|
+
[ "xget(testa,length);", "3" ],
|
|
638
|
+
[ "testa.length;", "3" ],
|
|
639
|
+
[ "testa.length = 4;", "4" ],
|
|
640
|
+
[ "testa.length;", "4" ],
|
|
641
|
+
[ "xget(testa,length);", "4" ],
|
|
642
|
+
[ "testa.3;", "false" ],
|
|
643
|
+
[ "totuple(testa);>", "(2 false 5 undefined)" ],
|
|
644
|
+
|
|
645
|
+
[ "totuple(testc = new(array).concat(1, 3, 5, 7, 9));>", "(1 3 5 7 9)" ],
|
|
646
|
+
[ "totuple(testc.copyWithin(0,4));>", "(9 3 5 7 9)" ],
|
|
647
|
+
[ "testc.pop();", "9" ],
|
|
648
|
+
[ "totuple(testc);>", "(9 3 5 7)" ],
|
|
649
|
+
[ "testc.push(9, 1);", "6" ],
|
|
650
|
+
[ "totuple(testc.reverse());>", "(1 9 7 5 3 9)" ],
|
|
651
|
+
[ "testc.shift();>", "1" ],
|
|
652
|
+
[ "totuple(testc.slice(1,3));>", "(7 5)" ],
|
|
653
|
+
[ "totuple(testc.sort(function(a,b) { a-b }));>", "(3 5 7 9 9)" ],
|
|
654
|
+
[ "totuple(testc.splice(-1, 1, 2, 4, 6, 8));>", "(9)" ],
|
|
655
|
+
[ "totuple(testc);>", "(3 5 7 9 2 4 6 8)" ],
|
|
656
|
+
[ "testc.unshift(0, 1);", "10" ],
|
|
657
|
+
[ "totuple(testc.sort(function(a,b) { a-b }));>", "(0 1 2 3 4 5 6 7 8 9)" ],
|
|
658
|
+
[ "totuple(testc.fill(`x, 1, 9));>", "(0 x x x x x x x x 9)" ],
|
|
659
|
+
|
|
660
|
+
[ "(acc=\"\") and testc.every(function(e,i,a) { acc=strcat(acc,e) }) and print(acc);", "0xxxxxxxx9|\"0xxxxxxxx9\"" ],
|
|
661
|
+
[ "totuple(testc.filter(function(e,i,a) { numeric(e) }));>", "(0 9)" ],
|
|
662
|
+
[ "testc.find(function(e,i,a) { printline(e, \"/\", i, \"/\", a),if e eq x { } });",
|
|
663
|
+
"0/0/Array[10]|x/1/Array[10]|x" ],
|
|
664
|
+
[ "testc.findIndex(function(e,i,a) { if e eq x { } });", "1" ],
|
|
665
|
+
[ "testc.forEach(function(e,i,a) { print(e) });", "0xxxxxxxx9|undefined" ],
|
|
666
|
+
[ "totuple(testc.map(function(e,i,a) { if e eq x `* else e }));>", "(0 * * * * * * * * 9)" ],
|
|
667
|
+
[ "testc.some(function(e,i,a) { printline(e, \"/\", i, \"/\", a), if e eq x { } });",
|
|
668
|
+
"0/0/Array[10]|x/1/Array[10]|true" ],
|
|
669
|
+
|
|
670
|
+
[ "totuple(Naan.array.arraycall(testc, splice, 1, 8, 1, 2, 3, 4, 5, 6, 7, 8));>", "(x x x x x x x x)" ],
|
|
671
|
+
[ "totuple(Naan.array.arraycall(testc, sort, function(a,b) { b-a }));>", "(9 8 7 6 5 4 3 2 1 0)" ],
|
|
672
|
+
|
|
673
|
+
[ "testc.indexOf(8);", "1" ],
|
|
674
|
+
[ "testc.lastIndexOf(8);", "1" ],
|
|
675
|
+
[ "testc.indexOf(8,2);", "-1" ],
|
|
676
|
+
[ "testc.lastIndexOf(8,-2);", "1" ],
|
|
677
|
+
|
|
678
|
+
[ "new(array).shift();>", "undefined" ],
|
|
679
|
+
[ "totuple(new(array).concat(w, x, y, z));>", "(w x y z)" ],
|
|
680
|
+
|
|
681
|
+
[ "Array(1,2,3).forEach(function(x) { print(x),return });", "123|undefined" ],
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
//
|
|
685
|
+
// dates
|
|
686
|
+
//
|
|
687
|
+
|
|
688
|
+
[ "Date(\"9/23/1960\").getDay();", "5" ],
|
|
689
|
+
[ "Date(\"9/23/1960\").getDate();", "23" ],
|
|
690
|
+
[ "eval(`(Date, 1960, 9, 23)).getFullYear();", "1960" ],
|
|
691
|
+
[ "Date(Date.UTC(1960,8,24,1,59,00)).toUTCString();", "\"Sat, 24 Sep 1960 01:59:00 GMT\"" ],
|
|
692
|
+
[ "quote(Date(3));>", "(Date 3)" ],
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
//
|
|
696
|
+
// strings
|
|
697
|
+
//
|
|
698
|
+
|
|
699
|
+
[ "\"abcdefghi\".replace(\"d\", function(m) { \"q\" });", "\"abcqefghi\"" ],
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
//
|
|
703
|
+
// other builtins
|
|
704
|
+
//
|
|
705
|
+
|
|
706
|
+
[ "cons();", "false" ],
|
|
707
|
+
[ "cons(`a);>", "(a)" ],
|
|
708
|
+
[ "cons(`a,`b);>", "(a . b)" ],
|
|
709
|
+
[ "cons(`a,`b,`c);>", "(a b . c)" ],
|
|
710
|
+
[ "length(stacktrace());", "54" ],
|
|
711
|
+
|
|
712
|
+
//
|
|
713
|
+
// lower builtin
|
|
714
|
+
//
|
|
715
|
+
|
|
716
|
+
[ "lower(1, 1);", "false" ],
|
|
717
|
+
[ "lower(1, 2);", "true" ],
|
|
718
|
+
[ "lower(2, 1);", "false" ],
|
|
719
|
+
[ "lower(1.0, 1.0);", "false" ],
|
|
720
|
+
[ "lower(1.0, 2.0);", "true" ],
|
|
721
|
+
[ "lower(2.0, 1.0);", "false" ],
|
|
722
|
+
[ "lower(1, 1.0);", "true" ],
|
|
723
|
+
[ "lower(1, 2.0);", "true" ],
|
|
724
|
+
[ "lower(2, 1.0);", "true" ],
|
|
725
|
+
[ "lower(1.0, 1);", "false" ],
|
|
726
|
+
[ "lower(1.0, 2);", "false" ],
|
|
727
|
+
[ "lower(2.0, 1);", "false" ],
|
|
728
|
+
|
|
729
|
+
[ "lower(\"abc\", \"abc\");", "false" ],
|
|
730
|
+
[ "lower(\"abc\", \"def\");", "true" ],
|
|
731
|
+
[ "lower(\"def\", \"abc\");", "false" ],
|
|
732
|
+
[ "lower(\"abc\", 1);", "false" ],
|
|
733
|
+
[ "lower(\"abc\", 1.0);", "false" ],
|
|
734
|
+
[ "lower(1, \"def\");", "true" ],
|
|
735
|
+
[ "lower(1.0, \"def\");", "true" ],
|
|
736
|
+
|
|
737
|
+
[ "lower(car(nsactive(true)), car(nsactive(true)));", "false" ],
|
|
738
|
+
[ "lower(car(nsactive(true)), cadr(nsactive(true)));", "false" ],
|
|
739
|
+
[ "lower(cadr(nsactive(true)), car(nsactive(true)));", "true" ],
|
|
740
|
+
|
|
741
|
+
[ "lower(a, a);", "false" ],
|
|
742
|
+
[ "lower(a, b);", "false" ],
|
|
743
|
+
[ "lower(b, a);", "false" ],
|
|
744
|
+
|
|
745
|
+
[ "lower(a, 1);", "false" ],
|
|
746
|
+
[ "lower(a, 1.0);", "false" ],
|
|
747
|
+
[ "lower(a, \"def\");", "true" ],
|
|
748
|
+
[ "lower(a, car(nsactive(true)));", "true" ],
|
|
749
|
+
[ "lower(1, b);", "true" ],
|
|
750
|
+
[ "lower(1, \"def\");", "true" ],
|
|
751
|
+
[ "lower(1, car(nsactive(true)));", "true" ],
|
|
752
|
+
[ "lower(1.0, b);", "true" ],
|
|
753
|
+
[ "lower(1.0, \"def\");", "true" ],
|
|
754
|
+
[ "lower(1.0, car(nsactive(true)));", "true" ],
|
|
755
|
+
[ "lower(\"abc\", b);", "false" ],
|
|
756
|
+
[ "lower(\"abc\", 1);", "false" ],
|
|
757
|
+
[ "lower(\"abc\", 1.0);", "false" ],
|
|
758
|
+
[ "lower(\"abc\", car(nsactive(true)));", "true" ],
|
|
759
|
+
[ "lower(car(nsactive(true)), b);", "false" ],
|
|
760
|
+
[ "lower(car(nsactive(true)), 1);", "false" ],
|
|
761
|
+
[ "lower(car(nsactive(true)), 1.0);", "false" ],
|
|
762
|
+
|
|
763
|
+
//
|
|
764
|
+
// mangled
|
|
765
|
+
//
|
|
766
|
+
|
|
767
|
+
[ "mangled();", "true" ],
|
|
768
|
+
]);
|