@lumjs/tests 1.6.0 → 1.7.1

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.
@@ -1,72 +0,0 @@
1
- // Common stuff for both regular and functional tests.
2
- const types = require('@lumjs/core').types;
3
-
4
- const okay = (1==1);
5
-
6
- const isTests = [1, 1.1, 'a', true, false, [1,2,3], null];
7
- const isntTests =
8
- [ // Tests to compare strict non-equality.
9
- [1, '1'],
10
- [1.1, '1.1'],
11
- [true, 1],
12
- [false, 0],
13
- [false, null],
14
- ['', null],
15
- [[1,2], [2,1]],
16
- ];
17
-
18
- const cmpTests =
19
- [ // Tests to use custom comparisons and aliases.
20
- [1, 1, '==='],
21
- [1, 1, 'is'],
22
- [0, 1, '!=='],
23
- [0, 1, 'isnt'],
24
- [1, '1', 'eq'],
25
- [0, false, 'eq'],
26
- [1, true, '=='],
27
- [1, false, 'ne'],
28
- [0, true, '!='],
29
- [1, 0, '>'],
30
- [1, 0, 'gt'],
31
- [1, 0, '>='],
32
- [1, 0, 'ge'],
33
- [1, 0, 'gte'],
34
- // TODO: finish this set of tests.
35
- ];
36
-
37
- const livesTests =
38
- [ // Tests for the lives() function.
39
- () => true,
40
- () => JSON.stringify({answer:42}),
41
- () => JSON.parse('{"hello":"world"}'),
42
- ];
43
-
44
- const isJsonTests =
45
- [
46
- [[1,2,3], [1,2,3]],
47
- [['hello','world'], ['hello','world']],
48
- [{hello: 'world'}, {hello:'world'}],
49
- ];
50
-
51
- const isntJsonTests =
52
- [
53
- [[1,2,3], [3,2,1]],
54
- [['hello','world'], ['goodbye','universe']],
55
- [{hello: 'world'}, {hello:'darkness my old friend'}],
56
- ];
57
-
58
- const plan
59
- = 2
60
- + isTests.length
61
- + isntTests.length
62
- + cmpTests.length
63
- + livesTests.length
64
- + isJsonTests.length
65
- + isntJsonTests.length
66
- ;
67
-
68
- module.exports =
69
- {
70
- isTests, isntTests, cmpTests, livesTests, isJsonTests, isntJsonTests,
71
- okay, plan, types,
72
- };
package/test/inc/dies.js DELETED
@@ -1,78 +0,0 @@
1
- // Common include for testing the .dies() method.
2
-
3
- // A custom error class.
4
- class Exception extends Error
5
- {
6
- constructor(msg)
7
- {
8
- super(msg);
9
- this.name = "Exception";
10
- }
11
- }
12
-
13
- exports.Exception = Exception;
14
-
15
- // A simplistic class for testing.
16
- class TestObject
17
- {
18
- static throwError()
19
- {
20
- throw new Error("error thrown statically");
21
- }
22
- static throwSyntaxError()
23
- {
24
- return this.noSuchMethod();
25
- }
26
-
27
- throwError()
28
- {
29
- throw new Error("error thrown");
30
- }
31
- throwSyntaxError()
32
- {
33
- return this.noSuchMethod();
34
- }
35
- }
36
-
37
- exports.TestObject = TestObject;
38
-
39
- function makeException()
40
- {
41
- throw new Exception("exception made");
42
- }
43
-
44
- exports.makeException = makeException;
45
-
46
- function syntaxError()
47
- {
48
- noSuchFunction();
49
- }
50
-
51
- exports.syntaxError = syntaxError;
52
-
53
- const testObject = new TestObject();
54
-
55
- const diesErrors =
56
- [
57
- [function() { throw new Error("001"); }, 'dies(thrown_from_inline_function)'],
58
- [() => { throw new Error("002") }, 'dies(thrown_from_arrow_function)'],
59
- [() => { throw new Exception("003")}, 'dies(threw_custom_error)'],
60
- [makeException, 'dies(thrown_from_named_function)'],
61
- [() => TestObject.throwError(), 'dies(thrown_from_static_method'],
62
- [() => testObject.throwError(), 'dies(thrown_from_instance_method'],
63
- ];
64
-
65
- exports.diesErrors = diesErrors;
66
-
67
- const diesSyntaxErrors =
68
- [
69
- [function() { wrong(); }, 'dies(synax_error_from_inline_function)'],
70
- [() => wrong(), 'dies(syntax_error_from_arrow_function)'],
71
- [syntaxError, 'dies(syntax_error_from_named_function'],
72
- [() => TestObject.throwSyntaxError(), 'dies(syntax_error_from_static_method)'],
73
- [() => testObject.throwSyntaxError(), 'dies(syntax_error_from_instance_method)'],
74
- ];
75
-
76
- exports.diesSyntaxErrors = diesSyntaxErrors;
77
-
78
- exports.plan = diesErrors.length + diesSyntaxErrors.length;
package/test/inc/isa.js DELETED
@@ -1,110 +0,0 @@
1
- // Common stuff for isa() and nota() tests.
2
- const types = require('@lumjs/core').types;
3
- // A quick reference to the type names.
4
- const TYP = types.TYPES;
5
-
6
- // I based most of these off of the tests in `@lumjs/core`.
7
- // Some almost verbatim, but others required restructuring.
8
-
9
- class TypeClass {}
10
-
11
- class SubtypeClass extends TypeClass {}
12
-
13
- const typesInstance = new TypeClass();
14
- const subtypeInstance = new SubtypeClass();
15
-
16
- class DifferentClass {}
17
-
18
- const differentInstance = new DifferentClass();
19
-
20
- function getArguments() { return arguments; }
21
-
22
- const MT = [TYP.S, TYP.N];
23
- const MC = [SubtypeClass, DifferentClass];
24
- const MM = [TYP.B, TypeClass];
25
-
26
- const MCT = ',[SubtypeClass,DifferentClass]';
27
- const MMT = ',["binary",TypeClass]';
28
-
29
- const isaTests =
30
- [
31
- // Single types.
32
- [{}, TYP.O],
33
- [function(){}, TYP.F],
34
- ['hello', TYP.S],
35
- [true, TYP.B],
36
- [false, TYP.B],
37
- [100, TYP.N],
38
- [undefined, TYP.U],
39
- [Symbol('foo'), TYP.SY],
40
- [BigInt(12345), TYP.BI, 'BigInt(12345),'+TYP.BI],
41
- [54321n, TYP.BI, '54321n,'+ TYP.BI],
42
- [getArguments(), TYP.ARGS],
43
- [[], TYP.ARRAY],
44
- [null, TYP.NULL],
45
- [new Int16Array(16), TYP.TYPEDARRAY, 'Int16Array(16),'+TYP.TYPEDARRAY],
46
- [{value: true}, TYP.DESCRIPTOR],
47
- [{get: function(){}}, TYP.DESCRIPTOR],
48
- [{}, TYP.COMPLEX],
49
- [function(){}, TYP.COMPLEX],
50
- [true, TYP.SCALAR],
51
- ['hi', TYP.SCALAR],
52
- ['woah', TYP.PROP],
53
- [Symbol('woah'), TYP.PROP],
54
- // Single class.
55
- [typesInstance, TypeClass, 'typesInstance,TypeClass'],
56
- [subtypeInstance, SubtypeClass, 'subtypeInstance,SubtypeClass'],
57
- [subtypeInstance, TypeClass, 'subtypeInstance,TypeClass'],
58
- [differentInstance, DifferentClass, 'differentInstance,DifferentClass'],
59
- // Multiples.
60
- ['hello', MT],
61
- [42, MT],
62
- [subtypeInstance, MC, 'subtypeInstance'+MCT],
63
- [differentInstance, MC, 'differentInstance'+MCT],
64
- [true, MM, 'true'+MMT],
65
- [false, MM, 'false'+MMT],
66
- [typesInstance, MM, 'typeInstance'+MMT],
67
- [subtypeInstance, MM, 'subtypeInstance'+MMT],
68
- ];
69
-
70
- const notaTests =
71
- [
72
- // Single types.
73
- ['foo', TYP.O],
74
- [null, TYP.O],
75
- [{}, TYP.F],
76
- [0, TYP.B],
77
- [1, TYP.B],
78
- ['0', TYP.N],
79
- [null, TYP.U],
80
- ['foo', TYP.SY],
81
- [12345, TYP.BI],
82
- [{}, TYP.ARGS],
83
- [{}, TYP.ARRAY],
84
- [false, TYP.NULL],
85
- [[], TYP.TYPEDARRAY],
86
- [{value: true, get: function(){}}, TYP.DESCRIPTOR],
87
- [{}, TYP.DESCRIPTOR],
88
- ['a string', TYP.COMPLEX],
89
- [{}, TYP.SCALAR],
90
- [null, TYP.PROP],
91
- // Single class.
92
- [typesInstance, SubtypeClass, 'typesInstance,SubtypeClass'],
93
- [differentInstance, TypeClass, 'differentInstance,TypeClass'],
94
- [typesInstance, DifferentClass, 'typesInstance,DifferentClass'],
95
- // Multiples.
96
- [{}, MT],
97
- [typesInstance, MC, 'typesInstance'+MCT],
98
- [null, MM, 'null'+MMT],
99
- ];
100
-
101
- const plan = isaTests.length + notaTests.length;
102
-
103
- function label (f,t)
104
- {
105
- return f+'('+((t.length === 3)
106
- ? t[2]
107
- : types.stringify(t[0])+','+types.stringify(t[1]))+')';
108
- }
109
-
110
- module.exports = {types, label, plan, isaTests, notaTests};
package/test/isa.js DELETED
@@ -1,23 +0,0 @@
1
- const Test = require('../lib').Test;
2
- const def = require('./inc/isa.js');
3
-
4
- const test = new Test();
5
- test.plan(def.plan);
6
-
7
- for (const isaTest of def.isaTests)
8
- {
9
- const label = def.label('isa',isaTest);
10
- test.isa(isaTest[0], isaTest[1], label);
11
- }
12
-
13
- for (const notaTest of def.notaTests)
14
- {
15
- const label = def.label('nota',notaTest);
16
- test.nota(notaTest[0], notaTest[1], label);
17
- }
18
-
19
- // We're done, output the log.
20
- console.log(test.tap());
21
-
22
- // Re-expect the test.
23
- module.exports = test;