C#: Various fixes to generic scripts
- Report a diagnostic when there are multiple classes that match the script file name in the same script since that will result in a duplicate path key in the bimap and it's not allowed. - Fix InspectorPlugin to handle empty paths in case the project was built with a previous version of Godot that used empty paths for generic scripts. - Add tests for the new diagnostic GD0003.
This commit is contained in:
+27
-2
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -47,9 +48,33 @@ public class ScriptPathAttributeGeneratorTests
|
||||
{
|
||||
var verifier = CSharpSourceGeneratorVerifier<ScriptPathAttributeGenerator>.MakeVerifier(
|
||||
new string[] { "Generic.cs" },
|
||||
new string[] { "Generic_ScriptPath.generated.cs" }
|
||||
new string[] { "Generic(Of T)_ScriptPath.generated.cs" }
|
||||
);
|
||||
verifier.TestState.GeneratedSources.Add(MakeAssemblyScriptTypesGeneratedSource(new string[] { "global::Generic" }));
|
||||
verifier.TestState.GeneratedSources.Add(MakeAssemblyScriptTypesGeneratedSource(new string[] { "global::Generic<>" }));
|
||||
await verifier.RunAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GenericMultipleClassesSameName()
|
||||
{
|
||||
var verifier = CSharpSourceGeneratorVerifier<ScriptPathAttributeGenerator>.MakeVerifier(
|
||||
Array.Empty<string>(),
|
||||
new string[] { "Generic(Of T)_ScriptPath.generated.cs" }
|
||||
);
|
||||
verifier.TestState.Sources.Add(("Generic.cs", File.ReadAllText(Path.Combine(Constants.SourceFolderPath, "Generic.GD0003.cs"))));
|
||||
verifier.TestState.GeneratedSources.Add(MakeAssemblyScriptTypesGeneratedSource(new string[] { "global::Generic<>", "global::Generic<,>", "global::Generic" }));
|
||||
await verifier.RunAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void NamespaceMultipleClassesSameName()
|
||||
{
|
||||
var verifier = CSharpSourceGeneratorVerifier<ScriptPathAttributeGenerator>.MakeVerifier(
|
||||
Array.Empty<string>(),
|
||||
new string[] { "NamespaceA.SameName_ScriptPath.generated.cs" }
|
||||
);
|
||||
verifier.TestState.Sources.Add(("SameName.cs", File.ReadAllText(Path.Combine(Constants.SourceFolderPath, "SameName.GD0003.cs"))));
|
||||
verifier.TestState.GeneratedSources.Add(MakeAssemblyScriptTypesGeneratedSource(new string[] { "global::NamespaceA.SameName", "global::NamespaceB.SameName" }));
|
||||
await verifier.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
using Godot;
|
||||
[ScriptPathAttribute("res://Generic.cs")]
|
||||
partial class Generic
|
||||
partial class Generic<T>
|
||||
{
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using Godot;
|
||||
namespace NamespaceA {
|
||||
|
||||
[ScriptPathAttribute("res://SameName.cs")]
|
||||
partial class SameName
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
|
||||
partial class Generic<T> : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
|
||||
// Generic again but different generic parameters
|
||||
partial class {|GD0003:Generic|}<T, R> : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
|
||||
// Generic again but without generic parameters
|
||||
partial class {|GD0003:Generic|} : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
-12
@@ -4,15 +4,3 @@ partial class Generic<T> : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
|
||||
// Generic again but different generic parameters
|
||||
partial class Generic<T, R> : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
|
||||
// Generic again but without generic parameters
|
||||
partial class Generic : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
|
||||
namespace NamespaceA
|
||||
{
|
||||
partial class SameName : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
}
|
||||
|
||||
// SameName again but different namespace
|
||||
namespace NamespaceB
|
||||
{
|
||||
partial class {|GD0003:SameName|} : GodotObject
|
||||
{
|
||||
private int _field;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user