@playcanvas/attribute-parser 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.
Files changed (56) hide show
  1. package/.github/workflows/ci.yml +28 -0
  2. package/README.md +76 -0
  3. package/package.json +24 -0
  4. package/src/index.js +226 -0
  5. package/src/parsers/attribute-parser.js +280 -0
  6. package/src/parsers/parsing-error.js +14 -0
  7. package/src/parsers/script-parser.js +404 -0
  8. package/src/utils/attribute-utils.js +72 -0
  9. package/src/utils/generic-utils.js +18 -0
  10. package/src/utils/tag-utils.js +65 -0
  11. package/src/utils/ts-utils.js +501 -0
  12. package/test/fixtures/asset.invalid.js +26 -0
  13. package/test/fixtures/asset.valid.js +25 -0
  14. package/test/fixtures/checkbox.valid.js +23 -0
  15. package/test/fixtures/color.valid.js +23 -0
  16. package/test/fixtures/curve.invalid.js +28 -0
  17. package/test/fixtures/curve.valid.js +49 -0
  18. package/test/fixtures/entity.valid.js +23 -0
  19. package/test/fixtures/enum.valid.js +78 -0
  20. package/test/fixtures/export.import.js +3 -0
  21. package/test/fixtures/export.valid.js +23 -0
  22. package/test/fixtures/inherit.valid.js +52 -0
  23. package/test/fixtures/intellisense.valid.js +37 -0
  24. package/test/fixtures/json.invalid.js +22 -0
  25. package/test/fixtures/json.valid.js +103 -0
  26. package/test/fixtures/misc.invalid.js +25 -0
  27. package/test/fixtures/misc.valid.js +33 -0
  28. package/test/fixtures/numeric.invalid.js +38 -0
  29. package/test/fixtures/numeric.valid.js +63 -0
  30. package/test/fixtures/playcanvas.d.ts +47963 -0
  31. package/test/fixtures/program.invalid.js +11 -0
  32. package/test/fixtures/text.valid.js +30 -0
  33. package/test/fixtures/vector.invalid.js +13 -0
  34. package/test/fixtures/vector.valid.js +23 -0
  35. package/test/tests/invalid/asset.test.js +48 -0
  36. package/test/tests/invalid/curve.test.js +24 -0
  37. package/test/tests/invalid/json.test.js +28 -0
  38. package/test/tests/invalid/misc.test.js +42 -0
  39. package/test/tests/invalid/numeric.test.js +56 -0
  40. package/test/tests/invalid/program.test.js +18 -0
  41. package/test/tests/invalid/vector.test.js +29 -0
  42. package/test/tests/valid/asset.test.js +51 -0
  43. package/test/tests/valid/checkbox.test.js +50 -0
  44. package/test/tests/valid/color.test.js +50 -0
  45. package/test/tests/valid/curve.test.js +77 -0
  46. package/test/tests/valid/entity.test.js +50 -0
  47. package/test/tests/valid/enum.test.js +74 -0
  48. package/test/tests/valid/export.test.js +56 -0
  49. package/test/tests/valid/inherit.test.js +103 -0
  50. package/test/tests/valid/intellisense.test.js +36 -0
  51. package/test/tests/valid/json.test.js +150 -0
  52. package/test/tests/valid/misc.test.js +47 -0
  53. package/test/tests/valid/numeric.test.js +104 -0
  54. package/test/tests/valid/text.test.js +59 -0
  55. package/test/tests/valid/vector.test.js +54 -0
  56. package/test/utils.js +53 -0
