From cc05debb4fcdecec5a1ba3039454b3b9c7e7085b Mon Sep 17 00:00:00 2001 From: Gopalakrishna Palem Date: Mon, 23 Oct 2023 07:45:03 +0530 Subject: [PATCH 1/4] Fix: missing array modifier for scalar fields https://github.com/accordproject/concerto/issues/346 Signed-off-by: Gopalakrishna Palem --- packages/concerto-core/lib/introspect/field.js | 1 + 1 file changed, 1 insertion(+) 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; } } From f23aa4f3c2f573bfaab7b44d7893de227df60974 Mon Sep 17 00:00:00 2001 From: Gopalakrishna Palem Date: Mon, 23 Oct 2023 07:45:03 +0530 Subject: [PATCH 2/4] Fix: missing array modifier for scalar fields https://github.com/accordproject/concerto/issues/346 Signed-off-by: Gopalakrishna Palem --- .../concerto-core/lib/introspect/field.js | 1 + .../parser/classdeclaration.scalararray.cto | 21 +++++++++++++++++++ .../test/introspect/classdeclaration.js | 5 +++++ .../concerto-core/test/introspect/scalars.js | 16 ++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 packages/concerto-core/test/data/parser/classdeclaration.scalararray.cto 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..4be11bfce 100644 --- a/packages/concerto-core/test/introspect/scalars.js +++ b/packages/concerto-core/test/introspect/scalars.js @@ -171,5 +171,21 @@ describe('Scalars', () => { p.getScalarField().getType().should.equal('DateTime'); }); + it("should handle arrays correctly", () => { + const p = new Field(mockClassDeclaration, { + $class: `${MetaModelNamespace}.StringProperty`, + name: "property", + array: true + }); + p.getScalarField().isArray().should.equal(true); + }); + + it("should handle non-arrays correctly", () => { + const p = new Field(mockClassDeclaration, { + $class: `${MetaModelNamespace}.StringProperty`, + name: "property", + }); + p.getScalarField().isArray().should.equal(false); + }); }); }); From b4f4e9aa9fd6c5a416bca0cfcac343ba571fec37 Mon Sep 17 00:00:00 2001 From: Matt Roberts <7544022+mttrbrts@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:57:10 +0100 Subject: [PATCH 3/4] Apply suggestions from code review --- packages/concerto-core/test/introspect/scalars.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/concerto-core/test/introspect/scalars.js b/packages/concerto-core/test/introspect/scalars.js index 17177af48..5fa471c30 100644 --- a/packages/concerto-core/test/introspect/scalars.js +++ b/packages/concerto-core/test/introspect/scalars.js @@ -174,7 +174,7 @@ describe('Scalars', () => { it('should handle arrays correctly', () => { const p = new Field(mockClassDeclaration, { $class: `${MetaModelNamespace}.StringProperty`, - name: "property", + name: 'property', array: true }); p.getScalarField().isArray().should.equal(true); @@ -183,7 +183,7 @@ describe('Scalars', () => { it('should handle non-arrays correctly', () => { const p = new Field(mockClassDeclaration, { $class: `${MetaModelNamespace}.StringProperty`, - name: "property", + name: 'property', }); p.getScalarField().isArray().should.equal(false); }); From bf0509cc890adf3a56afadb87d2d99d8fee37c0e Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Tue, 24 Oct 2023 16:58:16 +0100 Subject: [PATCH 4/4] test(scalar): fix array test for scalars Signed-off-by: Matt Roberts --- .../concerto-core/test/introspect/scalars.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/concerto-core/test/introspect/scalars.js b/packages/concerto-core/test/introspect/scalars.js index 5fa471c30..265ce7dc7 100644 --- a/packages/concerto-core/test/introspect/scalars.js +++ b/packages/concerto-core/test/introspect/scalars.js @@ -172,18 +172,32 @@ describe('Scalars', () => { }); it('should handle arrays correctly', () => { + mockScalarDeclaration.ast = { + $class: `${MetaModelNamespace}.StringScalar`, + name: 'MyScalar', + }; const p = new Field(mockClassDeclaration, { - $class: `${MetaModelNamespace}.StringProperty`, + $class: `${MetaModelNamespace}.ObjectProperty`, name: 'property', - array: true + 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}.StringProperty`, + $class: `${MetaModelNamespace}.ObjectProperty`, name: 'property', + type: { + name: 'MyScalar', + }, }); p.getScalarField().isArray().should.equal(false); });