functionalscript 0.0.156 → 0.0.157
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/index.js +0 -4
- package/iterable/test.js +12 -12
- package/lib/index.js +1 -28
- package/map/test.js +4 -5
- package/module-manager/test.js +22 -17
- package/package.json +1 -1
- package/test.js +2 -2
package/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
const lib = require('./lib')
|
|
4
2
|
|
|
5
|
-
const todo = () => lib.panic('not implemented')
|
|
6
|
-
|
|
7
3
|
/** @type {<F>(c: string, found: (before: string, after: string) => F, notFound: (c: string, source: string) => F) => (source: string) => F} */
|
|
8
4
|
const splitOne = (c, found, notFound) => source => {
|
|
9
5
|
const i = source.indexOf(c)
|
package/iterable/test.js
CHANGED
|
@@ -3,30 +3,30 @@ const lib = require('../lib')
|
|
|
3
3
|
|
|
4
4
|
{
|
|
5
5
|
const r = i.sum([120, 300, 42])
|
|
6
|
-
|
|
6
|
+
if (r !== 462) { throw 'error' }
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
{
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
if (i.sum([1, 2]) !== 3) { throw 'error' }
|
|
11
|
+
if (i.sum([1, 2]) !== 3) { throw 'error' }
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
{
|
|
15
15
|
const x = Array.from(i.map(a => a ** 2)([1, 2, 3]))
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (x.length !== 3) { throw 'error' }
|
|
17
|
+
if (x[0] !== 1) { throw 'error' }
|
|
18
|
+
if (x[1] !== 4) { throw 'error' }
|
|
19
|
+
if (x[2] !== 9) { throw 'error' }
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (i.join('/')([]) !== '') { throw 'error' }
|
|
24
|
+
if (i.join('/')(['a']) !== 'a') { throw 'error' }
|
|
25
|
+
if (i.join('/')(['a', 'b']) !== 'a/b') { throw 'error'}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
{
|
|
29
|
-
|
|
29
|
+
if (i.find(x => x === 'c')(['a', 'b', 'c']) !== 'c') { throw 'error' }
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
{
|
|
@@ -37,5 +37,5 @@ const lib = require('../lib')
|
|
|
37
37
|
(i.map(x => file(x())))
|
|
38
38
|
(i.find(x => x !== undefined))
|
|
39
39
|
([() => p, () => `${p}.js`, () => `${p}/index.js`])
|
|
40
|
-
|
|
40
|
+
if (x('index.js') !== 'x') { throw 'error' }
|
|
41
41
|
}
|
package/lib/index.js
CHANGED
|
@@ -23,18 +23,6 @@
|
|
|
23
23
|
/**
|
|
24
24
|
* @template T
|
|
25
25
|
* @typedef {[T]|Continue<T>} Continuation
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/** @type {(_: string) => never} */
|
|
29
|
-
const panic = message => { throw message }
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @template T
|
|
33
|
-
* @template R
|
|
34
|
-
* @typedef {{
|
|
35
|
-
* merge: (_: R) => (_: T) => R
|
|
36
|
-
* init: R
|
|
37
|
-
* }} Reduce
|
|
38
26
|
*/
|
|
39
27
|
|
|
40
28
|
/** @type {<I, X>(_: (_: I) => X) => <O>(_: (_: X) => O) => (_: I) => O} */
|
|
@@ -77,22 +65,7 @@ const chain = value => ({
|
|
|
77
65
|
|
|
78
66
|
module.exports = {
|
|
79
67
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
todo: () => panic('not implemented'),
|
|
83
|
-
|
|
84
|
-
/** @type {(_: string) => (_: boolean) => void} */
|
|
85
|
-
panic_if: message => condition => condition ? panic(message) : undefined,
|
|
86
|
-
|
|
87
|
-
/** @type {<T>(_: Continuation<T>) => T} */
|
|
88
|
-
trampoline: continuation => {
|
|
89
|
-
while (true) {
|
|
90
|
-
if (typeof continuation !== 'function') {
|
|
91
|
-
return continuation[0]
|
|
92
|
-
}
|
|
93
|
-
continuation = continuation()
|
|
94
|
-
}
|
|
95
|
-
},
|
|
68
|
+
todo: () => { throw 'not implemented' },
|
|
96
69
|
|
|
97
70
|
pipe,
|
|
98
71
|
|
package/map/test.js
CHANGED
|
@@ -42,14 +42,13 @@ const lib = require('../lib')
|
|
|
42
42
|
|
|
43
43
|
{
|
|
44
44
|
const m = empty.set('x')(12).set('y')(44)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (m.get('x') !== 12) { throw 'error' }
|
|
46
|
+
if (m.get('y') !== 44) { throw 'error' }
|
|
47
|
+
if (m.get('a') !== undefined) { throw 'error' }
|
|
48
48
|
const entries = Array.from(m.entries())
|
|
49
|
-
|
|
49
|
+
if (entries.length !== 2) { throw 'error' }
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
{
|
|
54
53
|
/** @type {import('.').Map<number>} */
|
|
55
54
|
let m = empty
|
package/module-manager/test.js
CHANGED
|
@@ -5,13 +5,16 @@ const lib = require('../lib')
|
|
|
5
5
|
require('./node/test')
|
|
6
6
|
|
|
7
7
|
/** @type {<T>(_: T | undefined) => T} */
|
|
8
|
-
const cast = x =>
|
|
8
|
+
const cast = x => {
|
|
9
|
+
if (x === undefined) { throw 'x' }
|
|
10
|
+
return x
|
|
11
|
+
}
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
if (i.isRelative('a/b/c'.split('/'))) { throw 'error '}
|
|
14
|
+
if (!i.isRelative('./a/b/c'.split('/'))) { throw 'error ' }
|
|
15
|
+
if (cast(i.pathNorm('a/../b'.split('/'))).join('/') !== 'b') { throw 'error ' }
|
|
16
|
+
if (cast(i.pathNorm('a/../b/../c'.split('/'))).join('/') !== 'c') { throw 'error ' }
|
|
17
|
+
if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { throw 'error ' }
|
|
15
18
|
|
|
16
19
|
{
|
|
17
20
|
/** @type {i.Package} */
|
|
@@ -35,7 +38,8 @@ lib.panic_if('pathNorm')(cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('
|
|
|
35
38
|
'index.js': 'b/c ./index.js',
|
|
36
39
|
'x/index.js': 'b/c ./x/index.js',
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
if (['.js', '', 'undefined.js'].includes(path)) { throw '.js' }
|
|
42
|
+
return f[path]
|
|
39
43
|
},
|
|
40
44
|
id: ['c']
|
|
41
45
|
}
|
|
@@ -59,7 +63,8 @@ lib.panic_if('pathNorm')(cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('
|
|
|
59
63
|
'a/index.js': './a/index.js',
|
|
60
64
|
'a/index.js.js': './a/index.js.js',
|
|
61
65
|
}
|
|
62
|
-
|
|
66
|
+
if (['.js', '', 'undefined.js'].includes(path)) { throw '.js' }
|
|
67
|
+
return f[path]
|
|
63
68
|
},
|
|
64
69
|
id: ['']
|
|
65
70
|
}
|
|
@@ -72,8 +77,8 @@ lib.panic_if('pathNorm')(cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('
|
|
|
72
77
|
}
|
|
73
78
|
{
|
|
74
79
|
const g = i.getModule({pack, local: []})
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
if (g('') !== undefined) { throw 'error' }
|
|
81
|
+
if (g('..') !== undefined) { throw 'error' }
|
|
77
82
|
expect(g('.'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
|
|
78
83
|
expect(g('./index'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
|
|
79
84
|
expect(g('./index.js'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
|
|
@@ -81,10 +86,10 @@ lib.panic_if('pathNorm')(cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('
|
|
|
81
86
|
expect(g('./a'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
|
|
82
87
|
expect(g('./a/index'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
|
|
83
88
|
expect(g('./a/index.js'))({ fileName: 'index.js.js', location: { pack, local: ['a']}, source: './a/index.js'})
|
|
84
|
-
|
|
89
|
+
if (g('./x') !== undefined) { throw 'error' }
|
|
85
90
|
expect(g('a'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
|
|
86
91
|
expect(g('a/index'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
|
|
87
|
-
|
|
92
|
+
if (g('b') !== undefined) { throw 'error' }
|
|
88
93
|
expect(g('b/c'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
|
|
89
94
|
expect(g('b/c/index'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
|
|
90
95
|
expect(g('b/c/index.js'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
|
|
@@ -93,21 +98,21 @@ lib.panic_if('pathNorm')(cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('
|
|
|
93
98
|
}
|
|
94
99
|
{
|
|
95
100
|
const g = i.getModule({pack, local: ['index']})
|
|
96
|
-
|
|
101
|
+
if (g('') !== undefined) { throw 'error' }
|
|
97
102
|
expect(g('..'))({ fileName: 'index.js', location: { pack, local: []}, source: './index.js'})
|
|
98
103
|
expect(g('.'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
|
|
99
104
|
expect(g('./index'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
|
|
100
105
|
expect(g('./index.js'))({ fileName: 'index.js', location: { pack, local: ['index']}, source: './index/index.js'})
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
if (g('./index/') !== undefined) { throw 'error' }
|
|
107
|
+
if (g('./a') !== undefined) { throw 'error' }
|
|
103
108
|
expect(g('../a'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
|
|
104
109
|
expect(g('../a/index'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
|
|
105
110
|
expect(g('../a/index.js'))({ fileName: 'index.js', location: { pack, local: ['a']}, source: './a/index.js'})
|
|
106
111
|
expect(g('../a/index.js.js'))({ fileName: 'index.js.js', location: { pack, local: ['a']}, source: './a/index.js.js'})
|
|
107
|
-
|
|
112
|
+
if (g('./x') !== undefined) { throw 'error' }
|
|
108
113
|
expect(g('a'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
|
|
109
114
|
expect(g('a/index'))({ fileName: 'index.js', location: { pack: a, local: []}, source: 'a ./index.js'})
|
|
110
|
-
|
|
115
|
+
if (g('b') !== undefined) { throw 'error' }
|
|
111
116
|
expect(g('b/c'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
|
|
112
117
|
expect(g('b/c/index'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
|
|
113
118
|
expect(g('b/c/index.js'))({ fileName: 'index.js', location: { pack: c, local: []}, source: 'b/c ./index.js'})
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -6,10 +6,10 @@ require('./module-manager/test')
|
|
|
6
6
|
require('./lib/test')
|
|
7
7
|
|
|
8
8
|
/** @type {() => never} */
|
|
9
|
-
const assert = () =>
|
|
9
|
+
const assert = () => { throw 'assert' }
|
|
10
10
|
|
|
11
11
|
/** @type {(_: boolean) => void} */
|
|
12
|
-
const assert_if = c =>
|
|
12
|
+
const assert_if = c => { if (c) { throw 'assert_if' } }
|
|
13
13
|
|
|
14
14
|
{
|
|
15
15
|
i.parseModuleUrl('')(
|