Skip to content

Commit

Permalink
Merge pull request #35 from nowsprinting/fix/assert_destroyed
Browse files Browse the repository at this point in the history
Fix assert destroyed object
  • Loading branch information
nowsprinting authored Feb 10, 2025
2 parents 309b2f1 + d6bd5e5 commit 358834e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions Assets/APIExamples/Tests/Runtime/NUnit/ConstraintExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -935,15 +935,33 @@ public void XmlSerializableConstraint_XMLシリアル化が可能であること
public class 破棄されたGameObject
{
[Test]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
// Note: プレイヤーではnull判定されるため除外
public void Boolキャストオペレーターで破棄されたGameObjectを検証する例()
{
var cube = new GameObject("Cube");
GameObject.DestroyImmediate(cube);
var go = new GameObject();
GameObject.DestroyImmediate(go);

Assert.That((bool)go, Is.False); // Note: GameObjectが破棄されているとき、boolキャストオペレーターはfalseを返す
}

[Test]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
public void IsNullで破棄されたGameObjectを検証する例_EditorではNotNull()
{
var go = new GameObject();
GameObject.DestroyImmediate(go);

Assume.That(go, Is.Not.Null); // Note: Editorでは破棄されていても参照はnullではない
}

[Test]
[UnityPlatform(exclude =
new[] { RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor })]
public void IsNullで破棄されたGameObjectを検証する例_PlayerではNull()
{
var go = new GameObject();
GameObject.DestroyImmediate(go);

Assume.That(cube, Is.Not.Null); // Note: 破棄されていても参照はnullではない
Assert.That((bool)cube, Is.False); // Note: GameObjectが破棄されているとき、boolキャストオペレーターはfalseを返す
Assume.That(go, Is.Null); // Note: Playerでは破棄されたObjectの参照はnull
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void CustomConstraint_Constraintの実装だけで可能な書きかた()

[Test]
[UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
// Note: プレイヤーではnull判定されるため除外
// Note: Playerでは破棄されたObjectの参照はnull判定されるため除外
public void CustomConstraint_Extensionsの実装も行なうと可能な書きかた()
{
var actual = CreateDestroyedObject();
Expand Down

0 comments on commit 358834e

Please # to comment.