Skip to content

Commit 00b37a5

Browse files
committed
Added a test to cover the package migration.
1 parent a260324 commit 00b37a5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Assets/Tests/InputSystem.Editor/CustomProcessorEnumTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,31 @@ public IEnumerator ProcessorEnum_ShouldSerializeByValue_WhenSerializedToAsset()
108108

109109
yield return null;
110110
}
111+
112+
[UnityTest]
113+
public IEnumerator Migration_FromLegacyJson_ShouldConvertOrdinal_KeepInvertVector2_AndSeparators()
114+
{
115+
var legacyJson = m_Asset.ToJson().Replace("\"version\": 1", "\"version\": 0").Replace("Custom(SomeEnum=10)", "Custom(SomeEnum=1)");
116+
117+
// Add a trailing processor to verify the semicolon separator is preserved.
118+
if (!legacyJson.Contains(";InvertVector2(invertX=true)"))
119+
legacyJson = legacyJson.Replace("Custom(SomeEnum=1)\"", "Custom(SomeEnum=1);InvertVector2(invertX=true)\"");
120+
121+
var migratedAsset = InputActionAsset.FromJson(legacyJson);
122+
Assume.That(migratedAsset, Is.Not.Null, "Failed to load legacy JSON into an InputActionAsset.");
123+
124+
var migratedJson = migratedAsset.ToJson();
125+
Assume.That(migratedJson, Is.Not.Null.And.Not.Empty, "Migrated JSON was empty.");
126+
127+
Assert.Less(migratedJson.IndexOf("InvertVector2(invertX=true)", StringComparison.Ordinal), migratedJson.IndexOf(",Custom(SomeEnum=20)", StringComparison.Ordinal),
128+
"Expected a comma between the first and second processors, with InvertVector2 first."
129+
);
130+
131+
Assert.Greater(migratedJson.IndexOf(";InvertVector2(invertX=true)", StringComparison.Ordinal), migratedJson.IndexOf("Custom(SomeEnum=20)", StringComparison.Ordinal),
132+
"Expected a semicolon between the second and third processors, with the trailing InvertVector2 last."
133+
);
134+
135+
yield return null;
136+
}
111137
}
112138
#endif

0 commit comments

Comments
 (0)