Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): missing array modifier for scalar fields #746

Merged
merged 7 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/concerto-core/lib/introspect/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class Field extends Property {

fieldAst.name = this.ast.name;
this.scalarField = new Field(this.getParent(), fieldAst);
this.scalarField.array = this.isArray();
return this.scalarField;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace com.testing

scalar SSN extends String default="000-00-0000" regex=/\d{3}-\d{2}-\{4}+/

concept Persons {
o SSN[] ssnArray
}
5 changes: 5 additions & 0 deletions packages/concerto-core/test/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ describe('ClassDeclaration', () => {
const clazz = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.scalaridentifier.cto', ConceptDeclaration);
clazz.validate();
});

it('should not throw when a scalar array is used as an identifier', () => {
const clazz = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.scalararray.cto', ConceptDeclaration);
clazz.validate();
});
});

describe('#accept', () => {
Expand Down
30 changes: 30 additions & 0 deletions packages/concerto-core/test/introspect/scalars.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,35 @@ describe('Scalars', () => {
p.getScalarField().getType().should.equal('DateTime');
});

it('should handle arrays correctly', () => {
mockScalarDeclaration.ast = {
$class: `${MetaModelNamespace}.StringScalar`,
name: 'MyScalar',
};
const p = new Field(mockClassDeclaration, {
$class: `${MetaModelNamespace}.ObjectProperty`,
name: 'property',
type: {
name: 'MyScalar',
},
isArray: true
});
p.getScalarField().isArray().should.equal(true);
});

it('should handle non-arrays correctly', () => {
mockScalarDeclaration.ast = {
$class: `${MetaModelNamespace}.StringScalar`,
name: 'MyScalar',
};
const p = new Field(mockClassDeclaration, {
$class: `${MetaModelNamespace}.ObjectProperty`,
name: 'property',
type: {
name: 'MyScalar',
},
});
p.getScalarField().isArray().should.equal(false);
});
});
});
Loading