@@ -0,0 +1,74 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Enum attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./enum.valid.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('e: should be a enum attribute', function () {
26
+ expect(data[0].example.attributes.e).to.exist;
27
+ expect(data[0].example.attributes.e.name).to.equal('e');
28
+ expect(data[0].example.attributes.e.type).to.equal('number');
29
+ expect(data[0].example.attributes.e.array).to.equal(false);
30
+ expect(data[0].example.attributes.e.default).to.equal(0);
31
+ });
32
+
33
+ it('f: should be a enum attribute with a default value', function () {
34
+ expect(data[0].example.attributes.f).to.exist;
35
+ expect(data[0].example.attributes.f.name).to.equal('f');
36
+ expect(data[0].example.attributes.f.type).to.equal('number');
37
+ expect(data[0].example.attributes.f.array).to.equal(false);
38
+ expect(data[0].example.attributes.f.default).to.equal(1);
39
+ });
40
+
41
+ it('g: should be a enum attribute array with a size', function () {
42
+ expect(data[0].example.attributes.g).to.exist;
43
+ expect(data[0].example.attributes.g.name).to.equal('g');
44
+ expect(data[0].example.attributes.g.type).to.equal('number');
45
+ expect(data[0].example.attributes.g.array).to.equal(true);
46
+ expect(data[0].example.attributes.g.size).to.equal(2);
47
+ expect(data[0].example.attributes.g.default).equal(null);
48
+ });
49
+
50
+ it('h: should be a enum attribute', function () {
51
+ expect(data[0].example.attributes.h).to.exist;
52
+ expect(data[0].example.attributes.h.name).to.equal('h');
53
+ expect(data[0].example.attributes.h.type).to.equal('string');
54
+ expect(data[0].example.attributes.h.array).to.equal(false);
55
+ expect(data[0].example.attributes.h.default).to.equal('');
56
+ });
57
+
58
+ it('i: should be a enum attribute with a default value', function () {
59
+ expect(data[0].example.attributes.i).to.exist;
60
+ expect(data[0].example.attributes.i.name).to.equal('i');
61
+ expect(data[0].example.attributes.i.type).to.equal('vec3');
62
+ expect(data[0].example.attributes.i.array).to.equal(false);
63
+ expect(data[0].example.attributes.i.default).to.eql([0, 0, 0]);
64
+ });
65
+
66
+ it('j: should be a enum attribute array with a size', function () {
67
+ expect(data[0].example.attributes.j).to.exist;
68
+ expect(data[0].example.attributes.j.name).to.equal('j');
69
+ expect(data[0].example.attributes.j.type).to.equal('number');
70
+ expect(data[0].example.attributes.j.array).to.equal(false);
71
+ expect(data[0].example.attributes.j.default).equal(2);
72
+ });
73
+
74
+ });
@@ -0,0 +1,56 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Export Script', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./export.valid.js', './export.import.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without attributes or errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('ExampleExport: should exist without attributes or errors', function () {
26
+ expect(data[0]?.exampleExport).to.exist;
27
+ expect(data[0].exampleExport.attributes).to.be.empty;
28
+ expect(data[0].exampleExport.errors).to.be.empty;
29
+ });
30
+
31
+ it('ExampleDefault: should exist without attributes or errors', function () {
32
+ expect(data[0]?.exampleDefault).to.exist;
33
+ expect(data[0].exampleDefault.attributes).to.be.empty;
34
+ expect(data[0].exampleDefault.errors).to.be.empty;
35
+ });
36
+
37
+ it('ExampleExportAs: should not exist', function () {
38
+ expect(data[0]?.exampleExportAs).to.not.exist;
39
+ });
40
+
41
+ it('ExampleImport: should exist without attributes or errors', function () {
42
+ expect(data[0]?.exampleImport).to.exist;
43
+ expect(data[0].exampleImport.attributes).to.be.empty;
44
+ expect(data[0].exampleImport.errors).to.be.empty;
45
+ });
46
+
47
+ it('ExampleImportExtend: should exist without attributes or errors', function () {
48
+ expect(data[0]?.exampleImportExtend).to.exist;
49
+ expect(data[0].exampleImportExtend.attributes).to.be.empty;
50
+ expect(data[0].exampleImportExtend.errors).to.be.empty;
51
+ });
52
+
53
+ it('ExampleNotExported: should not exist (not exported)', function () {
54
+ expect(data[0]?.exampleNotExported).to.not.exist;
55
+ });
56
+ });
@@ -0,0 +1,103 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Script inheritance attributes', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./inherit.valid.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('ExampleExtended: should exist without errors', function () {
26
+ expect(data[0]?.exampleExtended).to.exist;
27
+ expect(data[0].exampleExtended.attributes).to.not.be.empty;
28
+ expect(data[0].exampleExtended.errors).to.be.empty;
29
+ });
30
+
31
+ it('ExampleExtendedExtended: should exist without errors', function () {
32
+ expect(data[0]?.exampleExtendedExtended).to.exist;
33
+ expect(data[0].exampleExtendedExtended.attributes).to.not.be.empty;
34
+ expect(data[0].exampleExtendedExtended.errors).to.be.empty;
35
+ });
36
+
37
+ it('ExampleAlias: should exist without errors', function () {
38
+ expect(data[0]?.exampleAlias).to.exist;
39
+ expect(data[0].exampleAlias.attributes).to.not.be.empty;
40
+ expect(data[0].exampleAlias.errors).to.be.empty;
41
+ });
42
+
43
+ it('Example#a: should be a checkbox attribute', function () {
44
+ expect(data[0].example.attributes.a).to.exist;
45
+ expect(data[0].example.attributes.a.name).to.equal('a');
46
+ expect(data[0].example.attributes.a.type).to.equal('boolean');
47
+ expect(data[0].example.attributes.a.array).to.equal(false);
48
+ expect(data[0].example.attributes.a.default).to.equal(false);
49
+ });
50
+
51
+ it('ExampleExtended#a: should be a checkbox attribute', function () {
52
+ expect(data[0].exampleExtended.attributes.a).to.exist;
53
+ expect(data[0].exampleExtended.attributes.a.name).to.equal('a');
54
+ expect(data[0].exampleExtended.attributes.a.type).to.equal('boolean');
55
+ expect(data[0].exampleExtended.attributes.a.array).to.equal(false);
56
+ expect(data[0].exampleExtended.attributes.a.default).to.equal(false);
57
+ });
58
+
59
+ it('ExampleExtended#b: should be a numeric attribute', function () {
60
+ expect(data[0].exampleExtended.attributes.b).to.exist;
61
+ expect(data[0].exampleExtended.attributes.b.name).to.equal('b');
62
+ expect(data[0].exampleExtended.attributes.b.type).to.equal('number');
63
+ expect(data[0].exampleExtended.attributes.b.array).to.equal(false);
64
+ expect(data[0].exampleExtended.attributes.b.default).to.equal(0);
65
+ });
66
+
67
+ it('ExampleExtendedExtended#a: should be a checkbox attribute', function () {
68
+ expect(data[0].exampleExtendedExtended.attributes.a).to.exist;
69
+ expect(data[0].exampleExtendedExtended.attributes.a.name).to.equal('a');
70
+ expect(data[0].exampleExtendedExtended.attributes.a.type).to.equal('boolean');
71
+ expect(data[0].exampleExtendedExtended.attributes.a.array).to.equal(false);
72
+ expect(data[0].exampleExtendedExtended.attributes.a.default).to.equal(false);
73
+ });
74
+
75
+ it('ExampleExtendedExtended#b: should be a numeric attribute', function () {
76
+ expect(data[0].exampleExtendedExtended.attributes.b).to.exist;
77
+ expect(data[0].exampleExtendedExtended.attributes.b.name).to.equal('b');
78
+ expect(data[0].exampleExtendedExtended.attributes.b.type).to.equal('number');
79
+ expect(data[0].exampleExtendedExtended.attributes.b.array).to.equal(false);
80
+ expect(data[0].exampleExtendedExtended.attributes.b.default).to.equal(0);
81
+ });
82
+
83
+ it('ExampleExtendedExtended#c: should be a string attribute', function () {
84
+ expect(data[0].exampleExtendedExtended.attributes.c).to.exist;
85
+ expect(data[0].exampleExtendedExtended.attributes.c.name).to.equal('c');
86
+ expect(data[0].exampleExtendedExtended.attributes.c.type).to.equal('string');
87
+ expect(data[0].exampleExtendedExtended.attributes.c.array).to.equal(false);
88
+ expect(data[0].exampleExtendedExtended.attributes.c.default).to.equal('');
89
+ });
90
+
91
+ it('ExampleAlias#a: should be a checkbox attribute', function () {
92
+ expect(data[0].exampleAlias.attributes.a).to.exist;
93
+ expect(data[0].exampleAlias.attributes.a.name).to.equal('a');
94
+ expect(data[0].exampleAlias.attributes.a.type).to.equal('boolean');
95
+ expect(data[0].exampleAlias.attributes.a.array).to.equal(false);
96
+ expect(data[0].exampleAlias.attributes.a.default).to.equal(false);
97
+ });
98
+
99
+ it('ExampleNoExtend: should not exist (does not extend Script)', function () {
100
+ expect(data[0].exampleNoExtend).to.not.exist;
101
+ });
102
+
103
+ });
@@ -0,0 +1,36 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { getAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Intellisense Parsing', function () {
8
+
9
+ let data;
10
+ before(async function () {
11
+ data = await getAttributes('./intellisense.valid.js');
12
+ });
13
+
14
+ it('only results should exist', function () {
15
+ expect(data).to.exist;
16
+ expect(data[0]).to.not.be.empty;
17
+ expect(data[1]).to.be.empty;
18
+ });
19
+
20
+ it('Example: should exist', function () {
21
+ expect(data[0]?.example).to.exist;
22
+ });
23
+
24
+ it('attributes have correct types', function () {
25
+ expect(data[0].folder[0].type).to.equal('any');
26
+ expect(data[0].folder[1].type).to.equal('number');
27
+
28
+ expect(data[0].example[0].type).to.equal('any');
29
+ expect(data[0].example[1].type).to.equal('number');
30
+ expect(data[0].example[2].type).to.equal('boolean');
31
+ expect(data[0].example[3].type).to.equal('string');
32
+ expect(data[0].example[4].type).to.equal('{}');
33
+ expect(data[0].example[5].type).to.equal('Vec3');
34
+ expect(data[0].example[6].type).to.equal('Folder');
35
+ });
36
+ });
@@ -0,0 +1,150 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: JSON attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./json.valid.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('f: should be a json attribute', function () {
26
+ expect(data[0].example.attributes.f).to.exist;
27
+ expect(data[0].example.attributes.f.name).to.equal('f');
28
+ expect(data[0].example.attributes.f.type).to.equal('json');
29
+ expect(data[0].example.attributes.f.array).to.equal(false);
30
+ expect(data[0].example.attributes.f.default).to.equal(null);
31
+
32
+ expect(data[0].example.attributes.f.schema).to.exist;
33
+ });
34
+
35
+ it('f[a]: should be a boolean attribute', function () {
36
+ expect(data[0].example.attributes.f.schema[0].name).to.equal('a');
37
+ expect(data[0].example.attributes.f.schema[0].type).to.equal('boolean');
38
+ expect(data[0].example.attributes.f.schema[0].array).to.equal(false);
39
+ expect(data[0].example.attributes.f.schema[0].default).to.equal(false);
40
+ });
41
+
42
+ it('f[b]: should be a numeric attribute', function () {
43
+ expect(data[0].example.attributes.f.schema[1].name).to.equal('b');
44
+ expect(data[0].example.attributes.f.schema[1].type).to.equal('number');
45
+ expect(data[0].example.attributes.f.schema[1].array).to.equal(false);
46
+ expect(data[0].example.attributes.f.schema[1].default).to.equal(10);
47
+ });
48
+
49
+ it('f[c]: should be a string attribute', function () {
50
+ expect(data[0].example.attributes.f.schema[2].name).to.equal('c');
51
+ expect(data[0].example.attributes.f.schema[2].type).to.equal('string');
52
+ expect(data[0].example.attributes.f.schema[2].array).to.equal(false);
53
+ expect(data[0].example.attributes.f.schema[2].default).to.equal('hello');
54
+ });
55
+
56
+ it('f[d]: should be a vec3 attribute array', function () {
57
+ expect(data[0].example.attributes.f.schema[3].name).to.equal('d');
58
+ expect(data[0].example.attributes.f.schema[3].type).to.equal('vec3');
59
+ expect(data[0].example.attributes.f.schema[3].array).to.equal(true);
60
+ expect(data[0].example.attributes.f.schema[3].default).to.eql(null);
61
+ });
62
+
63
+ it('g: should be a json attribute array with a size', function () {
64
+ expect(data[0].example.attributes.g).to.exist;
65
+ expect(data[0].example.attributes.g.name).to.equal('g');
66
+ expect(data[0].example.attributes.g.type).to.equal('json');
67
+ expect(data[0].example.attributes.g.array).to.equal(true);
68
+ expect(data[0].example.attributes.g.size).to.equal(2);
69
+ expect(data[0].example.attributes.g.default).to.eql(null);
70
+
71
+ expect(data[0].example.attributes.g.schema).to.exist;
72
+ });
73
+
74
+ it('h: should be a nested json attribute (parent)', function () {
75
+ expect(data[0].example.attributes.h).to.exist;
76
+ expect(data[0].example.attributes.h.name).to.equal('h');
77
+ expect(data[0].example.attributes.h.type).to.equal('json');
78
+ expect(data[0].example.attributes.h.array).to.equal(false);
79
+ expect(data[0].example.attributes.h.default).to.eql(null);
80
+
81
+ expect(data[0].example.attributes.h.schema).to.exist;
82
+ });
83
+
84
+ it('h[x]: should be a nested json attribute (child)', function () {
85
+ expect(data[0].example.attributes.h.schema[0].name).to.equal('x');
86
+ expect(data[0].example.attributes.h.schema[0].type).to.equal('json');
87
+ expect(data[0].example.attributes.h.schema[0].array).to.equal(false);
88
+ expect(data[0].example.attributes.h.schema[0].default).to.eql(null);
89
+
90
+ expect(data[0].example.attributes.h.schema[0].schema).to.exist;
91
+ });
92
+
93
+ it('i: should be an inline default json attribute', function () {
94
+ expect(data[0].example.attributes.i).to.exist;
95
+ expect(data[0].example.attributes.i.name).to.equal('i');
96
+ expect(data[0].example.attributes.i.type).to.equal('json');
97
+ expect(data[0].example.attributes.i.array).to.equal(false);
98
+ expect(data[0].example.attributes.i.default).to.eql(null);
99
+
100
+ expect(data[0].example.attributes.i.schema).to.exist;
101
+ });
102
+
103
+ it('j: should be a typedef json attribute', function () {
104
+ expect(data[0].example.attributes.j).to.exist;
105
+ expect(data[0].example.attributes.j.name).to.equal('j');
106
+ expect(data[0].example.attributes.j.type).to.equal('json');
107
+ expect(data[0].example.attributes.j.array).to.equal(false);
108
+ expect(data[0].example.attributes.j.default).to.eql(null);
109
+
110
+ expect(data[0].example.attributes.j.schema).to.exist;
111
+ });
112
+
113
+ it('k: should be an inline typedef json attribute', function () {
114
+ expect(data[0].example.attributes.k).to.exist;
115
+ expect(data[0].example.attributes.k.name).to.equal('k');
116
+ expect(data[0].example.attributes.k.type).to.equal('json');
117
+ expect(data[0].example.attributes.k.array).to.equal(false);
118
+ expect(data[0].example.attributes.k.default).to.eql(null);
119
+
120
+ expect(data[0].example.attributes.k.schema).to.exist;
121
+ });
122
+
123
+ it('l: should be an inline type json attribute', function () {
124
+ expect(data[0].example.attributes.l).to.exist;
125
+ expect(data[0].example.attributes.l.name).to.equal('l');
126
+ expect(data[0].example.attributes.l.type).to.equal('json');
127
+ expect(data[0].example.attributes.l.array).to.equal(false);
128
+ expect(data[0].example.attributes.l.default).to.eql(null);
129
+
130
+ expect(data[0].example.attributes.l.schema).to.exist;
131
+ });
132
+
133
+ it('m: should be a self reference json attribute', function () {
134
+ expect(data[0].example.attributes.m).to.exist;
135
+ expect(data[0].example.attributes.m.name).to.equal('m');
136
+ expect(data[0].example.attributes.m.type).to.equal('json');
137
+ expect(data[0].example.attributes.m.array).to.equal(false);
138
+ expect(data[0].example.attributes.m.default).to.eql(null);
139
+
140
+ expect(data[0].example.attributes.m.schema).to.exist;
141
+ });
142
+
143
+ it('n: should not be recognised as an attribute (no attribute tag)', function () {
144
+ expect(data[0].example.attributes.n).to.not.exist;
145
+ });
146
+
147
+ it('o: should not be recognised as an attribute (type not an interface)', function () {
148
+ expect(data[0].example.attributes.o).to.not.exist;
149
+ });
150
+ });
@@ -0,0 +1,47 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Misc attribute types', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./misc.valid.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('a: should be a numeric attribute with a title and description', function () {
26
+ expect(data[0].example.attributes.a).to.exist;
27
+ expect(data[0].example.attributes.a.name).to.equal('a');
28
+ expect(data[0].example.attributes.a.type).to.equal('number');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.equal(0);
31
+ expect(data[0].example.attributes.a.title).to.equal('A number');
32
+ expect(data[0].example.attributes.a.description).to.equal('This is a description of the attribute');
33
+ });
34
+
35
+ it('b: should be a numeric attribute with a getter and setter', function () {
36
+ expect(data[0].example.attributes.b).to.exist;
37
+ expect(data[0].example.attributes.b.name).to.equal('b');
38
+ expect(data[0].example.attributes.b.type).to.equal('number');
39
+ expect(data[0].example.attributes.b.array).to.equal(false);
40
+ expect(data[0].example.attributes.b.default).to.equal(0);
41
+ });
42
+
43
+ it('c: should not be recognised as an attribute (no attribute tag)', function () {
44
+ expect(data[0].example.attributes.c).to.not.exist;
45
+ });
46
+
47
+ });
@@ -0,0 +1,104 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Numeric attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./numeric.valid.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('a: should be a numeric attribute', function () {
26
+ expect(data[0].example.attributes.a).to.exist;
27
+ expect(data[0].example.attributes.a.name).to.equal('a');
28
+ expect(data[0].example.attributes.a.type).to.equal('number');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.equal(0);
31
+ });
32
+
33
+ it('b: should be a numeric attribute with a default value', function () {
34
+ expect(data[0].example.attributes.b).to.exist;
35
+ expect(data[0].example.attributes.b.name).to.equal('b');
36
+ expect(data[0].example.attributes.b.type).to.equal('number');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.equal(1);
39
+ });
40
+
41
+ it('c: should be a numeric attribute with a precision and step', function () {
42
+ expect(data[0].example.attributes.c).to.exist;
43
+ expect(data[0].example.attributes.c.name).to.equal('c');
44
+ expect(data[0].example.attributes.c.type).to.equal('number');
45
+ expect(data[0].example.attributes.c.array).to.equal(false);
46
+ expect(data[0].example.attributes.c.default).to.equal(0);
47
+ expect(data[0].example.attributes.c.precision).to.equal(2);
48
+ expect(data[0].example.attributes.c.step).to.equal(0.01);
49
+ });
50
+
51
+ it('d: should be a numeric attribute with a range, precision and step', function () {
52
+ expect(data[0].example.attributes.d).to.exist;
53
+ expect(data[0].example.attributes.d.name).to.equal('d');
54
+ expect(data[0].example.attributes.d.type).to.equal('number');
55
+ expect(data[0].example.attributes.d.array).to.equal(false);
56
+ expect(data[0].example.attributes.d.default).to.equal(0);
57
+ expect(data[0].example.attributes.d.min).to.equal(0);
58
+ expect(data[0].example.attributes.d.max).to.equal(1);
59
+ expect(data[0].example.attributes.d.precision).to.equal(2);
60
+ expect(data[0].example.attributes.d.step).to.equal(0.01);
61
+ });
62
+
63
+ it('e: should be a numeric attribute array with a size', function () {
64
+ expect(data[0].example.attributes.e).to.exist;
65
+ expect(data[0].example.attributes.e.name).to.equal('e');
66
+ expect(data[0].example.attributes.e.type).to.equal('number');
67
+ expect(data[0].example.attributes.e.array).to.equal(true);
68
+ expect(data[0].example.attributes.e.size).to.equal(2);
69
+ expect(data[0].example.attributes.e.default).equal(null);
70
+ });
71
+
72
+ it('f: should be a numeric attribute in an unusual format', function () {
73
+ expect(data[0].example.attributes.f).to.exist;
74
+ expect(data[0].example.attributes.f.name).to.equal('f');
75
+ expect(data[0].example.attributes.f.type).to.equal('number');
76
+ expect(data[0].example.attributes.f.array).to.equal(false);
77
+ expect(data[0].example.attributes.f.default).to.equal(0);
78
+ expect(data[0].example.attributes.f.min).to.equal(-255);
79
+ expect(data[0].example.attributes.f.max).to.equal(0);
80
+ expect(data[0].example.attributes.f.precision).to.equal(2);
81
+ expect(data[0].example.attributes.f.step).to.equal(0.01);
82
+ });
83
+
84
+ it('g: should be a numeric attribute with single value in range', function () {
85
+ expect(data[0].example.attributes.g).to.exist;
86
+ expect(data[0].example.attributes.g.name).to.equal('g');
87
+ expect(data[0].example.attributes.g.type).to.equal('number');
88
+ expect(data[0].example.attributes.g.array).to.equal(false);
89
+ expect(data[0].example.attributes.g.default).to.equal(0);
90
+ expect(data[0].example.attributes.g.min).to.equal(1);
91
+ expect(data[0].example.attributes.g.max).to.not.exist;
92
+ });
93
+
94
+ it('h: should be a numeric attribute with empty range', function () {
95
+ expect(data[0].example.attributes.h).to.exist;
96
+ expect(data[0].example.attributes.h.name).to.equal('h');
97
+ expect(data[0].example.attributes.h.type).to.equal('number');
98
+ expect(data[0].example.attributes.h.array).to.equal(false);
99
+ expect(data[0].example.attributes.h.default).to.equal(0);
100
+ expect(data[0].example.attributes.h.min).to.not.exist;
101
+ expect(data[0].example.attributes.h.max).to.not.exist;
102
+ });
103
+
104
+ });
@@ -0,0 +1,59 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import { describe, it, before } from 'mocha';
3
+ import { expect } from 'chai';
4
+
5
+ import { parseAttributes } from '../../utils.js';
6
+
7
+ describe('VALID: Text attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./text.valid.js');
11
+ });
12
+
13
+ it('only results should exist', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.not.be.empty;
16
+ expect(data[1]).to.be.empty;
17
+ });
18
+
19
+ it('Example: should exist without errors', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors).to.be.empty;
23
+ });
24
+
25
+ it('a: should be a string attribute', function () {
26
+ expect(data[0].example.attributes.a).to.exist;
27
+ expect(data[0].example.attributes.a.name).to.equal('a');
28
+ expect(data[0].example.attributes.a.type).to.equal('string');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.equal('');
31
+ });
32
+
33
+ it('b: should be a string attribute with a default value', function () {
34
+ expect(data[0].example.attributes.b).to.exist;
35
+ expect(data[0].example.attributes.b.name).to.equal('b');
36
+ expect(data[0].example.attributes.b.type).to.equal('string');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.equal('example');
39
+ });
40
+
41
+ it('c: should be a string attribute with a placeholder', function () {
42
+ expect(data[0].example.attributes.c).to.exist;
43
+ expect(data[0].example.attributes.c.name).to.equal('c');
44
+ expect(data[0].example.attributes.c.type).to.equal('string');
45
+ expect(data[0].example.attributes.c.array).to.equal(false);
46
+ expect(data[0].example.attributes.c.default).to.equal('');
47
+ expect(data[0].example.attributes.c.placeholder).to.equal('Example text');
48
+ });
49
+
50
+ it('d: should be a string attribute array with a size', function () {
51
+ expect(data[0].example.attributes.d).to.exist;
52
+ expect(data[0].example.attributes.d.name).to.equal('d');
53
+ expect(data[0].example.attributes.d.type).to.equal('string');
54
+ expect(data[0].example.attributes.d.array).to.equal(true);
55
+ expect(data[0].example.attributes.d.size).to.equal(2);
56
+ expect(data[0].example.attributes.d.default).equal(null);
57
+ });
58
+
59
+ });