functionalscript 0.0.423 → 0.0.424

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.423",
3
+ "version": "0.0.424",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
package/test.f.cjs CHANGED
@@ -1,95 +1,58 @@
1
1
  const i = require('./module.f.cjs')
2
2
 
3
- require('./types/list/test.f.cjs')
4
- require('./types/number/test.f.cjs')
5
- require('./types/bigint/module.f.cjs')
6
- require('./types/array/test.f.cjs')
7
- require('./types/btree/test.f.cjs')
8
- require('./types/byteSet/test.f.cjs')
9
- require('./types/nibbleSet/test.f.cjs')
10
- require('./sha2/test.f.cjs')
11
- require('./types/map/test.f.cjs')
12
- require('./json/test.f.cjs')
13
- require('./types/string/test.f.cjs')
14
- require('./json/tokenizer/test.f.cjs')
15
- require('./types/object/test.f.cjs')
16
- // require('./commonjs/test.cjs')
17
- require('./commonjs/package/dependencies/test.f.cjs')
18
- require('./commonjs/package/test.f.cjs')
19
- require('./commonjs/path/test.f.cjs')
20
- require('./types/function/test.f.cjs')
21
- require('./types/function/compare/test.f.cjs')
22
- require('./types/stringset/test.f.cjs')
23
- require('./types/option/test.f.cjs')
24
- require('./commonjs/build/test.f.cjs')
25
- require('./types/range/test.f.cjs')
26
- require('./html/test.f.cjs')
27
- require('./text/test.f.cjs')
28
- require('./text/utf8/test.f.cjs')
29
- require('./text/utf16/test.f.cjs')
30
- require('./com/cs/test.f.cjs')
31
- require('./com/cpp/test.f.cjs')
32
- require('./nodejs/version/test.f.cjs')
33
- require('./com/rust/test.f.cjs')
34
-
35
3
  /** @type {() => never} */
36
4
  const assert = () => { throw 'assert' }
37
5
 
38
6
  /** @type {(_: boolean) => void} */
39
7
  const assert_if = c => { if (c) { throw 'assert_if' } }
40
8
 
