-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(map): Adds map declaration analysis to concerto-analysis (#691)
* feat(maps): export MapDeclaration type definitions Signed-off-by: jonathan.casey <[email protected]> * feat(maps): update JSDoc and type definition Signed-off-by: jonathan.casey <[email protected]> * feat(maps): adds map-declaration comparer Signed-off-by: jonathan.casey <[email protected]> * feat(maps): extends comparer for map declaration Signed-off-by: jonathan.casey <[email protected]> * feat(maps): refactor util function Signed-off-by: jonathan.casey <[email protected]> * feat(maps): adds test coverage Signed-off-by: jonathan.casey <[email protected]> * feat(maps): JSDoc Signed-off-by: jonathan.casey <[email protected]> * feat(maps): adds changelog hash Signed-off-by: jonathan.casey <[email protected]> * feat(maps): add ENABLE_MAP_TYPE env var for test run Signed-off-by: jonathan.casey <[email protected]> * feat(maps): remove improbable branch Signed-off-by: jonathan.casey <[email protected]> * feat(maps): tighten optional chain call Signed-off-by: jonathan.casey <[email protected]> * feat(maps): adds additional assertion to satisfy coveralls Signed-off-by: jonathan.casey <[email protected]> * feat(maps): add more cov Signed-off-by: jonathan.casey <[email protected]> * feat(maps): remove optional chaining Signed-off-by: jonathan.casey <[email protected]> --------- Signed-off-by: jonathan.casey <[email protected]>
- Loading branch information
1 parent
43c96e0
commit 09b3d15
Showing
19 changed files
with
196 additions
and
42 deletions.
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
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
42 changes: 42 additions & 0 deletions
42
packages/concerto-analysis/src/comparers/map-declarations.ts
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,42 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { ComparerFactory } from '../comparer'; | ||
|
||
const mapDeclarationTypeChanged: ComparerFactory = (context) => ({ | ||
compareMapDeclaration: (a, b) => { | ||
|
||
if (!a || !b) { | ||
return; | ||
} | ||
|
||
if(a.getKey().getType() !== b.getKey().getType()) { | ||
context.report({ | ||
key: 'map-key-type-changed', | ||
message: `The map key type was changed to "${b.getKey().getType()}"`, | ||
element: b | ||
}); | ||
} | ||
|
||
if(a.getValue().getType() !== b.getValue().getType()) { | ||
context.report({ | ||
key: 'map-value-type-changed', | ||
message: `The map value type was changed to "${b.getValue().getType()}"`, | ||
element: b | ||
}); | ||
} | ||
}, | ||
}); | ||
|
||
export const mapDeclarationComparerFactories = [mapDeclarationTypeChanged]; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace [email protected] | ||
|
||
map Thing { | ||
o String | ||
o String | ||
} |
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,6 @@ | ||
namespace [email protected] | ||
|
||
map Thing { | ||
o DateTime | ||
o String | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/concerto-analysis/test/fixtures/map-changed-value.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,6 @@ | ||
namespace [email protected] | ||
|
||
map Thing { | ||
o String | ||
o DateTime | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { ClassDeclaration, ModelFile, ModelManager, Property, Validator, Field } from '@accordproject/concerto-core'; | ||
import { getClassDeclarationType, getPropertyType, getValidatorType } from '../../src/compare-utils'; | ||
import { getDeclarationType, getPropertyType, getValidatorType } from '../../src/compare-utils'; | ||
|
||
// This test suite should disappear once we port concerto-core to TypeScript because the error branches will be enforced by the transpiler. | ||
|
||
|
@@ -19,7 +19,7 @@ const field = new Field(classDeclaration, propertyAst); | |
const validator = new Validator(field, undefined); | ||
|
||
test('should throw for unknown class declaration type', () => { | ||
expect(() => getClassDeclarationType(classDeclaration)).toThrow('unknown class declaration type "ClassDeclaration {[email protected] super=Concept enum=false abstract=false}"'); | ||
expect(() => getDeclarationType(classDeclaration)).toThrow('unknown class declaration type "ClassDeclaration {[email protected] super=Concept enum=false abstract=false}"'); | ||
}); | ||
|
||
test('should throw for unknown class property type', () => { | ||
|
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.