-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!(core): detect ambiguous imports / declarations (#800)
* fix(core): detect ambiguous imports / declarations Signed-off-by: Matt Roberts <[email protected]> * fix(lint): assetdeclaration Signed-off-by: Matt Roberts <[email protected]> --------- Signed-off-by: Matt Roberts <[email protected]> Signed-off-by: Angel Mendez Cano <[email protected]>
- Loading branch information
Showing
13 changed files
with
79 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,18 +33,6 @@ const COMPOSER_MODEL = | |
*/ | ||
namespace [email protected] | ||
event Event { | ||
} | ||
participant Participant { | ||
} | ||
asset Asset { | ||
} | ||
transaction Transaction { | ||
} | ||
/** | ||
* Abstract system participant that all participants extend. | ||
* Has no properties, and is soley used as a basis to model other assets. | ||
|
19 changes: 0 additions & 19 deletions
19
packages/concerto-core/test/data/parser/assetdeclaration.systypename.cto
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -14,12 +14,12 @@ | |
|
||
namespace [email protected] | ||
|
||
asset Asset identified by id { | ||
asset MyAsset identified by id { | ||
o String id | ||
o String newValue | ||
} | ||
|
||
asset Asset identified by id { | ||
asset MyAsset identified by id { | ||
o String id | ||
o String newValue | ||
} |
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 |
---|---|---|
|
@@ -14,12 +14,12 @@ | |
|
||
namespace [email protected] | ||
|
||
concept Concept{ | ||
concept MyConcept { | ||
o String id | ||
o String newValue | ||
} | ||
|
||
concept Concept{ | ||
concept MyConcept { | ||
o String id | ||
o String newValue | ||
} |
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
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 |
---|---|---|
|
@@ -282,6 +282,46 @@ describe('ModelFile', () => { | |
}).should.throw('Importing types from different versions ("1.0.0", "2.0.0") of the same namespace "[email protected]" is not permitted.'); | ||
}); | ||
|
||
it('should throw when declaring an ambiguous type', () => { | ||
const myModelManager = new ModelManager(); | ||
|
||
const model1 = `namespace [email protected] | ||
concept B { | ||
o String name | ||
}`; | ||
|
||
const model2 = `namespace [email protected] | ||
import [email protected].{B} | ||
concept B { | ||
}`; | ||
|
||
|
||
let modelFile1 = ParserUtil.newModelFile(myModelManager, model1); | ||
myModelManager.addModelFile(modelFile1); | ||
|
||
let modelFile2 = ParserUtil.newModelFile(myModelManager, model2); | ||
|
||
(() => { | ||
myModelManager.addModelFile(modelFile2); | ||
}).should.throw('Type \'B\' clashes with an imported type with the same name.'); | ||
}); | ||
|
||
it('should recognise a user-space type with the same name as a Prototype', () => { | ||
const model1 = ` | ||
namespace [email protected] | ||
concept Transaction {} | ||
`; | ||
|
||
let modelFile1 = ParserUtil.newModelFile(modelManager, model1); | ||
|
||
(() => { | ||
modelManager.addModelFile(modelFile1); | ||
}).should.throw('Type \'Transaction\' clashes with an imported type with the same name.'); | ||
}); | ||
|
||
}); | ||
|
||
describe('#getDefinitions', () => { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ describe('Concept Identifiers', function () { | |
--> Product product | ||
} | ||
transaction Request {} | ||
event Event {} | ||
event MyEvent {} | ||
`, 'test.cto'); | ||
classDecl = modelManager.getType('[email protected]'); | ||
}); | ||
|
@@ -98,7 +98,7 @@ describe('Concept Identifiers', function () { | |
const txn = factory.newResource('[email protected]', 'Request'); | ||
dayjs(txn.getTimestamp()).isValid().should.be.true; | ||
|
||
const event = factory.newResource('[email protected]', 'Event'); | ||
const event = factory.newResource('[email protected]', 'MyEvent'); | ||
dayjs(event.getTimestamp()).isValid().should.be.true; | ||
}); | ||
|
||
|
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 |
---|---|---|
|
@@ -882,11 +882,11 @@ concept Bar { | |
}); | ||
|
||
describe('#getDeclarations', () => { | ||
const numberModelBaseAssets = 13; | ||
const numberModelBaseAssets = 12; | ||
const numberModelBaseEnums = 2; | ||
const numberModelBaseParticipants = 5; | ||
const numberModelBaseEvents = 1; | ||
const numberModelBaseTransactions = 21; | ||
const numberModelBaseParticipants = 4; | ||
const numberModelBaseEvents = 0; | ||
const numberModelBaseTransactions = 20; | ||
const numberModelBaseConcepts = 2; | ||
|
||
describe('#getAssetDeclarations', () => { | ||
|
@@ -1122,7 +1122,7 @@ concept Bar { | |
modelManager.addModelFiles([composerModel, modelBase, farm2fork, concertoModel]); | ||
|
||
modelManager.getModelFiles().length.should.equal(5); | ||
modelManager.getModelFiles().map(mf => mf.getAllDeclarations()).flat().length.should.equal(69); | ||
modelManager.getModelFiles().map(mf => mf.getAllDeclarations()).flat().length.should.equal(65); | ||
|
||
const filtered = modelManager.filter(declaration => declaration.getFullyQualifiedName() === '[email protected]'); | ||
|
||
|