-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
feat(map): Support Map Key Type Imports #739
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/concerto-core/test/data/parser/mapdeclaration/base.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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 [email protected] | ||
|
||
concept Thing { | ||
o String name | ||
} | ||
|
||
scalar Time extends DateTime |
21 changes: 21 additions & 0 deletions
21
...es/concerto-core/test/data/parser/mapdeclaration/mapdeclaration.badkey.imported.thing.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | ||
|
||
import [email protected].{Thing} | ||
|
||
map Dictionary { | ||
o Thing | ||
o String | ||
} |
21 changes: 21 additions & 0 deletions
21
.../concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodkey.imported.scalar.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | ||
|
||
import [email protected] | ||
|
||
map Dictionary { | ||
o Time | ||
o String | ||
} |
21 changes: 21 additions & 0 deletions
21
...concerto-core/test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [email protected] | ||
|
||
import [email protected] | ||
|
||
map Dictionary { | ||
o String | ||
o Thing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ const ParserUtil = require('./parserutility'); | |
|
||
const ModelManager = require('../../lib/modelmanager'); | ||
const Util = require('../composer/composermodelutility'); | ||
const fs = require('fs'); | ||
|
||
const sinon = require('sinon'); | ||
const expect = require('chai').expect; | ||
|
@@ -46,7 +47,7 @@ describe('MapDeclaration', () => { | |
|
||
describe('#constructor', () => { | ||
|
||
it('should throw if ast contains no Map Key Property', () => { | ||
it('should throw if ast contains no Map Key Type', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -162,6 +163,13 @@ describe('MapDeclaration', () => { | |
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodkey.scalar.string.cto', MapDeclaration); | ||
decl.validate(); | ||
}); | ||
|
||
it('should validate when map key is imported and is of valid map key type', () => { | ||
const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8'); | ||
introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto'); | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodkey.imported.scalar.cto', MapDeclaration); | ||
decl.validate(); | ||
}); | ||
}); | ||
|
||
describe('#validate success scenarios - Map Value', () => { | ||
|
@@ -254,11 +262,18 @@ describe('MapDeclaration', () => { | |
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.primitive.long.cto', MapDeclaration); | ||
decl.validate(); | ||
}); | ||
|
||
it('should validate when map value is imported and is of valid map key type', () => { | ||
const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8'); | ||
introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto'); | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.goodvalue.imported.thing.cto', MapDeclaration); | ||
decl.validate(); | ||
}); | ||
}); | ||
|
||
describe('#validate failure scenarios - Map Key', () => { | ||
|
||
it('should throw if ast contains illegal Map Key Property', () => { | ||
it('should throw if ast contains illegal Map Key Type', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -273,42 +288,42 @@ describe('MapDeclaration', () => { | |
}).should.throw(IllegalModelException); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Concept', () => { | ||
it('should throw if ast contains illegal Map Key Type - Concept', () => { | ||
(() => { | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.declaration.concept.cto', MapDeclaration); | ||
decl.validate().should.throw(IllegalModelException); | ||
}); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Scalar Long', () => { | ||
it('should throw if ast contains illegal Map Key Type - Scalar Long', () => { | ||
(() => { | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.long.cto', MapDeclaration); | ||
decl.validate(); | ||
}); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Scalar Integer', () => { | ||
it('should throw if ast contains illegal Map Key Type - Scalar Integer', () => { | ||
(() => { | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.integer.cto', MapDeclaration); | ||
decl.validate().should.throw(IllegalModelException); | ||
}); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Scalar Double', () => { | ||
it('should throw if ast contains illegal Map Key Type - Scalar Double', () => { | ||
(() => { | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.double.cto', MapDeclaration); | ||
decl.validate().should.throw(IllegalModelException); | ||
}); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Scalar Boolean', () => { | ||
it('should throw if ast contains illegal Map Key Type - Scalar Boolean', () => { | ||
(() => { | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.scalar.boolean.cto', MapDeclaration); | ||
decl.validate().should.throw(IllegalModelException); | ||
}); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Boolean', () => { | ||
it('should throw if ast contains illegal Map Key Type - Boolean', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -323,7 +338,7 @@ describe('MapDeclaration', () => { | |
}).should.throw(IllegalModelException); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Integer', () => { | ||
it('should throw if ast contains illegal Map Key Type - Integer', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -338,7 +353,7 @@ describe('MapDeclaration', () => { | |
}).should.throw(IllegalModelException); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Long', () => { | ||
it('should throw if ast contains illegal Map Key Type - Long', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -353,7 +368,7 @@ describe('MapDeclaration', () => { | |
}).should.throw(IllegalModelException); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Double', () => { | ||
it('should throw if ast contains illegal Map Key Type - Double', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -368,7 +383,7 @@ describe('MapDeclaration', () => { | |
}).should.throw(IllegalModelException); | ||
}); | ||
|
||
it('should throw if ast contains illegal Map Key Property - Enum', () => { | ||
it('should throw if ast contains illegal Map Key Type - Enum', () => { | ||
(() => { | ||
new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
|
@@ -386,6 +401,15 @@ describe('MapDeclaration', () => { | |
}); | ||
}).should.throw(IllegalModelException); | ||
}); | ||
|
||
it('should throw when map key is imported and is an illegal Map Key Type', () => { | ||
(() => { | ||
const base_cto = fs.readFileSync('test/data/parser/mapdeclaration/base.cto', 'utf-8'); | ||
introspectUtils.modelManager.addCTOModel(base_cto, 'base.cto'); | ||
let decl = introspectUtils.loadLastDeclaration('test/data/parser/mapdeclaration/mapdeclaration.badkey.imported.thing.cto', MapDeclaration); | ||
decl.validate().should.throw(IllegalModelException); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#validate failure scenarios - Map Value', () => { | ||
|
@@ -489,7 +513,7 @@ describe('MapDeclaration', () => { | |
}); | ||
|
||
describe('#getKey', () => { | ||
it('should return the map key property', () => { | ||
it('should return the Map Key Type', () => { | ||
let clz = new MapDeclaration(modelFile, { | ||
$class: '[email protected]', | ||
name: 'MapPermutation1', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in the jsdoc - this is not map specific.
Not sure we need this function. ModelFile.getType takes a short type name and returns the FQN, taking care of primitive, imported types and reports errors.
The docs for this function are not clear in whether type is a short name or FQN and what happens with primitives, and what happens if the type does not exist (null/undefined return or throws an exception).
In general in Concerto we use "from biggest to smallest" when we order function args, so this would be (model, type).
If you decide we need this function, then the implementation could be: