-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): Support for more dotnet built-in types (#605)
* Support for more dotnet builtin types Signed-off-by: [email protected] <[email protected]> * remove redundant types Signed-off-by: [email protected] <[email protected]> --------- Signed-off-by: [email protected] <[email protected]>
- Loading branch information
1 parent
58f34e5
commit 30590fc
Showing
2 changed files
with
76 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ const ModelFile = require('@accordproject/concerto-core').ModelFile; | |
const ModelManager = require('@accordproject/concerto-core').ModelManager; | ||
const RelationshipDeclaration = require('@accordproject/concerto-core').RelationshipDeclaration; | ||
const FileWriter = require('@accordproject/concerto-util').FileWriter; | ||
const csharpBuiltInTypes = ['bool','byte','char','decimal','double','float','int','long','nint','nuint','sbyte','short', | ||
'string','uint','ulong','ushort']; | ||
|
||
describe('CSharpVisitor', function () { | ||
let csharpVisitor; | ||
|
@@ -83,6 +85,43 @@ describe('CSharpVisitor', function () { | |
file2.should.match(/namespace org.acme.other;/); | ||
}); | ||
|
||
csharpBuiltInTypes.forEach(builtInType => { | ||
it('should use the dotnet built in type '+ builtInType +' if @DotNetType if present', () => { | ||
const modelManager = new ModelManager({ strict: true }); | ||
modelManager.addCTOModel(` | ||
namespace [email protected] | ||
concept Thing { | ||
@DotNetType("`+ builtInType +`") | ||
o String builtInTypeValue | ||
@DotNetType("`+ builtInType +`") | ||
o String optionalBuiltInTypeValue optional | ||
} | ||
`); | ||
csharpVisitor.visit(modelManager, { fileWriter }); | ||
const files = fileWriter.getFilesInMemory(); | ||
const file = files.get('[email protected]'); | ||
let matchText = 'public '+ builtInType + ' builtInTypeValue'; | ||
file.should.match(new RegExp(matchText,'g')); | ||
matchText = 'public '+ builtInType + '\\? optionalBuiltInTypeValue'; | ||
file.should.match(new RegExp(matchText,'g')); | ||
}); | ||
}); | ||
|
||
it('should throw an error when an non built in @DotNetType is supplied', () => { | ||
const modelManager = new ModelManager({ strict: true }); | ||
modelManager.addCTOModel(` | ||
namespace [email protected] | ||
concept Thing { | ||
@DotNetType("nonBuiltInType") | ||
o String builtInTypeValue | ||
}`); | ||
(() => { | ||
csharpVisitor.visit(modelManager, { fileWriter }); | ||
}).should.throw('Malformed @DotNetType decorator'); | ||
}); | ||
|
||
it('should use the @DotNetNamespace decorator if present', () => { | ||
const modelManager = new ModelManager({ strict: true }); | ||
modelManager.addCTOModel(` | ||
|
@@ -1137,6 +1176,11 @@ describe('CSharpVisitor', function () { | |
it('should return Guid for Scalar type UUID', () => { | ||
csharpVisitor.toCSharpType('concerto.scalar.UUID').should.deep.equal('System.Guid'); | ||
}); | ||
csharpBuiltInTypes.forEach(builtInType => { | ||
it('should return ' + builtInType + ' for ' + builtInType, () => { | ||
csharpVisitor.toCSharpType(builtInType).should.deep.equal(builtInType); | ||
}); | ||
}); | ||
it('should return passed in type by default', () => { | ||
csharpVisitor.toCSharpType('Penguin').should.deep.equal('Penguin'); | ||
}); | ||
|