@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,11 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * @attribute
6
+ * @type {boolean}
7
+ */
8
+ a = 10;
9
+ }
10
+
11
+ export { Example };
@@ -0,0 +1,30 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * @attribute
6
+ * @type {string}
7
+ */
8
+ a;
9
+
10
+ /**
11
+ * @attribute
12
+ */
13
+ b = 'example';
14
+
15
+ /**
16
+ * @attribute
17
+ * @type {string}
18
+ * @placeholder Example text
19
+ */
20
+ c;
21
+
22
+ /**
23
+ * @attribute
24
+ * @type {string[]}
25
+ * @size 2
26
+ */
27
+ d;
28
+ }
29
+
30
+ export { Example };
@@ -0,0 +1,13 @@
1
+ import { Script, Vec3 } from 'playcanvas';
2
+
3
+ class Vec3Extended extends Vec3 {};
4
+
5
+ class Example extends Script {
6
+ /**
7
+ * @attribute
8
+ * @type {Vec3Extended}
9
+ */
10
+ d;
11
+ }
12
+
13
+ export { Example };
@@ -0,0 +1,23 @@
1
+ import { Script, Vec2, Vec3, Vec4 } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * @attribute
6
+ * @type {Vec2}
7
+ */
8
+ a;
9
+
10
+ /**
11
+ * @attribute
12
+ */
13
+ b = new Vec3(1, 2, 3);
14
+
15
+ /**
16
+ * @attribute
17
+ * @type {Vec4[]}
18
+ * @size 2
19
+ */
20
+ c;
21
+ }
22
+
23
+ export { Example };
@@ -0,0 +1,48 @@
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('INVALID: Asset attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./asset.invalid.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 with errors (3)', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors.length).to.equal(3);
23
+ });
24
+
25
+ it('a: should fallback to an asset attribute without resource', 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('asset');
29
+ expect(data[0].example.attributes.a.default).to.not.exist;
30
+ expect(data[0].example.attributes.a.resource).to.not.exist;
31
+ });
32
+
33
+ it('b: should fallback to an asset attribute without resource', 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('asset');
37
+ expect(data[0].example.attributes.b.default).to.not.exist;
38
+ expect(data[0].example.attributes.b.resource).to.not.exist;
39
+ });
40
+
41
+ it('c: should fallback to an asset attribute without resource', 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('asset');
45
+ expect(data[0].example.attributes.c.default).to.not.exist;
46
+ expect(data[0].example.attributes.c.resource).to.not.exist;
47
+ });
48
+ });
@@ -0,0 +1,24 @@
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('INVALID: Curve attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./curve.invalid.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 with errors (4)', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors.length).to.equal(4);
23
+ });
24
+ });
@@ -0,0 +1,28 @@
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('INVALID: JSON attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./json.invalid.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 with errors (1)', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.be.empty;
22
+ expect(data[0].example.errors.length).to.equal(1);
23
+ });
24
+
25
+ it('o: should not be recognised as an attribute (type not an interface)', function () {
26
+ expect(data[0].example.attributes.o).to.not.exist;
27
+ });
28
+ });
@@ -0,0 +1,42 @@
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('INVALID: Misc attribute types', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./misc.invalid.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 with attributes and errors (4)', function () {
20
+ expect(data[0].example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors.length).to.equal(3);
23
+ });
24
+
25
+ it('e: should not be recognised as an attribute (cannot infer GraphNode type)', function () {
26
+ expect(data[0].example.attributes.e).to.not.exist;
27
+ });
28
+
29
+ it('f: should not be recognised as an attribute (cannot infer custom Vec3 type)', function () {
30
+ expect(data[0].example.attributes.f).to.not.exist;
31
+ });
32
+
33
+ it('g: should fallback to a numeric attribute array without size', function () {
34
+ expect(data[0].example.attributes.g).to.exist;
35
+ expect(data[0].example.attributes.g.name).to.equal('g');
36
+ expect(data[0].example.attributes.g.type).to.equal('number');
37
+ expect(data[0].example.attributes.g.array).to.equal(true);
38
+ expect(data[0].example.attributes.g.default).to.not.exist;
39
+ expect(data[0].example.attributes.g.size).to.not.exist;
40
+ });
41
+
42
+ });
@@ -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('INVALID: Numeric attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./numeric.invalid.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 with attributes and errors (6)', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.not.be.empty;
22
+ expect(data[0].example.errors.length).to.equal(6);
23
+ });
24
+
25
+ it('a: should fallback to a numeric attribute without range', 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.min).to.not.exist;
32
+ expect(data[0].example.attributes.a.max).to.not.exist;
33
+ });
34
+
35
+ it('b: should not be recognised as an attribute (step tag dropped)', function () {
36
+ expect(data[0].example.attributes.b).to.not.exist;
37
+ });
38
+
39
+ it('c: should not be recognised as an attribute (precision tag dropped)', function () {
40
+ expect(data[0].example.attributes.c).to.not.exist;
41
+ });
42
+
43
+ it('d: should fallback to a numeric attribute without step and precision', function () {
44
+ expect(data[0].example.attributes.d).to.exist;
45
+ expect(data[0].example.attributes.d.name).to.equal('d');
46
+ expect(data[0].example.attributes.d.type).to.equal('number');
47
+ expect(data[0].example.attributes.d.array).to.equal(false);
48
+ expect(data[0].example.attributes.d.step).to.not.exist;
49
+ expect(data[0].example.attributes.d.precision).to.not.exist;
50
+ });
51
+
52
+ it('e: should not be recognised as an attribute (step tag dropped)', function () {
53
+ expect(data[0].example.attributes.e).to.exist;
54
+ expect(data[0].example.attributes.e.step).to.not.exist;
55
+ });
56
+ });
@@ -0,0 +1,18 @@
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('INVALID: Program ', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./program.invalid.js');
11
+ });
12
+
13
+ it('only errors should exist (1)', function () {
14
+ expect(data).to.exist;
15
+ expect(data[0]).to.be.empty;
16
+ expect(data[1].length).to.equal(1);
17
+ });
18
+ });
@@ -0,0 +1,29 @@
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('INVALID: Vector attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./vector.invalid.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 with errors (1)', function () {
20
+ expect(data[0]?.example).to.exist;
21
+ expect(data[0].example.attributes).to.be.empty;
22
+ expect(data[0].example.errors.length).to.equal(1);
23
+ });
24
+
25
+ it('d: should not be recognized as an attribute (extends vector and not is vector)', function () {
26
+ expect(data[0].example.attributes.d).to.not.exist;
27
+ });
28
+
29
+ });
@@ -0,0 +1,51 @@
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: Asset attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./asset.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 asset 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('asset');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.equal(null);
31
+ });
32
+
33
+ it('b: should be a asset attribute with a texture resource', 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('asset');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.equal(null);
39
+ expect(data[0].example.attributes.b.resource).to.equal('texture');
40
+ });
41
+
42
+ it('c: should be a asset attribute array with a container resource', function () {
43
+ expect(data[0].example.attributes.c).to.exist;
44
+ expect(data[0].example.attributes.c.name).to.equal('c');
45
+ expect(data[0].example.attributes.c.type).to.equal('asset');
46
+ expect(data[0].example.attributes.c.array).to.equal(true);
47
+ expect(data[0].example.attributes.c.default).to.equal(null);
48
+ expect(data[0].example.attributes.c.resource).to.equal('container');
49
+ });
50
+
51
+ });
@@ -0,0 +1,50 @@
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: Checkbox attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./checkbox.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 checkbox 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('boolean');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.equal(false);
31
+ });
32
+
33
+ it('b: should be a checkbox 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('boolean');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.equal(true);
39
+ });
40
+
41
+ it('c: should be a checkbox attribute array with a size', 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('boolean');
45
+ expect(data[0].example.attributes.c.array).to.equal(true);
46
+ expect(data[0].example.attributes.c.size).to.equal(2);
47
+ expect(data[0].example.attributes.c.default).equal(null);
48
+ });
49
+
50
+ });
@@ -0,0 +1,50 @@
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: Color attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./color.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 color 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('rgba');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.eql([1, 1, 1, 1]);
31
+ });
32
+
33
+ it('b: should be a color 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('rgba');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.eql([1, 0, 0, 1]);
39
+ });
40
+
41
+ it('c: should be a color attribute array with a size', 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('rgba');
45
+ expect(data[0].example.attributes.c.array).to.equal(true);
46
+ expect(data[0].example.attributes.c.size).to.equal(2);
47
+ expect(data[0].example.attributes.c.default).equal(null);
48
+ });
49
+
50
+ });
@@ -0,0 +1,77 @@
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: Curve attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./curve.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 curve attribute', function () {
26
+ expect(data[0].example.attributes.a).exist;
27
+ expect(data[0].example.attributes.a.name).to.equal('a');
28
+ expect(data[0].example.attributes.a.type).to.equal('curve');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.eql([]);
31
+ });
32
+
33
+ it('b: should be a curve attribute with a default value', function () {
34
+ expect(data[0].example.attributes.b).exist;
35
+ expect(data[0].example.attributes.b.name).to.equal('b');
36
+ expect(data[0].example.attributes.b.type).to.equal('curve');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.eql([0, 0, 1, 1]);
39
+ });
40
+
41
+ it('c: should be a curve attribute with a color', function () {
42
+ expect(data[0].example.attributes.c).exist;
43
+ expect(data[0].example.attributes.c.name).to.equal('c');
44
+ expect(data[0].example.attributes.c.type).to.equal('curve');
45
+ expect(data[0].example.attributes.c.array).to.equal(false);
46
+ expect(data[0].example.attributes.c.default).to.eql([]);
47
+ expect(data[0].example.attributes.c.color).to.equal('r');
48
+ });
49
+
50
+ it('d: should be a curve attribute with a color and curve', function () {
51
+ expect(data[0].example.attributes.d).exist;
52
+ expect(data[0].example.attributes.d.name).to.equal('d');
53
+ expect(data[0].example.attributes.d.type).to.equal('curve');
54
+ expect(data[0].example.attributes.d.array).to.equal(false);
55
+ expect(data[0].example.attributes.d.default).to.eql([]);
56
+ expect(data[0].example.attributes.d.color).to.equal('rgb');
57
+ expect(data[0].example.attributes.d.curves).to.deep.equal(['x', 'y', 'z']);
58
+ });
59
+
60
+ it('e: should be a curve attribute array with a size', function () {
61
+ expect(data[0].example.attributes.e).exist;
62
+ expect(data[0].example.attributes.e.name).to.equal('e');
63
+ expect(data[0].example.attributes.e.type).to.equal('curve');
64
+ expect(data[0].example.attributes.e.array).to.equal(true);
65
+ expect(data[0].example.attributes.e.size).to.equal(2);
66
+ expect(data[0].example.attributes.e.default).equal(null);
67
+ });
68
+
69
+ it('f: should be a curve attribute in an unsual format', function () {
70
+ expect(data[0].example.attributes.f).exist;
71
+ expect(data[0].example.attributes.f.name).to.equal('f');
72
+ expect(data[0].example.attributes.f.type).to.equal('curve');
73
+ expect(data[0].example.attributes.f.array).to.equal(false);
74
+ expect(data[0].example.attributes.f.color).to.equal('rgba');
75
+ expect(data[0].example.attributes.f.curves).to.deep.equal(['x', 'y', 'z']);
76
+ });
77
+ });
@@ -0,0 +1,50 @@
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: Entity attribute', function () {
8
+ let data;
9
+ before(async function () {
10
+ data = await parseAttributes('./entity.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 entity 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('entity');
29
+ expect(data[0].example.attributes.a.array).to.equal(false);
30
+ expect(data[0].example.attributes.a.default).to.equal(null);
31
+ });
32
+
33
+ it('b: should be a entity 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('entity');
37
+ expect(data[0].example.attributes.b.array).to.equal(false);
38
+ expect(data[0].example.attributes.b.default).to.equal(null);
39
+ });
40
+
41
+ it('c: should be a entity attribute array with a size', 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('entity');
45
+ expect(data[0].example.attributes.c.array).to.equal(true);
46
+ expect(data[0].example.attributes.c.size).to.equal(2);
47
+ expect(data[0].example.attributes.c.default).equal(null);
48
+ });
49
+
50
+ });