Skip to content

Commit

Permalink
fix(core): missing array modifier for scalar fields (#746)
Browse files Browse the repository at this point in the history
* Fix:  missing array modifier for scalar fields

#346
Signed-off-by: Gopalakrishna Palem <KrishnaPG@Yahoo.com>

* Fix:  missing array modifier for scalar fields

#346
Signed-off-by: Gopalakrishna Palem <KrishnaPG@Yahoo.com>

* Apply suggestions from code review

* test(scalar): fix array test for scalars

Signed-off-by: Matt Roberts <code@rbrts.uk>

---------

Signed-off-by: Gopalakrishna Palem <KrishnaPG@Yahoo.com>
Signed-off-by: Matt Roberts <code@rbrts.uk>
Co-authored-by: Matt Roberts <7544022+mttrbrts@users.noreply.github.com>
Co-authored-by: Matt Roberts <code@rbrts.uk>
  • Loading branch information
3 people committed Oct 24, 2023
1 parent 9ff9b0c commit 96002a1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
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);
});
});
});

0 comments on commit 96002a1

Please sign in to comment.