mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Core - Fix removing dynamic children and checking which properties are in use
- DataModel.RemoveDynamicChild compared the value of each child with the child that was passed in, so it never removed anything. - IsPropertyInUse with includeChildren matched paths by their start, so a path to "Integers" made "Integer" count as in use. Children are now matched on what follows a dot.
This commit is contained in:
1 parent
504845c7d2
commit
bbaf21c25f
2 files changed
+11
-12
No files matched your search
@@ -184,7 +184,7 @@ public class DataModelTests : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RemovingADynamicChild_DoesNotRemoveIt()
|
public void RemovingADynamicChild_RemovesIt()
|
||||||
{
|
{
|
||||||
DynamicChild<int> child = DataModel.AddDynamicChild("Extra", 5);
|
DynamicChild<int> child = DataModel.AddDynamicChild("Extra", 5);
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
@@ -192,11 +192,8 @@ public class DataModelTests : IDisposable
|
|||||||
|
|
||||||
DataModel.RemoveDynamicChild(child);
|
DataModel.RemoveDynamicChild(child);
|
||||||
|
|
||||||
// Pinned as-is: RemoveDynamicChild compares the value of each child (BaseValue) with the child that was passed in,
|
DataModel.DynamicChildren.ShouldNotContainKey("Extra");
|
||||||
// rather than the child itself, so it only removes a child whose value is the child object. Looks like it should
|
removed.ShouldBe(1);
|
||||||
// compare the children themselves; RemoveDynamicChildByKey works.
|
|
||||||
DataModel.DynamicChildren.ShouldContainKey("Extra");
|
|
||||||
removed.ShouldBe(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -304,14 +301,14 @@ public class DataModelTests : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IncludingChildren_AlsoMatchesPropertiesThatStartWithTheSameName()
|
public void IncludingChildren_DoesNotMatchPropertiesThatStartWithTheSameName()
|
||||||
{
|
{
|
||||||
using DataModelPath path = new(DataModel, "Integers");
|
using DataModelPath path = new(DataModel, "Integers");
|
||||||
|
|
||||||
// Pinned as-is: children are matched by checking whether a path starts with the given text, so "Integer" counts as
|
// Integers is a different property than Integer, not a child of it
|
||||||
// in use because of a path to "Integers", a different property. Looks like it should check for "Integer."
|
_module.IsPropertyInUse("Integer", true).ShouldBeFalse();
|
||||||
_module.IsPropertyInUse("Integer", true).ShouldBeTrue();
|
|
||||||
_module.IsPropertyInUse("Integer", false).ShouldBeFalse();
|
_module.IsPropertyInUse("Integer", false).ShouldBeFalse();
|
||||||
|
_module.IsPropertyInUse("Integers", true).ShouldBeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ public abstract class DataModel
|
|||||||
public void RemoveDynamicChild(DynamicChild dynamicChild)
|
public void RemoveDynamicChild(DynamicChild dynamicChild)
|
||||||
{
|
{
|
||||||
if (dynamicChild == null) throw new ArgumentNullException(nameof(dynamicChild));
|
if (dynamicChild == null) throw new ArgumentNullException(nameof(dynamicChild));
|
||||||
List<string> keys = _dynamicChildren.Where(kvp => kvp.Value.BaseValue == dynamicChild).Select(kvp => kvp.Key).ToList();
|
List<string> keys = _dynamicChildren.Where(kvp => kvp.Value == dynamicChild).Select(kvp => kvp.Key).ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
_dynamicChildren.Remove(key);
|
_dynamicChildren.Remove(key);
|
||||||
@@ -335,8 +335,10 @@ public abstract class DataModel
|
|||||||
{
|
{
|
||||||
lock (_activePaths)
|
lock (_activePaths)
|
||||||
{
|
{
|
||||||
|
// A child's path continues after a dot, matching on the text alone would also match a property that merely starts
|
||||||
|
// with the same name (Integer and Integers)
|
||||||
return includeChildren
|
return includeChildren
|
||||||
? _activePathsHashSet.Any(p => p.StartsWith(path, PathsStringComparison))
|
? _activePathsHashSet.Any(p => string.Equals(p, path, PathsStringComparison) || p.StartsWith(path + ".", PathsStringComparison))
|
||||||
: _activePathsHashSet.Contains(path);
|
: _activePathsHashSet.Contains(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user