@lumjs/tests 1.1.0 → 1.4.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/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "@lumjs/tests",
3
- "version": "1.1.0",
3
+ "version": "1.4.0",
4
4
  "main": "lib/index.js",
5
+ "exports":
6
+ {
7
+ ".": "./lib/index.js",
8
+ "./test": "./lib/test.js",
9
+ "./functional": "./lib/functional.js",
10
+ "./harness": "./lib/harness.js",
11
+ "./package.json": "./package.json"
12
+ },
5
13
  "license": "MIT",
6
14
  "repository":
7
15
  {
@@ -9,6 +17,12 @@
9
17
  "url": "https://github.com/supernovus/lum.tests.js.git"
10
18
  },
11
19
  "dependencies": {
12
- "@lumjs/core": "^1.0.0"
20
+ "@lumjs/core": "^1.1.0"
21
+ },
22
+ "scripts":
23
+ {
24
+ "-TODO-1": "When Harness and bin/lumtest are done, use that for 'test'",
25
+ "test": "prove -e node --ext js ./test",
26
+ "build-docs": "jsdoc -c ./jsdoc.json"
13
27
  }
14
28
  }
package/test/basics.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const Test = require('../lib').Test;
2
2
  const def = require('./inc/basics.js');
3
+ const stringify = def.types.stringify;
3
4
 
4
5
  const test = new Test();
5
6
  test.plan(def.plan);
@@ -9,22 +10,39 @@ test.pass('pass()');
9
10
 
10
11
  for (const is of def.isTests)
11
12
  {
12
- const t = JSON.stringify(is);
13
+ const t = stringify(is);
13
14
  test.is(is, is, 'is('+t+','+t+')');
14
15
  }
15
16
 
16
17
  for (const [a,b] of def.isntTests)
17
18
  {
18
- const msg = `isnt(${JSON.stringify(a)},${JSON.stringify(b)})`;
19
+ const msg = `isnt(${stringify(a)},${stringify(b)})`;
19
20
  test.isnt(a, b, msg);
20
21
  }
21
22
 
22
23
  for (const args of def.cmpTests)
23
24
  {
24
- const msg = 'cmp('+JSON.stringify(args)+')';
25
+ const msg = 'cmp('+stringify(args)+')';
25
26
  test.cmp(...args, msg);
26
27
  }
27
28
 
29
+ for (const func of def.livesTests)
30
+ {
31
+ test.lives(func, `lives(${stringify(func)})`);
32
+ }
33
+
34
+ for (const [a,b] of def.isJsonTests)
35
+ {
36
+ const msg = `isJSON(${stringify(a)},${stringify(b)})`;
37
+ test.isJSON(a, b, msg);
38
+ }
39
+
40
+ for (const [a,b] of def.isntJsonTests)
41
+ {
42
+ const msg = `isntJSON(${stringify(a)},${stringify(b)})`;
43
+ test.isntJSON(a, b, msg);
44
+ }
45
+
28
46
  // We're done, output the log.
29
47
  console.log(test.tap());
30
48
 
@@ -1,7 +1,11 @@
1
1
  // Testing the basic functions of the functional testing API.
2
2
 
3
- const {test,plan,ok,pass,is,isnt,cmp,tap} = require('../lib').functional();
3
+ const
4
+ {
5
+ test,plan,ok,pass,is,isnt,cmp,tap,isJSON,isntJSON,lives,
6
+ } = require('../lib').functional();
4
7
  const def = require('./inc/basics.js');
8
+ const stringify = def.types.stringify;
5
9
 
6
10
  plan(def.plan);
7
11
 
@@ -10,22 +14,39 @@ pass('pass()');
10
14
 
11
15
  for (const it of def.isTests)
12
16
  {
13
- const t = JSON.stringify(it);
17
+ const t = stringify(it);
14
18
  is(it, it, 'is('+t+','+t+')');
15
19
  }
16
20
 
17
21
  for (const [a,b] of def.isntTests)
18
22
  {
19
- const msg = `isnt(${JSON.stringify(a)},${JSON.stringify(b)})`;
23
+ const msg = `isnt(${stringify(a)},${stringify(b)})`;
20
24
  isnt(a, b, msg);
21
25
  }
22
26
 
23
27
  for (const args of def.cmpTests)
24
28
  {
25
- const msg = 'cmp('+JSON.stringify(args)+')';
29
+ const msg = 'cmp('+stringify(args)+')';
26
30
  cmp(...args, msg);
27
31
  }
28
32
 
33
+ for (const func of def.livesTests)
34
+ {
35
+ lives(func, `lives(${stringify(func)})`);
36
+ }
37
+
38
+ for (const [a,b] of def.isJsonTests)
39
+ {
40
+ const msg = `isJSON(${stringify(a)},${stringify(b)})`;
41
+ isJSON(a, b, msg);
42
+ }
43
+
44
+ for (const [a,b] of def.isntJsonTests)
45
+ {
46
+ const msg = `isntJSON(${stringify(a)},${stringify(b)})`;
47
+ isntJSON(a, b, msg);
48
+ }
49
+
29
50
  // We're done, output the log.
30
51
  console.log(tap());
31
52
 
@@ -0,0 +1,23 @@
1
+ const {test,plan,tap,isa,nota} = require('../lib').functional();
2
+ const def = require('./inc/isa.js');
3
+ const getLabel = def.label;
4
+
5
+ plan(def.plan);
6
+
7
+ for (const isaTest of def.isaTests)
8
+ {
9
+ const label = getLabel('isa',isaTest);
10
+ isa(isaTest[0], isaTest[1], label);
11
+ }
12
+
13
+ for (const notaTest of def.notaTests)
14
+ {
15
+ const label = getLabel('nota',notaTest);
16
+ nota(notaTest[0], notaTest[1], label);
17
+ }
18
+
19
+ // We're done, output the log.
20
+ console.log(tap());
21
+
22
+ // And re-export the test.
23
+ module.exports = test;
@@ -1,4 +1,5 @@
1
1
  // Common stuff for both regular and functional tests.
2
+ const types = require('@lumjs/core').types;
2
3
 
3
4
  const okay = (1==1);
4
5
 
@@ -33,10 +34,39 @@ const cmpTests =
33
34
  // TODO: finish this set of tests.
34
35
  ];
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
+
36
58
  const plan
37
59
  = 2
38
60
  + isTests.length
39
61
  + isntTests.length
40
- + cmpTests.length;
62
+ + cmpTests.length
63
+ + livesTests.length
64
+ + isJsonTests.length
65
+ + isntJsonTests.length
66
+ ;
41
67
 
42
- module.exports = {okay, isTests, isntTests, cmpTests, plan};
68
+ module.exports =
69
+ {
70
+ isTests, isntTests, cmpTests, livesTests, isJsonTests, isntJsonTests,
71
+ okay, plan, types,
72
+ };
@@ -0,0 +1,110 @@
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 ADDED
@@ -0,0 +1,23 @@
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;