Skip to content

Commit 0a94831

Browse files
authored
Merge pull request #80 from BDisp/ustring-equal-not-equal-tests
Fixes #79. Needed to add unit test for equal and not equal operators.
2 parents 3b3f408 + d1bf26c commit 0a94831

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

NStack/strings/ustring.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,9 +2230,7 @@ public ustring Replace (ustring oldValue, ustring newValue, int maxReplacements
22302230
/// <returns></returns>
22312231
public static bool IsNullOrEmpty (ustring value)
22322232
{
2233-
if (value == null)
2234-
return true;
2235-
if (value.Length == 0)
2233+
if (value?.IsEmpty != false)
22362234
return true;
22372235
return false;
22382236
}

NStackTests/ustringTest.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,5 +821,71 @@ public void IsNullOrEmpty_Accept_Null_Ustring_Arg ()
821821
Assert.False (string.IsNullOrEmpty (ustr.ToString ()));
822822
Assert.False (ustring.IsNullOrEmpty (ustr));
823823
}
824+
825+
[Test]
826+
public void Operator_Equal_Ustring_Versus_String ()
827+
{
828+
ustring? ustr = null;
829+
string? str = null;
830+
Assert.True (ustr == str);
831+
Assert.True (str == ustr);
832+
Assert.True (ustr == null);
833+
Assert.True (str == null);
834+
Assert.False (ustr == "");
835+
Assert.False (str == "");
836+
837+
ustr = "";
838+
str = "";
839+
Assert.True (ustr == str);
840+
Assert.True (str == ustr);
841+
Assert.False (ustr == null);
842+
Assert.False (str == null);
843+
Assert.True (ustr == "");
844+
Assert.True (str == "");
845+
846+
ustr = " ";
847+
str = " ";
848+
Assert.True (ustr == str);
849+
Assert.True (str == ustr);
850+
Assert.False (ustr == null);
851+
Assert.False (str == null);
852+
Assert.False (ustr == "");
853+
Assert.False (str == "");
854+
Assert.True (ustr == " ");
855+
Assert.True (str == " ");
856+
}
857+
858+
[Test]
859+
public void Operator_Not_Equal_Ustring_Versus_String ()
860+
{
861+
ustring? ustr = null;
862+
string? str = null;
863+
Assert.False (ustr != str);
864+
Assert.False (str != ustr);
865+
Assert.False (ustr != null);
866+
Assert.False (str != null);
867+
Assert.True (ustr != "");
868+
Assert.True (str != "");
869+
870+
ustr = "";
871+
str = "";
872+
Assert.False (ustr != str);
873+
Assert.False (str != ustr);
874+
Assert.True (ustr != null);
875+
Assert.True (str != null);
876+
Assert.False (ustr != "");
877+
Assert.False (str != "");
878+
879+
ustr = " ";
880+
str = " ";
881+
Assert.False (ustr != str);
882+
Assert.False (str != ustr);
883+
Assert.True (ustr != null);
884+
Assert.True (str != null);
885+
Assert.True (ustr != "");
886+
Assert.True (str != "");
887+
Assert.False (ustr != " ");
888+
Assert.False (str != " ");
889+
}
824890
}
825891
}

0 commit comments

Comments
 (0)