diff --git a/packages/concerto-core/lib/introspect/field.js b/packages/concerto-core/lib/introspect/field.js index b23a4c4c8..2af86d4b8 100644 --- a/packages/concerto-core/lib/introspect/field.js +++ b/packages/concerto-core/lib/introspect/field.js @@ -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; } } diff --git a/packages/concerto-core/test/data/parser/classdeclaration.scalararray.cto b/packages/concerto-core/test/data/parser/classdeclaration.scalararray.cto new file mode 100644 index 000000000..cfdb386e8 --- /dev/null +++ b/packages/concerto-core/test/data/parser/classdeclaration.scalararray.cto @@ -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 +} diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index 60a365ed4..823862ab8 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -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', () => { diff --git a/packages/concerto-core/test/introspect/scalars.js b/packages/concerto-core/test/introspect/scalars.js index 4de2d0ce0..265ce7dc7 100644 --- a/packages/concerto-core/test/introspect/scalars.js +++ b/packages/concerto-core/test/introspect/scalars.js @@ -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); + }); }); });