-
Notifications
You must be signed in to change notification settings - Fork 1
/
EchoObject_KeyIndex_Tracking_Tests.cs
110 lines (87 loc) · 2.79 KB
/
EchoObject_KeyIndex_Tracking_Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// This file is part of the Prowl Game Engine
// Licensed under the MIT License. See the LICENSE file in the project root for details.
namespace Prowl.Echo.Test;
public class EchoObject_KeyIndex_Tracking_Tests
{
[Fact]
public void ListIndex_IsNull_WhenNotInList()
{
var item = EchoObject.NewCompound();
Assert.Null(item.ListIndex);
}
[Fact]
public void ListIndex_IsSet_WhenAddedToList()
{
var list = EchoObject.NewList();
var item1 = new EchoObject("first");
var item2 = new EchoObject("second");
list.ListAdd(item1);
list.ListAdd(item2);
Assert.Equal(0, item1.ListIndex);
Assert.Equal(1, item2.ListIndex);
}
[Fact]
public void ListIndex_UpdatesOnRemoval()
{
var list = EchoObject.NewList();
var item1 = new EchoObject("first");
var item2 = new EchoObject("second");
var item3 = new EchoObject("third");
list.ListAdd(item1);
list.ListAdd(item2);
list.ListAdd(item3);
list.ListRemove(item1);
Assert.Null(item1.ListIndex); // Removed item
Assert.Equal(0, item2.ListIndex); // Should shift down
Assert.Equal(1, item3.ListIndex);
}
[Fact]
public void CompoundKey_IsNull_WhenNotInCompound()
{
var item = new EchoObject("test");
Assert.Null(item.CompoundKey);
}
[Fact]
public void CompoundKey_IsSet_WhenAddedToCompound()
{
var compound = EchoObject.NewCompound();
var item = new EchoObject("test");
compound["myKey"] = item;
Assert.Equal("myKey", item.CompoundKey);
}
[Fact]
public void CompoundKey_UpdatesOnRemoval()
{
var compound = EchoObject.NewCompound();
var item = new EchoObject("test");
compound["myKey"] = item;
Assert.Equal("myKey", item.CompoundKey);
compound.Remove("myKey");
Assert.Null(item.CompoundKey);
}
[Fact]
public void CompoundKey_UpdatesOnReassignment()
{
var compound = EchoObject.NewCompound();
var item = new EchoObject("test");
compound["key1"] = item;
Assert.Equal("key1", item.CompoundKey);
item.Parent.Remove(item.CompoundKey);
compound["key2"] = item; // Move to new key
Assert.Equal("key2", item.CompoundKey);
}
[Fact]
public void ListIndex_And_CompoundKey_AreExclusive()
{
var list = EchoObject.NewList();
var compound = EchoObject.NewCompound();
var item = new EchoObject("test");
list.ListAdd(item);
Assert.NotNull(item.ListIndex);
Assert.Null(item.CompoundKey);
list.ListRemove(item);
compound["key"] = item;
Assert.Null(item.ListIndex);
Assert.NotNull(item.CompoundKey);
}
}