forked from accordproject/concerto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): detect primitive to declaration and namespace changes (contr…
…ibutes to accordproject#442) Signed-off-by: Simon Stone <[email protected]>
- Loading branch information
Simon Stone
authored and
Simon Stone
committed
Aug 5, 2022
1 parent
a85f35b
commit 34a2c08
Showing
12 changed files
with
198 additions
and
16 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
7 changes: 7 additions & 0 deletions
7
packages/concerto-analysis/test/fixtures/field-namespace-changed-a.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,7 @@ | ||
namespace [email protected] | ||
|
||
import { Bar } from [email protected] | ||
|
||
concept Thing { | ||
o Bar bar | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/concerto-analysis/test/fixtures/field-namespace-changed-b.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,7 @@ | ||
namespace [email protected] | ||
|
||
import { Bar } from [email protected] | ||
|
||
concept Thing { | ||
o Bar bar | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/concerto-analysis/test/fixtures/field-namespace-changed-major-b.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,7 @@ | ||
namespace [email protected] | ||
|
||
import { Bar } from [email protected] | ||
|
||
concept Thing { | ||
o Bar bar | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/concerto-analysis/test/fixtures/field-namespace-changed-minor-b.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,7 @@ | ||
namespace [email protected] | ||
|
||
import { Bar } from [email protected] | ||
|
||
concept Thing { | ||
o Bar bar | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/concerto-analysis/test/fixtures/field-namespace-changed-patch-b.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,7 @@ | ||
namespace [email protected] | ||
|
||
import { Bar } from [email protected] | ||
|
||
concept Thing { | ||
o Bar bar | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/concerto-analysis/test/fixtures/primitive-to-declaration-a.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,9 @@ | ||
namespace [email protected] | ||
|
||
concept Bar { | ||
|
||
} | ||
|
||
concept Thing { | ||
o String bar | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/concerto-analysis/test/fixtures/primitive-to-declaration-b.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,9 @@ | ||
namespace [email protected] | ||
|
||
concept Bar { | ||
|
||
} | ||
|
||
concept Thing { | ||
o Bar bar | ||
} |
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 |
---|---|---|
|
@@ -212,3 +212,65 @@ test('should detect an array changing to a scalar', async () => { | |
])); | ||
expect(results.result).toBe(CompareResult.MAJOR); | ||
}); | ||
|
||
test('should detect a primitive typed field changing to a declaration typed field', async () => { | ||
const [a, b] = await getModelFiles('primitive-to-declaration-a.cto', 'primitive-to-declaration-b.cto'); | ||
const results = new Compare().compare(a, b); | ||
expect(results.findings).toEqual(expect.arrayContaining([ | ||
expect.objectContaining({ | ||
key: 'property-type-changed', | ||
message: 'The field "bar" in the concept "Thing" changed type from "String" to "[email protected]" (type name differs)' | ||
}) | ||
])); | ||
expect(results.result).toBe(CompareResult.MAJOR); | ||
}); | ||
|
||
test('should detect a declaration typed field changing to a primitive typed field', async () => { | ||
const [a, b] = await getModelFiles('primitive-to-declaration-b.cto', 'primitive-to-declaration-a.cto'); | ||
const results = new Compare().compare(a, b); | ||
expect(results.findings).toEqual(expect.arrayContaining([ | ||
expect.objectContaining({ | ||
key: 'property-type-changed', | ||
message: 'The field "bar" in the concept "Thing" changed type from "[email protected]" to "String" (type name differs)' | ||
}) | ||
])); | ||
expect(results.result).toBe(CompareResult.MAJOR); | ||
}); | ||
|
||
test('should detect a declaration typed field namespace change', async () => { | ||
const [a, b] = await getModelFiles('field-namespace-changed-a.cto', 'field-namespace-changed-b.cto'); | ||
const results = new Compare().compare(a, b); | ||
expect(results.findings).toEqual(expect.arrayContaining([ | ||
expect.objectContaining({ | ||
key: 'property-type-changed', | ||
message: 'The field "bar" in the concept "Thing" changed type from "[email protected]" to "[email protected]" (type namespace differs)' | ||
}) | ||
])); | ||
expect(results.result).toBe(CompareResult.MAJOR); | ||
}); | ||
|
||
test('should not detect a declaration typed field namespace patch version change', async () => { | ||
const [a, b] = await getModelFiles('field-namespace-changed-a.cto', 'field-namespace-changed-patch-b.cto'); | ||
const results = new Compare().compare(a, b); | ||
expect(results.findings).toHaveLength(0); | ||
expect(results.result).toBe(CompareResult.NONE); | ||
}); | ||
|
||
test('should not detect a declaration typed field namespace minor version change', async () => { | ||
const [a, b] = await getModelFiles('field-namespace-changed-a.cto', 'field-namespace-changed-minor-b.cto'); | ||
const results = new Compare().compare(a, b); | ||
expect(results.findings).toHaveLength(0); | ||
expect(results.result).toBe(CompareResult.NONE); | ||
}); | ||
|
||
test('should detect a declaration typed field namespace major version change', async () => { | ||
const [a, b] = await getModelFiles('field-namespace-changed-a.cto', 'field-namespace-changed-major-b.cto'); | ||
const results = new Compare().compare(a, b); | ||
expect(results.findings).toEqual(expect.arrayContaining([ | ||
expect.objectContaining({ | ||
key: 'property-type-changed', | ||
message: 'The field "bar" in the concept "Thing" changed type from "[email protected]" to "[email protected]" (type version incompatible)' | ||
}) | ||
])); | ||
expect(results.result).toBe(CompareResult.MAJOR); | ||
}); |