diff --git a/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceE2ETests.cs b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceE2ETests.cs
new file mode 100644
index 000000000..3d7204a51
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceE2ETests.cs
@@ -0,0 +1,282 @@
+using System;
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+
+using NUnit.Framework;
+
+using UnityEngine;
+
+using io.github.hatayama.UnityCliLoop.FirstPartyTools;
+using io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload.@event;
+
+namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload
+{
+ ///
+ /// End-to-end coverage for hot reload of types declared in a namespace with a keyword-named
+ /// segment (@event): a method body, a property getter, a call to an added method and a nested
+ /// type's method are all patched, and RevertAll restores the compiled values.
+ ///
+ public class HotReloadKeywordNamespaceE2ETests
+ {
+ private const string FixtureFileName = "HotReloadKeywordNamespaceFixtures.cs";
+
+ private const string AddedMethodAnchor = " public int CallsAddedMethod()";
+
+ private const string AddedMethodSource =
+ " private int AddedKeywordNamespaceValue()\n"
+ + " {\n"
+ + " return 35998;\n"
+ + " }\n\n";
+
+ private HotReloadDomainTestScope _scope;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _scope = new HotReloadDomainTestScope();
+ HotReloadAutoRefreshHold.SyncToActiveChanges();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ _scope.Dispose();
+ HotReloadAutoRefreshHold.SyncToActiveChanges();
+ }
+
+ ///
+ /// What: an edited method body of a type in a keyword-named namespace is Patched and returns
+ /// the edited value; RevertAll restores the compiled value.
+ ///
+ [Test]
+ public async Task Run_MethodOfTypeInKeywordNamedNamespace_IsPatchedAndReverts()
+ {
+ HotReloadKeywordNamespaceHost host = new HotReloadKeywordNamespaceHost();
+ Assert.That(host.MethodValue(), Is.EqualTo(35990));
+
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace("return 35990;", "return 35991;"));
+
+ AssertKind(result, "MethodValue", HotReloadMethodOutcomeKind.Patched);
+ Assert.That(host.MethodValue(), Is.EqualTo(35991));
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(host.MethodValue(), Is.EqualTo(35990));
+ }
+
+ ///
+ /// What: an edited property getter of a type in a keyword-named namespace is Patched and
+ /// returns the edited value, so the getter shim declared in that namespace compiles.
+ ///
+ [Test]
+ public async Task Run_PropertyGetterOfTypeInKeywordNamedNamespace_IsPatched()
+ {
+ HotReloadKeywordNamespaceHost host = new HotReloadKeywordNamespaceHost();
+ Assert.That(host.GetterValue, Is.EqualTo(35993));
+
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace("return 35993;", "return 35994;"));
+
+ AssertKind(result, "get_GetterValue", HotReloadMethodOutcomeKind.Patched);
+ Assert.That(host.GetterValue, Is.EqualTo(35994));
+ }
+
+ ///
+ /// What: a method of a type in a keyword-named namespace that now calls a method this reload
+ /// adds is Patched and returns what the added method computes, so the call the rewrite
+ /// qualifies with the shim's namespace compiles.
+ ///
+ [Test]
+ public async Task Run_CallToAddedMethodOfTypeInKeywordNamedNamespace_IsPatched()
+ {
+ HotReloadKeywordNamespaceHost host = new HotReloadKeywordNamespaceHost();
+ Assert.That(host.CallsAddedMethod(), Is.EqualTo(35996));
+
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk
+ .Replace(AddedMethodAnchor, AddedMethodSource + AddedMethodAnchor)
+ .Replace("return 35996;", "return AddedKeywordNamespaceValue();"));
+
+ AssertKind(result, "CallsAddedMethod", HotReloadMethodOutcomeKind.Patched);
+ Assert.That(host.CallsAddedMethod(), Is.EqualTo(35998));
+ }
+
+ ///
+ /// What: an edited method body of a type nested in a type of a keyword-named namespace is
+ /// Patched and returns the edited value; RevertAll restores the compiled value.
+ ///
+ [Test]
+ public async Task Run_MethodOfNestedTypeInKeywordNamedNamespace_IsPatchedAndReverts()
+ {
+ HotReloadKeywordNamespaceHost.Nested nested = new HotReloadKeywordNamespaceHost.Nested();
+ Assert.That(nested.NestedValue(), Is.EqualTo(35999));
+
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace("return 35999;", "return 36000;"));
+
+ AssertKind(result, "NestedValue", HotReloadMethodOutcomeKind.Patched);
+ Assert.That(nested.NestedValue(), Is.EqualTo(36000));
+ HotReloadCompositionRoot.Services.Patcher.RevertAll();
+ Assert.That(nested.NestedValue(), Is.EqualTo(35999));
+ }
+
+ ///
+ /// What: a changed const of a type in a keyword-named namespace produces the const drift
+ /// warning naming that const, so the compiled type is found by its metadata name.
+ ///
+ [Test]
+ public async Task Run_ConstChangedInTypeOfKeywordNamedNamespace_WarnsAboutTheDrift()
+ {
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace("KeywordTuning = 4;", "KeywordTuning = 6;"));
+
+ Assert.That(
+ FindWarningContaining(result, "KeywordTuning"),
+ Does.Contain("is 6 in the edited source but 4 in the compiled assembly"),
+ string.Join("\n", result.Warnings));
+ }
+
+ ///
+ /// What: removing a compiled property of a type in a keyword-named namespace produces the
+ /// kind-change warning naming that property, and no outside-method-body drift warning,
+ /// because the removed declaration is matched to the kind-change key and left out of the
+ /// drift comparison.
+ ///
+ [Test]
+ public async Task Run_PropertyRemovedFromTypeOfKeywordNamedNamespace_WarnsAboutTheKindChangeOnly()
+ {
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace(" public int KindChangeValue => 36002;\n", string.Empty));
+
+ Assert.That(
+ FindWarningContaining(result, "KindChangeValue"),
+ Does.StartWith("Compiled property '"),
+ string.Join("\n", result.Warnings));
+ AssertNoOutsideMethodBodyDriftWarning(result);
+ }
+
+ ///
+ /// What: removing a compiled property of a keyword-named type (@class) in a keyword-named
+ /// namespace produces the kind-change warning naming that property and no
+ /// outside-method-body drift warning.
+ ///
+ [Test]
+ public async Task Run_PropertyRemovedFromKeywordNamedType_WarnsAboutTheKindChangeOnly()
+ {
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace(" public int ClassKindChangeValue => 36005;\n", string.Empty));
+
+ Assert.That(
+ FindWarningContaining(result, "ClassKindChangeValue"),
+ Does.StartWith("Compiled property '"),
+ string.Join("\n", result.Warnings));
+ AssertNoOutsideMethodBodyDriftWarning(result);
+ }
+
+ ///
+ /// What: removing a compiled keyword-named property (@checked) produces the kind-change
+ /// warning naming it and no outside-method-body drift warning.
+ ///
+ [Test]
+ public async Task Run_KeywordNamedPropertyRemoved_WarnsAboutTheKindChangeOnly()
+ {
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk.Replace(" public int @checked => 36007;\n", string.Empty));
+
+ Assert.That(
+ FindWarningContaining(result, ".checked'"),
+ Does.StartWith("Compiled property '"),
+ string.Join("\n", result.Warnings));
+ AssertNoOutsideMethodBodyDriftWarning(result);
+ }
+
+ ///
+ /// What: a keyword-named field (@event) that the edit adds and a method now reads is Patched
+ /// with the field's initial value, and raises no outside-method-body drift warning.
+ ///
+ [Test]
+ public async Task Run_KeywordNamedFieldAdded_IsPatchedWithoutDriftWarning()
+ {
+ HotReloadKeywordNamespaceHost host = new HotReloadKeywordNamespaceHost();
+ Assert.That(host.ReadsAddedField(), Is.EqualTo(36008));
+
+ HotReloadOrchestratorResult result = await RunEditAsync(
+ onDisk => onDisk
+ .Replace(
+ " public int ReadsAddedField()",
+ " private int @event = 36009;\n\n public int ReadsAddedField()")
+ .Replace("return 36008;", "return @event;"));
+
+ AssertKind(result, "ReadsAddedField", HotReloadMethodOutcomeKind.Patched);
+ Assert.That(host.ReadsAddedField(), Is.EqualTo(36009));
+ AssertNoOutsideMethodBodyDriftWarning(result);
+ }
+
+ private static void AssertNoOutsideMethodBodyDriftWarning(HotReloadOrchestratorResult result)
+ {
+ foreach (string warning in result.Warnings)
+ {
+ Assert.That(
+ warning,
+ Does.Not.StartWith("Edits outside method bodies"),
+ string.Join("\n", result.Warnings));
+ }
+ }
+
+ private static string FindWarningContaining(HotReloadOrchestratorResult result, string fragment)
+ {
+ foreach (string warning in result.Warnings)
+ {
+ if (warning.Contains(fragment))
+ {
+ return warning;
+ }
+ }
+
+ Assert.Fail("No warning names " + fragment + ".\n" + string.Join("\n", result.Warnings));
+ return null;
+ }
+
+ private static async Task RunEditAsync(Func edit)
+ {
+ string fixturePath = Path.GetFullPath(
+ Path.Combine(Application.dataPath, "Tests", "Editor", "HotReload", FixtureFileName));
+ string onDisk = File.ReadAllText(fixturePath);
+ string edited = edit(onDisk);
+ Assert.That(edited, Is.Not.EqualTo(onDisk), "Precondition: the edit must change the fixture.");
+ string editedPath = HotReloadTestSourceWriter.WriteEditedSource("KeywordNamespaceE2E.cs", edited);
+ return await HotReloadCompositionRoot.Services.Orchestrator.RunAsync(
+ new[] { fixturePath },
+ editedPath,
+ CancellationToken.None);
+ }
+
+ private static void AssertKind(
+ HotReloadOrchestratorResult result,
+ string methodName,
+ HotReloadMethodOutcomeKind expectedKind)
+ {
+ foreach (HotReloadMethodOutcome outcome in result.Methods)
+ {
+ if (outcome.Method.Contains("." + methodName + "("))
+ {
+ Assert.That(outcome.Kind, Is.EqualTo(expectedKind), outcome.Method + ": " + outcome.Reason);
+ return;
+ }
+ }
+
+ Assert.Fail("No row for " + methodName + ". Rows: " + DescribeRows(result));
+ }
+
+ private static string DescribeRows(HotReloadOrchestratorResult result)
+ {
+ string rows = string.Empty;
+ foreach (HotReloadMethodOutcome outcome in result.Methods)
+ {
+ rows += outcome.Method + " = " + outcome.Kind + " (" + outcome.Reason + "); ";
+ }
+
+ return rows;
+ }
+ }
+}
diff --git a/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceE2ETests.cs.meta b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceE2ETests.cs.meta
new file mode 100644
index 000000000..2b2c7f50a
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceE2ETests.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 29e1f6c248584468c9b31e8534b8222c
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceFixtures.cs b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceFixtures.cs
new file mode 100644
index 000000000..49e5ea7fd
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceFixtures.cs
@@ -0,0 +1,64 @@
+namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload.@event
+{
+ ///
+ /// Host types declared in a namespace whose last segment is a C# keyword. Tests edit their
+ /// bodies to check that hot reload patches them: the escaped spelling (@event) appears only in
+ /// source, while the compiled metadata names the namespace "event".
+ ///
+ public sealed class HotReloadKeywordNamespaceHost
+ {
+ public const int KeywordTuning = 4;
+
+ public int MethodValue()
+ {
+ return 35990;
+ }
+
+ public int GetterValue
+ {
+ get
+ {
+ return 35993;
+ }
+ }
+
+ public int CallsAddedMethod()
+ {
+ return 35996;
+ }
+
+ public int CallsIntroducedType()
+ {
+ return 36001;
+ }
+
+ public int KindChangeValue => 36002;
+
+ public int @checked => 36007;
+
+ public int ReadsAddedField()
+ {
+ return 36008;
+ }
+
+ ///
+ /// Nested host, so the conversion of a nested type name in that namespace is covered too.
+ ///
+ public sealed class Nested
+ {
+ public int NestedValue()
+ {
+ return 35999;
+ }
+ }
+ }
+
+ ///
+ /// Host whose own name is a C# keyword, so a key built from its identifier must drop the @
+ /// as well as the namespace's.
+ ///
+ public sealed class @class
+ {
+ public int ClassKindChangeValue => 36005;
+ }
+}
diff --git a/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceFixtures.cs.meta b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceFixtures.cs.meta
new file mode 100644
index 000000000..04e6a79d2
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceFixtures.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6700df0513cd94d51848148484f7d12d
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceIntroducedTypeE2ETests.cs b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceIntroducedTypeE2ETests.cs
new file mode 100644
index 000000000..568661e3a
--- /dev/null
+++ b/Assets/Tests/Editor/HotReload/HotReloadKeywordNamespaceIntroducedTypeE2ETests.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using System.Threading;
+using System.Threading.Tasks;
+
+using NUnit.Framework;
+
+using io.github.hatayama.UnityCliLoop.FirstPartyTools;
+
+namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload
+{
+ ///
+ /// End-to-end coverage of a type an earlier reload introduced into a namespace with a
+ /// keyword-named segment (@event): a later body-only edit is patched on the retained artifact,
+ /// which is found by the type's metadata name.
+ ///
+ public class HotReloadKeywordNamespaceIntroducedTypeE2ETests : HotReloadIntroducedTypeE2ETestBase
+ {
+ private const string FixtureFileName = "HotReloadKeywordNamespaceFixtures.cs";
+ private const string HostTypeAnchor = " public sealed class HotReloadKeywordNamespaceHost";
+ private const string CallerBody = "return 36001;";
+ private const string IntroducedTypeSimpleName = "HotReloadKeywordNamespaceIntroduced";
+
+ // Why "event" without the escape: this is the name the compiled metadata carries.
+ private const string IntroducedTypeMetadataName =
+ "io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload.event." + IntroducedTypeSimpleName;
+
+ ///
+ /// What: editing only the body of a type that an earlier reload introduced into a
+ /// keyword-named namespace patches it on the retained artifact without failures, and a call
+ /// into the artifact runs the edited body.
+ ///
+ [Test]
+ public async Task Run_IntroducedTypeInKeywordNamedNamespaceBodyEdited_PatchesTheRetainedArtifact()
+ {
+ string fixturePath = FixturePath(FixtureFileName);
+
+ await RunInIntroducedTypeDomainAsync(async readArtifact =>
+ {
+ HotReloadOrchestratorResult first = await RunAsync(
+ fixturePath,
+ "KeywordNamespaceIntroducing.cs",
+ "36003");
+ Assert.That(CountFailures(first), Is.EqualTo(0), DescribeOutcomes(first));
+ Assert.That(ReadComputedValue(readArtifact()), Is.EqualTo(36003));
+
+ HotReloadOrchestratorResult second = await RunAsync(
+ fixturePath,
+ "KeywordNamespaceIntroducedBodyEdited.cs",
+ "36004");
+
+ Assert.That(CountFailures(second), Is.EqualTo(0), DescribeOutcomes(second));
+ Assert.That(
+ HasPatchedCompute(second),
+ Is.True,
+ "The edited body of the introduced type must be reported as patched.\n" + DescribeOutcomes(second));
+ Assert.That(ReadComputedValue(readArtifact()), Is.EqualTo(36004));
+ });
+ }
+
+ private static Task RunAsync(
+ string fixturePath,
+ string editedFileName,
+ string computedValue)
+ {
+ string onDisk = File.ReadAllText(fixturePath);
+ Assert.That(onDisk, Does.Contain(HostTypeAnchor), "Precondition: host type anchor must exist.");
+ Assert.That(onDisk, Does.Contain(CallerBody), "Precondition: caller body must exist.");
+ string introduced =
+ " public sealed class " + IntroducedTypeSimpleName + "\n"
+ + " {\n"
+ + " [System.Runtime.CompilerServices.MethodImpl(\n"
+ + " System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]\n"
+ + " public int Compute()\n"
+ + " {\n"
+ + " return " + computedValue + ";\n"
+ + " }\n"
+ + " }\n"
+ + "\n";
+ string edited = onDisk
+ .Replace(HostTypeAnchor, introduced + HostTypeAnchor, StringComparison.Ordinal)
+ .Replace(
+ CallerBody,
+ "return new " + IntroducedTypeSimpleName + "().Compute();",
+ StringComparison.Ordinal);
+ return HotReloadCompositionRoot.Services.Orchestrator.RunAsync(
+ new[] { fixturePath },
+ contentPathOverride: null,
+ CancellationToken.None,
+ new Dictionary
+ {
+ [fixturePath] = HotReloadTestSourceWriter.WriteEditedSource(editedFileName, edited)
+ });
+ }
+
+ private static bool HasPatchedCompute(HotReloadOrchestratorResult result)
+ {
+ foreach (HotReloadMethodOutcome outcome in result.Methods)
+ {
+ if (outcome.Kind == HotReloadMethodOutcomeKind.Patched
+ && outcome.Method != null
+ && outcome.Method.Contains("." + IntroducedTypeSimpleName + ".Compute()", StringComparison.Ordinal))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private static int ReadComputedValue(HotReloadIntroducedTypeArtifact artifact)
+ {
+ Assert.That(artifact, Is.Not.Null, "A reload had to introduce the type before this check.");
+ Type introducedType = artifact.Assembly.GetType(IntroducedTypeMetadataName, throwOnError: false);
+ Assert.That(introducedType, Is.Not.Null, "The artifact must hold " + IntroducedTypeMetadataName + ".");
+ MethodInfo compute = introducedType.GetMethod("Compute", BindingFlags.Instance | BindingFlags.Public);
+ return (int)compute.Invoke(Activator.CreateInstance(introducedType), Array.Empty