This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add codegen tests for name clashes (#1380)
- Loading branch information
Paul Balaji
authored
Jun 2, 2020
1 parent
1ce9ba6
commit a69a09e
Showing
14 changed files
with
389 additions
and
28 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 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
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
9 changes: 9 additions & 0 deletions
9
...mplate/CodeGenerationLib/Tests/Model/NameClashingSchema/clash_command_in_component.schema
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 @@ | ||
package improbable.gdk.test; | ||
|
||
import "improbable/gdk/core/common.schema"; | ||
|
||
component IllegalComponentCommand | ||
{ | ||
id=12499; | ||
command improbable.gdk.core.Empty illegal_component_command(improbable.gdk.core.Empty); | ||
} |
9 changes: 9 additions & 0 deletions
9
...odeGenTemplate/CodeGenerationLib/Tests/Model/NameClashingSchema/clash_enum_in_type.schema
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 @@ | ||
package improbable.gdk.test; | ||
|
||
type IllegalEnumField { | ||
enum NestedEnum { | ||
SUCCESS = 0; | ||
FAILURE = 1; | ||
} | ||
NestedEnum nested_enum = 1; | ||
} |
9 changes: 9 additions & 0 deletions
9
...Template/CodeGenerationLib/Tests/Model/NameClashingSchema/clash_event_in_component.schema
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 @@ | ||
package improbable.gdk.test; | ||
|
||
import "improbable/gdk/core/common.schema"; | ||
|
||
component IllegalComponentEvent | ||
{ | ||
id=12599; | ||
event improbable.gdk.core.Empty illegal_component_event; | ||
} |
6 changes: 6 additions & 0 deletions
6
...odeGenTemplate/CodeGenerationLib/Tests/Model/NameClashingSchema/clash_type_in_type.schema
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 @@ | ||
package improbable.gdk.test; | ||
|
||
type IllegalTypeField { | ||
type NestedType {} | ||
NestedType nested_type = 1; | ||
} |
103 changes: 103 additions & 0 deletions
103
....improbable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/Tests/Model/NameClashingTests.cs
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,103 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using Improbable.Gdk.CodeGeneration.Model; | ||
using Improbable.Gdk.CodeGeneration.Model.Details; | ||
using NLog; | ||
using NLog.Config; | ||
using NLog.Fluent; | ||
using NLog.Targets; | ||
using NUnit.Framework; | ||
|
||
namespace Improbable.Gdk.CodeGeneration.Tests.Model | ||
{ | ||
[TestFixture] | ||
public class NameClashingTests | ||
{ | ||
private MemoryTarget memoryTarget; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
memoryTarget = new MemoryTarget("MemoryTarget"); | ||
|
||
var configuration = new LoggingConfiguration(); | ||
configuration.AddTarget(memoryTarget); | ||
configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Error, memoryTarget)); | ||
|
||
LogManager.Configuration = configuration; | ||
} | ||
|
||
[Test] | ||
public void Clashing_command_in_component() | ||
{ | ||
var bundleName = "clash_command_in_component"; | ||
var qualifiedName = "improbable.gdk.test.IllegalComponentCommand"; | ||
|
||
var store = GetDetailsFromBundle(bundleName); | ||
|
||
Assert.IsTrue(store.Components.ContainsKey(qualifiedName)); | ||
Assert.AreEqual(0, store.Components[qualifiedName].CommandDetails.Count); | ||
|
||
Assert.AreEqual(1, memoryTarget.Logs.Count); | ||
} | ||
|
||
[Test] | ||
public void Clashing_event_in_component() | ||
{ | ||
var bundleName = "clash_event_in_component"; | ||
var qualifiedName = "improbable.gdk.test.IllegalComponentEvent"; | ||
|
||
var store = GetDetailsFromBundle(bundleName); | ||
|
||
Assert.IsTrue(store.Components.ContainsKey(qualifiedName)); | ||
Assert.AreEqual(0, store.Components[qualifiedName].EventDetails.Count); | ||
|
||
Assert.AreEqual(1, memoryTarget.Logs.Count); | ||
} | ||
|
||
[Test] | ||
public void Clashing_enum_in_type() | ||
{ | ||
var bundleName = "clash_enum_in_type"; | ||
var qualifiedName = "improbable.gdk.test.IllegalEnumField"; | ||
|
||
var store = GetDetailsFromBundle(bundleName); | ||
|
||
Assert.IsTrue(store.Types.ContainsKey(qualifiedName)); | ||
Assert.IsTrue(store.Enums.ContainsKey($"{qualifiedName}.NestedEnum")); | ||
Assert.AreEqual(1, store.Types[qualifiedName].ChildEnums.Count); | ||
Assert.AreEqual(0, store.Types[qualifiedName].FieldDetails.Count); | ||
|
||
Assert.AreEqual(1, memoryTarget.Logs.Count); | ||
} | ||
|
||
[Test] | ||
public void Clashing_type_in_type() | ||
{ | ||
var bundleName = "clash_type_in_type"; | ||
var qualifiedName = "improbable.gdk.test.IllegalTypeField"; | ||
|
||
var store = GetDetailsFromBundle(bundleName); | ||
|
||
Assert.IsTrue(store.Types.ContainsKey(qualifiedName)); | ||
Assert.IsTrue(store.Types.ContainsKey($"{qualifiedName}.NestedType")); | ||
Assert.AreEqual(1, store.Types[qualifiedName].ChildTypes.Count); | ||
Assert.AreEqual(0, store.Types[qualifiedName].FieldDetails.Count); | ||
|
||
Assert.AreEqual(1, memoryTarget.Logs.Count); | ||
} | ||
|
||
private static DetailsStore GetDetailsFromBundle(string bundleName) | ||
{ | ||
var bundleResourceName = | ||
$"CodeGenerationLib.Tests.Model.SchemaBundleV1.Resources.{bundleName}.json"; | ||
|
||
var assembly = Assembly.GetExecutingAssembly(); | ||
var resource = assembly.GetManifestResourceStream(bundleResourceName); | ||
var json = new StreamReader(resource).ReadToEnd(); | ||
|
||
return new DetailsStore(SchemaBundle.LoadBundle(json), new List<string>(), null); | ||
} | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
...te/CodeGenerationLib/Tests/Model/SchemaBundleV1/Resources/clash_command_in_component.json
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,53 @@ | ||
{ | ||
"schemaFiles": [ | ||
{ | ||
"canonicalPath": "clash_command_in_component.schema", | ||
"package": { | ||
"sourceReference": { | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"name": "improbable.gdk.test" | ||
}, | ||
"imports": [ | ||
{ | ||
"sourceReference": { | ||
"line": 3, | ||
"column": 1 | ||
}, | ||
"path": "improbable/gdk/core/common.schema" | ||
} | ||
], | ||
"enums": [], | ||
"types": [], | ||
"components": [ | ||
{ | ||
"sourceReference": { | ||
"line": 5, | ||
"column": 1 | ||
}, | ||
"annotations": [], | ||
"qualifiedName": "improbable.gdk.test.IllegalComponentCommand", | ||
"name": "IllegalComponentCommand", | ||
"componentId": 12499, | ||
"dataDefinition": "", | ||
"fields": [], | ||
"events": [], | ||
"commands": [ | ||
{ | ||
"sourceReference": { | ||
"line": 5, | ||
"column": 1 | ||
}, | ||
"annotations": [], | ||
"name": "illegal_component_command", | ||
"requestType": "improbable.gdk.core.Empty", | ||
"responseType": "improbable.gdk.core.Empty", | ||
"commandIndex": 1 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
77 changes: 77 additions & 0 deletions
77
...enTemplate/CodeGenerationLib/Tests/Model/SchemaBundleV1/Resources/clash_enum_in_type.json
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,77 @@ | ||
{ | ||
"schemaFiles": [ | ||
{ | ||
"canonicalPath": "clash_enum_in_type.schema", | ||
"package": { | ||
"sourceReference": { | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"name": "improbable.gdk.test" | ||
}, | ||
"imports": [], | ||
"enums": [ | ||
{ | ||
"sourceReference": { | ||
"line": 4, | ||
"column": 5 | ||
}, | ||
"annotations": [], | ||
"qualifiedName": "improbable.gdk.test.IllegalEnumField.NestedEnum", | ||
"name": "NestedEnum", | ||
"outerType": "improbable.gdk.test.IllegalEnumField", | ||
"values": [ | ||
{ | ||
"sourceReference": { | ||
"line": 5, | ||
"column": 9 | ||
}, | ||
"annotations": [], | ||
"name": "SUCCESS", | ||
"value": 0 | ||
}, | ||
{ | ||
"sourceReference": { | ||
"line": 6, | ||
"column": 9 | ||
}, | ||
"annotations": [], | ||
"name": "FAILURE", | ||
"value": 1 | ||
} | ||
] | ||
} | ||
], | ||
"types": [ | ||
{ | ||
"sourceReference": { | ||
"line": 3, | ||
"column": 1 | ||
}, | ||
"annotations": [], | ||
"qualifiedName": "improbable.gdk.test.IllegalEnumField", | ||
"name": "IllegalEnumField", | ||
"outerType": "", | ||
"fields": [ | ||
{ | ||
"sourceReference": { | ||
"line": 8, | ||
"column": 5 | ||
}, | ||
"annotations": [], | ||
"name": "nested_enum", | ||
"fieldId": 1, | ||
"transient": false, | ||
"singularType": { | ||
"type": { | ||
"enum": "improbable.gdk.test.IllegalEnumField.NestedEnum" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"components": [] | ||
} | ||
] | ||
} |
52 changes: 52 additions & 0 deletions
52
...late/CodeGenerationLib/Tests/Model/SchemaBundleV1/Resources/clash_event_in_component.json
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,52 @@ | ||
{ | ||
"schemaFiles": [ | ||
{ | ||
"canonicalPath": "clash_event_in_component.schema", | ||
"package": { | ||
"sourceReference": { | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"name": "improbable.gdk.test" | ||
}, | ||
"imports": [ | ||
{ | ||
"sourceReference": { | ||
"line": 3, | ||
"column": 1 | ||
}, | ||
"path": "improbable/gdk/core/common.schema" | ||
} | ||
], | ||
"enums": [], | ||
"types": [], | ||
"components": [ | ||
{ | ||
"sourceReference": { | ||
"line": 5, | ||
"column": 1 | ||
}, | ||
"annotations": [], | ||
"qualifiedName": "improbable.gdk.test.IllegalComponentEvent", | ||
"name": "IllegalComponentEvent", | ||
"componentId": 12599, | ||
"dataDefinition": "", | ||
"fields": [], | ||
"events": [ | ||
{ | ||
"sourceReference": { | ||
"line": 8, | ||
"column": 5 | ||
}, | ||
"annotations": [], | ||
"name": "illegal_component_event", | ||
"type": "improbable.gdk.core.Empty", | ||
"eventIndex": 1 | ||
} | ||
], | ||
"commands": [] | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.