41
- {
42
- const c = (()=>{})['constructor']
43
- const f = c('return 5')
44
- const result = f()
45
- if (result !== 5) { throw 'function' }
46
- }
47
-
48
- {
49
- /** @type {any} */
50
- const o = {}
51
- const c = o['constructor']
52
- // console.log(c)
53
- // console.log(c(()=>{}))
54
- }
55
-
56
- {
57
- /** @type {any} */
58
- const o = {
59
- constructor: undefined
9
+ module.exports = {
10
+ ctor: () => {
11
+ const c = (() => { })['constructor']
12
+ const f = c('return 5')
13
+ const result = f()
14
+ if (result !== 5) { throw 'function' }
15
+ },
16
+ ctorEmpty: () => {
17
+ /** @type {any} */
18
+ const o = {}
19
+ const c = o['constructor']
20
+ // console.log(c)
21
+ // console.log(c(()=>{}))
22
+ },
23
+ ctorUndefined: () => {
24
+ /** @type {any} */
25
+ const o = {
26
+ constructor: undefined
27
+ }
28
+ const c = o['constructor']
29
+ //console.log(c)
30
+ },
31
+ number: () => {
32
+ /** @type {any} */
33
+ const b = '42'
34
+ const r = Number(b)
35
+ //console.log(r)
36
+ },
37
+ properties: () => {
38
+ /** @type {any} */
39
+ const o = {}
40
+ //const c = o['constructor']
41
+ //const c = o['__proto__']
42
+ //const c = o['__defineGetter__']
43
+ //const c = o['__defineSetter__']
44
+ //const c = o['__lookupGetter__']
45
+ //const c = o['__lookupSetter__']
46
+ //const c = o['hasOwnProperty']
47
+ //const c = o['isPrototypeOf']
48
+ //const c = o['propertyIsEnumerable']
49
+ //const c = o['toString']
50
+ const c = o['valueOf']
51
+ //console.log(c)
52
+ },
53
+ getOwnPropertyDescriptor: () => {
54
+ const x = { 'a': 12 }
55
+ const c = Object.getOwnPropertyDescriptor(x, 'constructor')
56
+ const a = Object.getOwnPropertyDescriptor(x, 'a')
60
57
  }
61
- const c = o['constructor']
62
- //console.log(c)
63
- }
64
-
65
- {
66
- /** @type {any} */
67
- const b = '42'
68
- const r = Number(b)
69
- //console.log(r)
70
- }
71
-
72
- {
73
- /** @type {any} */
74
- const o = {}
75
- //const c = o['constructor']
76
- //const c = o['__proto__']
77
- //const c = o['__defineGetter__']
78
- //const c = o['__defineSetter__']
79
- //const c = o['__lookupGetter__']
80
- //const c = o['__lookupSetter__']
81
- //const c = o['hasOwnProperty']
82
- //const c = o['isPrototypeOf']
83
- //const c = o['propertyIsEnumerable']
84
- //const c = o['toString']
85
- const c = o['valueOf']
86
- //console.log(c)
87
- }
88
-
89
- {
90
- const x = { 'a': 12 }
91
- const c = Object.getOwnPropertyDescriptor(x, 'constructor')
92
- const a = Object.getOwnPropertyDescriptor(x, 'a')
93
- }
94
-
95
- module.exports = {}
58
+ }
package/test.mjs CHANGED
@@ -21,9 +21,28 @@
21
21
  /** @type {FsPromises} */
22
22
  const { readdir, readFile } = await import(globalThis.Deno ? 'https://deno.land/std/node/fs/promises.ts' : 'node:fs/promises')
23
23
 
24
- const load = async() => {
25
- /** @type {FunctionMap} */
26
- const map = {}
24
+ /** @typedef {{ exports?: unknown }} Module */
25
+
26
+ /** @typedef {(name: string) => unknown} Require */
27
+
28
+ /**
29
+ * @typedef {{
30
+ * readonly[k in string]: Function
31
+ * }} FunctionMap
32
+ */
33
+
34
+ /**
35
+ * @template T
36
+ * @typedef {readonly[string, T]} Entry
37
+ */
38
+
39
+ /** @type {(a: Entry<Function>, b: Entry<Function>) => number} */
40
+ const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
41
+
42
+ /** @type {() => Promise<FunctionMap>} */
43
+ const load = async () => {
44
+ /** @type {(readonly[string, Function])[]} */
45
+ const map = []
27
46
  /** @type {(path: string) => Promise<void>} */
28
47
  const f = async p => {
29
48
  for (const i of await readdir(p, { withFileTypes: true })) {
@@ -37,27 +56,18 @@ const load = async() => {
37
56
  } else if (name.endsWith('.f.cjs')) {
38
57
  console.log(`loading ${file}`)
39
58
  const source = await readFile(file, 'utf8')
40
- map[file] = Function('module', 'require', `"use strict";${source}`)
59
+ map.push([file, Function('module', 'require', `"use strict";${source}`)])
41
60
  }
42
61
  }
43
62
  }
44
63
  }
45
64
  await f('.')
46
- return map
65
+ map.sort(cmp)
66
+ return Object.fromEntries(map)
47
67
  }
48
68
 
49
69
  const map = await load()
50
70
 
51
- /** @typedef {{ exports?: unknown }} Module */
52
-
53
- /** @typedef {(name: string) => unknown} Require */
54
-
55
- /**
56
- * @typedef {{
57
- * [k in string]: Function
58
- * }} FunctionMap
59
- */
60
-
61
71
  /**
62
72
  * @typedef {{
63
73
  * [k in string]: unknown
@@ -96,3 +106,37 @@ const build = async () => {
96
106
  }
97
107
 
98
108
  const modules = await build()
109
+
110
+ const test = i => v => {
111
+ switch (typeof v) {
112
+ case 'function': {
113
+ if (v.length === 0) {
114
+ const r = v()
115
+ console.log(`${i}() passed`)
116
+ test(`${i}| `)(r)
117
+ }
118
+ return;
119
+ }
120
+ case 'object': {
121
+ if (v instanceof Array) {
122
+ for (const v2 of v) {
123
+ test(`${i}| `)(v2)
124
+ }
125
+ } else {
126
+ for (const [k, v2] of Object.entries(v)) {
127
+ const i2 = `${i}| `
128
+ console.log(`${i}${k}:`)
129
+ test(i2)(v2)
130
+ }
131
+ }
132
+ return;
133
+ }
134
+ }
135
+ }
136
+
137
+ for (const [k, v] of Object.entries(modules)) {
138
+ if (k.endsWith('test.f.cjs')) {
139
+ console.log(`testing ${k}`)
140
+ test('| ')(v)
141
+ }
142
+ }
@@ -89,6 +89,4 @@ const stringify = a => json.stringify(sort)(a)
89
89
  if (result !== undefined) {throw result}
90
90
  }
91
91
 
92
- module.exports = {
93
-
94
- }
92
+ module.exports = {}
@@ -1,8 +1,8 @@
1
1
  const { sum } = require('./module.f.cjs')
2
2
 
3
- {
4
- const result = sum([2n, 3n, 4n, 5n])
5
- if (result !== 14n) { throw result }
6
- }
7
-
8
- module.exports = {}
3
+ module.exports = {
4
+ sum: () => {
5
+ const result = sum([2n, 3n, 4n, 5n])
6
+ if (result !== 14n) { throw result }
7
+ }
8
+ }
@@ -1,44 +1,41 @@
1
1
  const { join, concat, repeat, cmp } = require('./module.f.cjs')
2
2
  const { repeat: repeatList } = require('../list/module.f.cjs')
3
3
 
4
- {
5
- const result = join('/')([])
6
- if (result !== '') { throw result }
4
+ module.exports = {
5
+ join: {
6
+ 0: () => {
7
+ const result = join('/')([])
8
+ if (result !== '') { throw result }
9
+ },
10
+ 1: () => {
11
+ const result = join('/')([''])
12
+ if (result !== '') { throw result }
13
+ },
14
+ 3: () => {
15
+ const result = join(' ')(['hello', 'world', '!'])
16
+ if (result !== 'hello world !') { throw result }
17
+ }
18
+ },
19
+ concat: () => {
20
+ const result = concat(['hello', 'world'])
21
+ if (result !== 'helloworld') { throw result }
22
+ },
23
+ repeatList: {
24
+ 0: () => {
25
+ const s = join('.')(repeatList('x')(0))
26
+ if (s != '') { throw s }
27
+ },
28
+ 5: () => {
29
+ const s = join('.')(repeatList('x')(5))
30
+ if (s != 'x.x.x.x.x') { throw s }
31
+ }
32
+ },
33
+ repeat: () => {
34
+ const s = repeat('x')(5)
35
+ if(s != 'xxxxx') { throw s }
36
+ },
37
+ cmp: () => {
38
+ const result = cmp('3')('4')
39
+ if (result !== -1) { throw result }
40
+ }
7
41
  }
8
-
9
- {
10
- const result = join('/')([''])
11
- if (result !== '') { throw result }
12
- }
13
-
14
- {
15
- const result = join(' ')(['hello', 'world', '!'])
16
- if (result !== 'hello world !') { throw result }
17
- }
18
-
19
- {
20
- const result = concat(['hello', 'world'])
21
- if (result !== 'helloworld') { throw result }
22
- }
23
-
24
- {
25
- const s = join('.')(repeatList('x')(0))
26
- if (s != '') { throw s }
27
- }
28
-
29
- {
30
- const s = join('.')(repeatList('x')(5))
31
- if (s != 'x.x.x.x.x') { throw s }
32
- }
33
-
34
- {
35
- const s = repeat('x')(5)
36
- if (s != 'xxxxx') { throw s }
37
- }
38
-
39
- {
40
- const result = cmp('3')('4')
41
- if (result !== -1) { throw result }
42
- }
43
-
44
- module.exports = {}
@@ -1,35 +1,34 @@
1
1
  const _ = require('./module.f.cjs')
2
2
 
3
- {
4
- const r = _.set('hello')(undefined)
5
- if (!_.contains('hello')(r)) { throw r }
6
- if (_.contains('hello1')(r)) { throw r }
7
- }
8
-
9
- {
10
- let r = _.set('hello')(undefined)
11
- r = _.set('world')(r)
12
- r = _.set('HELLO')(r)
13
- r = _.set('WORLD!')(r)
14
- if (!_.contains('hello')(r)) { throw r }
15
- if (_.contains('hello1')(r)) { throw r }
16
- if (!_.contains('HELLO')(r)) { throw r }
17
- if (_.contains('WORLD')(r)) { throw r }
18
- if (!_.contains('world')(r)) { throw r }
19
- if (_.contains('world!')(r)) { throw r }
20
- if (!_.contains('WORLD!')(r)) { throw r }
21
- //
22
- r = _.remove('hello')(r)
23
- if (_.contains('hello')(r)) { throw r }
24
- if (!_.contains('world')(r)) { throw r }
25
- r = _.remove('world')(r)
26
- if (_.contains('world')(r)) { throw r }
27
- if (!_.contains('HELLO')(r)) { throw r }
28
- r = _.remove('HELLO')(r)
29
- if (_.contains('HELLO')(r)) { throw r }
30
- if (!_.contains('WORLD!')(r)) { throw r }
31
- r = _.remove('WORLD!')(r)
32
- if (r !== undefined) { throw r }
33
- }
34
-
35
- module.exports = {}
3
+ module.exports = {
4
+ contains: () => {
5
+ const r = _.set('hello')(undefined)
6
+ if (!_.contains('hello')(r)) { throw r }
7
+ if (_.contains('hello1')(r)) { throw r }
8
+ },
9
+ remove: () => {
10
+ let r = _.set('hello')(undefined)
11
+ r = _.set('world')(r)
12
+ r = _.set('HELLO')(r)
13
+ r = _.set('WORLD!')(r)
14
+ if (!_.contains('hello')(r)) { throw r }
15
+ if (_.contains('hello1')(r)) { throw r }
16
+ if (!_.contains('HELLO')(r)) { throw r }
17
+ if (_.contains('WORLD')(r)) { throw r }
18
+ if (!_.contains('world')(r)) { throw r }
19
+ if (_.contains('world!')(r)) { throw r }
20
+ if (!_.contains('WORLD!')(r)) { throw r }
21
+ //
22
+ r = _.remove('hello')(r)
23
+ if (_.contains('hello')(r)) { throw r }
24
+ if (!_.contains('world')(r)) { throw r }
25
+ r = _.remove('world')(r)
26
+ if (_.contains('world')(r)) { throw r }
27
+ if (!_.contains('HELLO')(r)) { throw r }
28
+ r = _.remove('HELLO')(r)
29
+ if (_.contains('HELLO')(r)) { throw r }
30
+ if (!_.contains('WORLD!')(r)) { throw r }
31
+ r = _.remove('WORLD!')(r)
32
+ if (r !== undefined) { throw r }
33
+ }
34
+ }