Essentials + extra crap
Loadings Startups Movement Camera
This commit is contained in:
1 parent
662f4a1d05
commit
5f5ace1b52
734 files changed
+107323
-1713
No files matched your search
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "FastScriptReload.Tests.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:0acc523941302664db1f4e527237feb3",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||
"GUID:b75b497805046c443a21f90e84a5ff4f",
|
||||
"GUID:97dcf6b63da809f4aa9573d9e792e540",
|
||||
"GUID:11386f958962b1e4bb7bfe4849957216"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"ImmersiveVRTools.Common.Editor.dll",
|
||||
"ImmersiveVRTools.Common.Runtime.dll",
|
||||
"0Harmony.dll",
|
||||
"Microsoft.CodeAnalysis.CSharp.dll",
|
||||
"Microsoft.CodeAnalysis.dll"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"FAST_SCRIPT_RELOAD_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2060b4187aa13b4f86125cb8077f21c
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/FastScriptReload.Tests.Editor.asmdef
|
||||
uploadId: 710802
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: febe2fc692c024c4eadab728d0dda0c4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00114660f9e847a68740513c9316c1ef
|
||||
timeCreated: 1680874891
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using FastScriptReload.Tests.Runtime.Integration.CodePatterns;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace FastScriptReload.Tests.Editor.Integration.CodePatterns
|
||||
{
|
||||
public class AccessingIdentifierNamedSameAsMethodTest : CompileWithRedirectTestBase
|
||||
{
|
||||
private static readonly string RelativeFilePath = @"Runtime\Integration\CodePatterns\AccessingIdentifierNamedSameAsMethod.cs";
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstanceFieldTypeRewritten_StandardCompilation_TypeForInstanceVariableCorrectlyRewritten()
|
||||
{
|
||||
var instance = new GameObject("instance").AddComponent<AccessingIdentifierNamedSameAsMethod>();
|
||||
|
||||
var patchedTypeName = nameof(AccessingIdentifierNamedSameAsMethod) + FastScriptReload.Runtime.AssemblyChangesLoader.ClassnamePatchedPostfix;
|
||||
TestCompileAndDetour(ResolveFullTestFilePath(RelativeFilePath), (compileResult) =>
|
||||
{
|
||||
instance.TestInstanceFieldTypeRewritten();
|
||||
});
|
||||
|
||||
AssertDetourConfirmed(typeof(AccessingIdentifierNamedSameAsMethod), nameof(instance.TestInstanceFieldTypeRewritten),
|
||||
(o) => o.ToString() == patchedTypeName,
|
||||
"Value should be set after compilation"
|
||||
);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestAccessingSameNamedVariableNotChanged_StandardCompilation_PropertyAccessInCallNotReplaced()
|
||||
{
|
||||
var instance = new GameObject("instance").AddComponent<AccessingIdentifierNamedSameAsMethod>();
|
||||
|
||||
TestCompileAndDetour(ResolveFullTestFilePath(RelativeFilePath), (compileResult) =>
|
||||
{
|
||||
instance.TestAccessingSameNamedVariableNotChanged();
|
||||
});
|
||||
|
||||
AssertDetourConfirmed(typeof(AccessingIdentifierNamedSameAsMethod), nameof(instance.TestAccessingSameNamedVariableNotChanged),
|
||||
(r) => (bool)r == true,
|
||||
"Value should be set after compilation"
|
||||
);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccf9421e7bd646d09606fb394b6b95a9
|
||||
timeCreated: 1681213826
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/Integration/CodePatterns/AccessingIdentifierNamedSameAsMethodTest.cs
|
||||
uploadId: 710802
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using FastScriptReload.Tests.Runtime.Integration.CodePatterns;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace FastScriptReload.Tests.Editor.Integration.CodePatterns
|
||||
{
|
||||
public class AccessingNewFieldsAddedAtRuntimeSameNameAsStaticClassFieldTest : CompileWithRedirectTestBase
|
||||
{
|
||||
private static readonly string RelativeFilePath = @$"Runtime\Integration\CodePatterns\{nameof(AccessingNewFieldsAddedAtRuntimeSameNameAsStaticClassField)}.cs";
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestStaticFieldAccess_StandardCompilation_CorrectRewriteCreated()
|
||||
{
|
||||
TestCompileAndDetour(ResolveFullTestFilePath(RelativeFilePath));
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca008c8e119e41f6be6bc825d15ee274
|
||||
timeCreated: 1697442442
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/Integration/CodePatterns/AccessingNewFieldsAddedAtRuntimeSameNameAsStaticClassFieldTest.cs
|
||||
uploadId: 710802
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FastScriptReload.Editor.Compilation;
|
||||
using FastScriptReload.Runtime;
|
||||
using ImmersiveVRTools.Runtime.Common;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Assert = UnityEngine.Assertions.Assert;
|
||||
|
||||
namespace FastScriptReload.Tests.Editor.Integration.CodePatterns
|
||||
{
|
||||
public delegate void AfterDetourTest(CompileResult compileResult);
|
||||
|
||||
public abstract class CompileWithRedirectTestBase : IPrebuildSetup
|
||||
{
|
||||
protected static void TestCompileAndDetour(string filePath)
|
||||
=> TestCompileAndDetour(filePath, (compileResult) => { });
|
||||
|
||||
protected static void TestCompileAndDetour(string filePath, AfterDetourTest afterDetourTest)
|
||||
{
|
||||
var originalSourceCode = File.ReadAllText(filePath);
|
||||
try
|
||||
{
|
||||
var adjustedSourceCode = originalSourceCode.Replace(TestDetourConfirmation.MockRuntimeCodeChange, string.Empty);
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText(filePath, adjustedSourceCode);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Unable to adjust code file (test), make sure it's not locked in IDE. '{filePath}', {e}");
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
var dynamicallyLoadedAssemblyCompilerResult = CompileCode(filePath);
|
||||
|
||||
var assemblyChangesLoader = AssemblyChangesLoaderResolver.Instance.Resolve();
|
||||
var options = new AssemblyChangesLoaderEditorOptionsNeededInBuild(true, false);
|
||||
assemblyChangesLoader.DynamicallyUpdateMethodsForCreatedAssembly(dynamicallyLoadedAssemblyCompilerResult.CompiledAssembly, options);
|
||||
|
||||
afterDetourTest(dynamicallyLoadedAssemblyCompilerResult);
|
||||
}
|
||||
catch (SourceCodeHasErrorsException e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
}
|
||||
catch (HotReloadCompilationException e)
|
||||
{
|
||||
Debug.Log($"Compilation Error: {e.InnerException}");
|
||||
InternalEditorUtility.OpenFileAtLineExternal(e.SourceCodeCombinedFileCreated, 0);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllText(filePath, originalSourceCode);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Unable to revert oto original code (test), make sure it's not locked in IDE. '{filePath}', {e}");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void AssertDetourConfirmed(Type type, string methodName, Func<object, bool> compareWithResultPredicate, string assertDescription)
|
||||
{
|
||||
Assert.IsTrue(TestDetourConfirmation.IsDetourConfirmed(type, methodName, compareWithResultPredicate), assertDescription);
|
||||
}
|
||||
|
||||
private static CompileResult CompileCode(string filePath)
|
||||
{
|
||||
var dispatcher = new GameObject("DispatcherInstance").AddComponent<UnityMainThreadDispatcher>();
|
||||
return DynamicAssemblyCompiler.Compile(new List<string> { filePath }, dispatcher);
|
||||
}
|
||||
|
||||
protected static string ResolveFullTestFilePath(string relativePath)
|
||||
{
|
||||
//TODO: how to resolve test path relative to proj dir for tests??
|
||||
return @$"E:\_src-unity\FastScriptReload\Assets\Tests\{relativePath}";
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
TestDetourConfirmation.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64e95a038f75d2643a69655937c0a4cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/Integration/CodePatterns/CompileWithRedirectTestBase.cs
|
||||
uploadId: 710802
|
||||
+346
@@ -0,0 +1,346 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.TestTools;
|
||||
using FastScriptReload.Editor.Compilation.CodeRewriting;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace FastScriptReload.Tests.Editor.Integration.CodePatterns
|
||||
{
|
||||
public class SyntaxTreeMergePartialsTest
|
||||
{
|
||||
private string _tempPath;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_tempPath = Path.Combine(Path.GetTempPath(), "PartialSyntaxTreeTests");
|
||||
Directory.CreateDirectory(_tempPath);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
if (Directory.Exists(_tempPath))
|
||||
Directory.Delete(_tempPath, true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Partials_ClassMergeTest()
|
||||
{
|
||||
// Arrange
|
||||
const string partialClass1 = @"
|
||||
using System;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClass
|
||||
{
|
||||
private int _field1;
|
||||
public void Method1() { }
|
||||
}
|
||||
}";
|
||||
|
||||
const string partialClass2 = @"
|
||||
using System.Collections.Generic;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClass
|
||||
{
|
||||
private int _field2;
|
||||
public void Method2() { }
|
||||
}
|
||||
}";
|
||||
|
||||
yield return MergeAndTest_CSharpPartialClass(partialClass1, partialClass2);
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Partials_StructMergeTest()
|
||||
{
|
||||
// Arrange
|
||||
const string partialStruct1 = @"
|
||||
using System;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial struct TestStruct
|
||||
{
|
||||
private int _field1;
|
||||
public void Method1() { }
|
||||
}
|
||||
}";
|
||||
|
||||
const string partialStruct2 = @"
|
||||
using System.Collections.Generic;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial struct TestStruct
|
||||
{
|
||||
private int _field2;
|
||||
public void Method2() { }
|
||||
}
|
||||
}";
|
||||
|
||||
yield return MergeAndTest_CSharpPartialStruct(partialStruct1, partialStruct2);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Partials_MethodMergeTest()
|
||||
{
|
||||
// Arrange
|
||||
const string partialClass1 = @"
|
||||
using System;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClass
|
||||
{
|
||||
int _field1;
|
||||
partial void Method1() { }
|
||||
}
|
||||
}";
|
||||
|
||||
const string partialClass2 = @"
|
||||
using System.Collections.Generic;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClass
|
||||
{
|
||||
int _field2;
|
||||
partial void Method2() { }
|
||||
}
|
||||
}";
|
||||
|
||||
yield return MergeAndTest_CSharpPartialClass(partialClass1, partialClass2);
|
||||
}
|
||||
|
||||
private IEnumerator MergeAndTest_CSharpPartialClass(string partialClass1, string partialClass2)
|
||||
{
|
||||
var path1 = Path.Combine(_tempPath, "PartialClass1.cs");
|
||||
var path2 = Path.Combine(_tempPath, "PartialClass2.cs");
|
||||
File.WriteAllText(path1, partialClass1);
|
||||
File.WriteAllText(path2, partialClass2);
|
||||
|
||||
var tree1 = CSharpSyntaxTree.ParseText(partialClass1, path: path1);
|
||||
var tree2 = CSharpSyntaxTree.ParseText(partialClass2, path: path1);
|
||||
var trees = new List<SyntaxTree>
|
||||
{
|
||||
tree1, tree2
|
||||
};
|
||||
|
||||
var result = trees.MergePartials(new List<string>
|
||||
{
|
||||
"DEBUG", "UNITY_EDITOR"
|
||||
});
|
||||
|
||||
var combinedTree = result.First();
|
||||
var root = combinedTree.GetCompilationUnitRoot();
|
||||
|
||||
var classDeclaration = root.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax>().First();
|
||||
Assert.AreEqual("TestClass", classDeclaration.Identifier.Text, "Class name should be TestClass");
|
||||
|
||||
//Test Fields
|
||||
var fields = classDeclaration.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(2, fields.Count, "Combined class should have two fields");
|
||||
|
||||
//Test Methods
|
||||
var methods = classDeclaration.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(2, methods.Count, "Combined class should have two methods");
|
||||
Assert.IsTrue(methods.Any(m => m.Identifier.Text == "Method1"), "Combined class should contain Method1");
|
||||
Assert.IsTrue(methods.Any(m => m.Identifier.Text == "Method2"), "Combined class should contain Method2");
|
||||
|
||||
//Test Usings
|
||||
var usingDirectives = root.Usings;
|
||||
Assert.AreEqual(2, usingDirectives.Count, "Should have two using directives");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System"), "Should have using System");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System.Collections.Generic"), "Should have using System.Collections.Generic");
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private IEnumerator MergeAndTest_CSharpPartialStruct(string partialClass1, string partialClass2)
|
||||
{
|
||||
var path1 = Path.Combine(_tempPath, "PartialClass1.cs");
|
||||
var path2 = Path.Combine(_tempPath, "PartialClass2.cs");
|
||||
File.WriteAllText(path1, partialClass1);
|
||||
File.WriteAllText(path2, partialClass2);
|
||||
|
||||
var tree1 = CSharpSyntaxTree.ParseText(partialClass1, path: path1);
|
||||
var tree2 = CSharpSyntaxTree.ParseText(partialClass2, path: path1);
|
||||
var trees = new List<SyntaxTree>
|
||||
{
|
||||
tree1, tree2
|
||||
};
|
||||
|
||||
var result = trees.MergePartials(new List<string>
|
||||
{
|
||||
"DEBUG", "UNITY_EDITOR"
|
||||
});
|
||||
|
||||
var combinedTree = result.First();
|
||||
var root = combinedTree.GetCompilationUnitRoot();
|
||||
|
||||
var structDeclaration = root.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.StructDeclarationSyntax>().First();
|
||||
Assert.AreEqual("TestStruct", structDeclaration.Identifier.Text, "Struct name should be TestStruct");
|
||||
|
||||
//Test Fields
|
||||
var fields = structDeclaration.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(2, fields.Count, "Combined class should have two fields");
|
||||
|
||||
//Test Methods
|
||||
var methods = structDeclaration.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(2, methods.Count, "Combined class should have two methods");
|
||||
Assert.IsTrue(methods.Any(m => m.Identifier.Text == "Method1"), "Combined class should contain Method1");
|
||||
Assert.IsTrue(methods.Any(m => m.Identifier.Text == "Method2"), "Combined class should contain Method2");
|
||||
|
||||
//Test Usings
|
||||
var usingDirectives = root.Usings;
|
||||
Assert.AreEqual(2, usingDirectives.Count, "Should have two using directives");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System"), "Should have using System");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System.Collections.Generic"), "Should have using System.Collections.Generic");
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Partials_ClassWithFieldsMergeTest()
|
||||
{
|
||||
// Arrange
|
||||
const string partialClass1 = @"
|
||||
using System;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClassWithFields
|
||||
{
|
||||
public int Field1;
|
||||
private string _privateField1;
|
||||
protected float ProtectedField1;
|
||||
}
|
||||
}";
|
||||
|
||||
const string partialClass2 = @"
|
||||
using System.Collections.Generic;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClassWithFields
|
||||
{
|
||||
public List<int> Field2;
|
||||
private DateTime _privateField2;
|
||||
protected bool ProtectedField2;
|
||||
}
|
||||
}";
|
||||
|
||||
var path1 = Path.Combine(_tempPath, "PartialClassWithFields1.cs");
|
||||
var path2 = Path.Combine(_tempPath, "PartialClassWithFields2.cs");
|
||||
File.WriteAllText(path1, partialClass1);
|
||||
File.WriteAllText(path2, partialClass2);
|
||||
|
||||
var tree1 = CSharpSyntaxTree.ParseText(partialClass1, path: path1);
|
||||
var tree2 = CSharpSyntaxTree.ParseText(partialClass2, path: path2);
|
||||
var trees = new List<SyntaxTree>
|
||||
{
|
||||
tree1, tree2
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = trees.MergePartials(new List<string>
|
||||
{
|
||||
"DEBUG", "UNITY_EDITOR"
|
||||
});
|
||||
|
||||
// Assert
|
||||
var combinedTree = result.First();
|
||||
var root = combinedTree.GetCompilationUnitRoot();
|
||||
|
||||
var classDeclaration = root.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax>().First();
|
||||
Assert.AreEqual("TestClassWithFields", classDeclaration.Identifier.Text, "Class name should be TestClassWithFields");
|
||||
|
||||
// Test Fields
|
||||
var fields = classDeclaration.DescendantNodes().OfType<Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(6, fields.Count, "Combined class should have six fields");
|
||||
|
||||
// Test specific fields
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "Field1" && f.Modifiers.Any(m => m.IsKind(SyntaxKind.PublicKeyword)))), "Should have public Field1");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "_privateField1" && f.Modifiers.Any(m => m.IsKind(SyntaxKind.PrivateKeyword)))), "Should have private _privateField1");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "ProtectedField1" && f.Modifiers.Any(m => m.IsKind(SyntaxKind.ProtectedKeyword)))), "Should have protected ProtectedField1");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "Field2" && f.Modifiers.Any(m => m.IsKind(SyntaxKind.PublicKeyword)))), "Should have public Field2");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "_privateField2" && f.Modifiers.Any(m => m.IsKind(SyntaxKind.PrivateKeyword)))), "Should have private _privateField2");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "ProtectedField2" && f.Modifiers.Any(m => m.IsKind(SyntaxKind.ProtectedKeyword)))), "Should have protected ProtectedField2");
|
||||
|
||||
// Test Usings
|
||||
var usingDirectives = root.Usings;
|
||||
Assert.AreEqual(2, usingDirectives.Count, "Should have two using directives");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System"), "Should have using System");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System.Collections.Generic"), "Should have using System.Collections.Generic");
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Partials_SameFileMergeTest()
|
||||
{
|
||||
// Arrange
|
||||
const string sameFilePartials = @"
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace TestNamespace
|
||||
{
|
||||
public partial class TestClass
|
||||
{
|
||||
private int _field1;
|
||||
public void Method1() { }
|
||||
}
|
||||
|
||||
public partial class TestClass
|
||||
{
|
||||
private string _field2;
|
||||
public void Method2() { }
|
||||
}
|
||||
}";
|
||||
|
||||
var path = Path.Combine(_tempPath, "SameFilePartials.cs");
|
||||
File.WriteAllText(path, sameFilePartials);
|
||||
|
||||
var tree = CSharpSyntaxTree.ParseText(sameFilePartials, path: path);
|
||||
var trees = new List<SyntaxTree> { tree };
|
||||
|
||||
// Act
|
||||
var result = trees.MergePartials(new List<string> { "DEBUG", "UNITY_EDITOR" });
|
||||
|
||||
// Assert
|
||||
var combinedTree = result.First();
|
||||
var root = combinedTree.GetCompilationUnitRoot();
|
||||
|
||||
var classDeclaration = root.DescendantNodes().OfType<ClassDeclarationSyntax>().First();
|
||||
Assert.AreEqual("TestClass", classDeclaration.Identifier.Text, "Class name should be TestClass");
|
||||
|
||||
// Test Fields
|
||||
var fields = classDeclaration.DescendantNodes().OfType<FieldDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(2, fields.Count, "Combined class should have two fields");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "_field1")), "Should have _field1");
|
||||
Assert.IsTrue(fields.Any(f => f.Declaration.Variables.Any(v => v.Identifier.Text == "_field2")), "Should have _field2");
|
||||
|
||||
// Test Methods
|
||||
var methods = classDeclaration.DescendantNodes().OfType<MethodDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(2, methods.Count, "Combined class should have two methods");
|
||||
Assert.IsTrue(methods.Any(m => m.Identifier.Text == "Method1"), "Combined class should contain Method1");
|
||||
Assert.IsTrue(methods.Any(m => m.Identifier.Text == "Method2"), "Combined class should contain Method2");
|
||||
|
||||
// Test Usings
|
||||
var usingDirectives = root.Usings;
|
||||
Assert.AreEqual(2, usingDirectives.Count, "Should have two using directives");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System"), "Should have using System");
|
||||
Assert.IsTrue(usingDirectives.Any(u => u.Name.ToString() == "System.Collections.Generic"), "Should have using System.Collections.Generic");
|
||||
|
||||
// Test that there's only one class declaration
|
||||
var classDeclarations = root.DescendantNodes().OfType<ClassDeclarationSyntax>().ToList();
|
||||
Assert.AreEqual(1, classDeclarations.Count, "Should only have one class declaration after merging");
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80204021db1542d68285b24331058642
|
||||
timeCreated: 1719873041
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/Integration/CodePatterns/MergePartialClassesTest.cs
|
||||
uploadId: 710802
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using FastScriptReload.Tests.Runtime.Integration.CodePatterns;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace FastScriptReload.Tests.Editor.Integration.CodePatterns
|
||||
{
|
||||
public class MethodAccessingNestedEnumTest : CompileWithRedirectTestBase
|
||||
{
|
||||
[UnityTest]
|
||||
public IEnumerator AssignNestedEnumToField_ValueAssignedDirectly_CorrectValueOnOriginalInstance()
|
||||
{
|
||||
//TODO: nested enums were broken as code-adjustments were too wide, need to retarget just to enums
|
||||
|
||||
var instance = new GameObject("instance").AddComponent<MethodAccessingNestedEnum>();
|
||||
var originalValue = (int)instance.GetType().GetField("_value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(instance);
|
||||
|
||||
TestCompileAndDetour(ResolveFullTestFilePath(@"Runtime\Integration\CodePatterns\MethodAccessingNestedEnum.cs"), (compilationResult) =>
|
||||
{
|
||||
Debug.Log("After");
|
||||
instance.AssignNestedEnumToField();
|
||||
});
|
||||
|
||||
Assert.AreEqual(originalValue, 0);
|
||||
AssertDetourConfirmed(typeof(MethodAccessingNestedEnum), nameof(instance.AssignNestedEnumToField),
|
||||
(o) => 2 == (int)o,
|
||||
"Value should be set by detour"
|
||||
);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e69f17e8e2b34d0598177ddf52587260
|
||||
timeCreated: 1680876313
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/Integration/CodePatterns/MethodAccessingNestedEnumTest.cs
|
||||
uploadId: 710802
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using FastScriptReload.Tests.Runtime.Integration.CodePatterns;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace FastScriptReload.Tests.Editor.Integration.CodePatterns
|
||||
{
|
||||
public class NewFieldInitDictionariesWithLocalFunctionTest : CompileWithRedirectTestBase
|
||||
{
|
||||
private static readonly string RelativeFilePath = @$"Runtime\Integration\CodePatterns\{nameof(NewFieldInitDictionariesWithLocalFunction)}.cs";
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestStaticFieldAccess_StandardCompilation_CorrectRewriteCreated()
|
||||
{
|
||||
TestCompileAndDetour(ResolveFullTestFilePath(RelativeFilePath));
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42e6cb12e17b461bbfa6478abf5d240d
|
||||
timeCreated: 1697792138
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 239351
|
||||
packageName: Fast Script Reload
|
||||
packageVersion: 1.6.1
|
||||
assetPath: Assets/FastScriptReload/Tests/Editor/Integration/CodePatterns/NewFieldInitDictionariesWithLocalFunctionTest.cs
|
||||
uploadId: 710802
|
||||
Reference in new issue
Block a user