Skip to content

Commit

Permalink
Fix default value for curve attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
marklundin committed Jul 24, 2024
1 parent 7292596 commit 1a9e75e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/parsers/script-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ const mapAttributesToOutput = (attribute) => {
// set the default value
if (attribute.value !== undefined) attribute.default = attribute.value;

// Curve Attributes specifically should not expose a default value if it's an empty array
if (attribute.type === 'curve' && Array.isArray(attribute.value) && attribute.value.length === 0) {
delete attribute.default;
}

// remove typeName from the output
delete attribute.typeName;
delete attribute.value;
Expand Down
8 changes: 4 additions & 4 deletions test/tests/valid/curve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('VALID: Curve attribute', function () {
expect(data[0].example.attributes.a.name).to.equal('a');
expect(data[0].example.attributes.a.type).to.equal('curve');
expect(data[0].example.attributes.a.array).to.equal(false);
expect(data[0].example.attributes.a.default).to.eql([]);
expect(data[0].example.attributes.a.default).to.not.exist;
});

it('b: should be a curve attribute with a default value', function () {
Expand All @@ -43,7 +43,7 @@ describe('VALID: Curve attribute', function () {
expect(data[0].example.attributes.c.name).to.equal('c');
expect(data[0].example.attributes.c.type).to.equal('curve');
expect(data[0].example.attributes.c.array).to.equal(false);
expect(data[0].example.attributes.c.default).to.eql([]);
expect(data[0].example.attributes.a.default).to.not.exist;
expect(data[0].example.attributes.c.color).to.equal('r');
});

Expand All @@ -52,7 +52,7 @@ describe('VALID: Curve attribute', function () {
expect(data[0].example.attributes.d.name).to.equal('d');
expect(data[0].example.attributes.d.type).to.equal('curve');
expect(data[0].example.attributes.d.array).to.equal(false);
expect(data[0].example.attributes.d.default).to.eql([]);
expect(data[0].example.attributes.a.default).to.not.exist;
expect(data[0].example.attributes.d.color).to.equal('rgb');
expect(data[0].example.attributes.d.curves).to.deep.equal(['x', 'y', 'z']);
});
Expand All @@ -63,7 +63,7 @@ describe('VALID: Curve attribute', function () {
expect(data[0].example.attributes.e.type).to.equal('curve');
expect(data[0].example.attributes.e.array).to.equal(true);
expect(data[0].example.attributes.e.size).to.equal(2);
expect(data[0].example.attributes.e.default).equal(null);
expect(data[0].example.attributes.e.default).to.not.exist;
});

it('f: should be a curve attribute in an unsual format', function () {
Expand Down

0 comments on commit 1a9e75e

Please sign in to comment.