Skip to content

Commit a4c0215

Browse files
committed
update test
1 parent 0659e5f commit a4c0215

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

src/Libraries/CoreNodes/Data.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ public static object SafeExtractDictionaryValue(Dictionary<string, object> dict,
666666
public static Dictionary<string, object> EvaluateDefineDataNode([ArbitraryDimensionArrayImport] object inputValue,
667667
string typeString, bool isList, bool isAutoMode, string playerValue)
668668
{
669-
670669
if (inputValue == null && string.IsNullOrEmpty(playerValue))
671670
{
672671
// Don't raise a warning if the node is unused
@@ -677,6 +676,18 @@ public static Dictionary<string, object> EvaluateDefineDataNode([ArbitraryDimens
677676
};
678677
}
679678

679+
// Unconnected var[]..[] ports can receive an empty sequence default.
680+
if (string.IsNullOrEmpty(playerValue)
681+
&& inputValue is IEnumerable enumerable and not string
682+
&& !enumerable.Cast<object>().Any())
683+
{
684+
return new Dictionary<string, object>
685+
{
686+
{ ">", inputValue },
687+
{ "Validation", null }
688+
};
689+
}
690+
680691
// If the playerValue is not empty, then we assume it was set by the player.
681692
// In that case, we need to parse it to get the actual value replace the inputValue.
682693
if (!string.IsNullOrEmpty(playerValue))
@@ -694,6 +705,17 @@ public static Dictionary<string, object> EvaluateDefineDataNode([ArbitraryDimens
694705
}
695706
}
696707

708+
// A player value can deserialize to null (e.g. "null"), which should
709+
// follow the same behavior as an unused Define Data input.
710+
if (inputValue == null)
711+
{
712+
return new Dictionary<string, object>
713+
{
714+
{ ">", inputValue },
715+
{ "Validation", null }
716+
};
717+
}
718+
697719
if (!IsSingleValueOrSingleLevelArrayList(inputValue))
698720
{
699721
var warning = Properties.Resources.DefineDataSupportedInputValueExceptionMessage;
@@ -714,7 +736,16 @@ public static Dictionary<string, object> EvaluateDefineDataNode([ArbitraryDimens
714736
// Type logic - we try to 'guess' the type of the object
715737
if (type == null || !IsSupportedDataNodeDynamoType(inputValue, type.Type, assertList))
716738
{
717-
var valueType = assertList ? FindCommonAncestor(arrayList) : inputValue.GetType();
739+
var valueType = assertList ? FindCommonAncestor(arrayList) : inputValue?.GetType();
740+
if (!assertList && valueType == null)
741+
{
742+
// Defensive null-safe fallback for analyzers: no input means no validation result.
743+
return new Dictionary<string, object>
744+
{
745+
{ ">", inputValue },
746+
{ "Validation", null }
747+
};
748+
}
718749
if (valueType == null)
719750
{
720751
// We couldn't find a common ancestor - list containing unsupported or incompatible data types

test/DynamoCoreTests/DSCoreDataTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,17 @@ public void EvaluateDefineDataNodeReturnsNullWhenInputValueAndPlayerValueAreEmpt
920920
Assert.IsNull(result["Validation"]);
921921
}
922922

923+
[Test]
924+
[Category("UnitTests")]
925+
public void EvaluateDefineDataNodeReturnsNullWhenPlayerValueDeserializesToNull()
926+
{
927+
var booleanString = typeof(bool).ToString();
928+
var result = DSCore.Data.EvaluateDefineDataNode(null, booleanString, false, true, "null");
929+
930+
Assert.IsNull(result[">"]);
931+
Assert.IsNull(result["Validation"]);
932+
}
933+
923934
[Test]
924935
[Category("UnitTests")]
925936
public void ThrowsCorrectErrorTypes()

test/DynamoCoreTests/Nodes/DefineDataTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using CoreNodeModels;
4+
using Dynamo.Graph.Connectors;
45
using Dynamo.Graph.Nodes;
56
using NUnit.Framework;
67

@@ -92,7 +93,7 @@ public void WhenConnectedThenClearsMissingUpstreamConnectionInfo()
9293

9394
CurrentDynamoModel.NodeFactory.CreateNodeFromTypeName("CoreNodeModels.Input.DoubleInput", out NodeModel numberNode);
9495
CurrentDynamoModel.CurrentWorkspace.AddAndRegisterNode(numberNode, false);
95-
defineData.ConnectInput(0, 0, numberNode);
96+
ConnectorModel.Make(numberNode, defineData, 0, 0);
9697

9798
Assert.IsFalse(defineData.Infos.Any(x => x.State == ElementState.PersistentInfo));
9899
}

0 commit comments

Comments
 (0)