Skip to content

Commit 829c4aa

Browse files
committed
Added test to cover the migration
1 parent ff05b1d commit 829c4aa

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Assets/Tests/InputSystem.Editor/CustomProcessorEnumTest.cs

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

109109
yield return null;
110110
}
111+
112+
[Test]
113+
public void Migration_ShouldProduceValidActionAsset_WithEnumProcessorConverted()
114+
{
115+
var legacyJson = @"
116+
{
117+
""name"": ""InputSystem_Actions"",
118+
""maps"": [
119+
{
120+
""name"": ""Player"",
121+
""id"": ""df70fa95-8a34-4494-b137-73ab6b9c7d37"",
122+
""actions"": [
123+
{
124+
""name"": ""Move"",
125+
""type"": ""Value"",
126+
""id"": ""351f2ccd-1f9f-44bf-9bec-d62ac5c5f408"",
127+
""expectedControlType"": ""Vector2"",
128+
""processors"": ""StickDeadzone,InvertVector2(invertX=false),Custom(SomeEnum=1)"",
129+
""interactions"": """",
130+
""initialStateCheck"": true
131+
}
132+
]
133+
}
134+
],
135+
""controlSchemes"": [],
136+
""version"": 0
137+
}";
138+
139+
// Parse and migrate the legacy JSON
140+
var asset = InputActionAsset.FromJson(legacyJson);
141+
142+
// Object is valid after migration
143+
Assert.That(asset, Is.Not.Null, "Migration failed to produce a valid InputActionAsset.");
144+
145+
var map = asset.FindActionMap("Player");
146+
Assert.That(map, Is.Not.Null, "Expected Player map to exist.");
147+
148+
var action = map.FindAction("Move");
149+
Assert.That(action, Is.Not.Null, "Expected Move action to exist.");
150+
151+
var processors = action.processors;
152+
153+
// Verify processor order and that enum was converted properly
154+
Assert.That(processors, Does.Contain("StickDeadzone"), "StickDeadzone processor missing.");
155+
Assert.That(processors, Does.Contain("InvertVector2(invertX=false)"), "InvertVector2 missing.");
156+
Assert.That(processors, Does.Contain("Custom(SomeEnum=20)"), "Custom(SomeEnum=1) should migrate to SomeEnum=20 (OptionB).");
157+
158+
// Verify To JSON
159+
var toJson = asset.ToJson();
160+
var reloaded = InputActionAsset.FromJson(toJson);
161+
Assert.That(reloaded, Is.Not.Null, "Reloaded asset after migration is null.");
162+
Assert.That(reloaded.FindAction("Player/Move"), Is.Not.Null, "Reloaded asset did not contain expected Move action.");
163+
}
111164
}
112165
#endif

0 commit comments

Comments
 (0)