Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit b755ab1

Browse files
author
jerbri
committed
Added tests for SafeSubstring
Added tests to validate the index and length parameters of the underlying Substring.
1 parent b34f6e4 commit b755ab1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/ServiceStack.Text.Tests/StringExtensionsTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,26 @@ public void Can_ParseKeyValueText()
226226
Assert.That("a:b\nc:d".ParseKeyValueText()["c"], Is.EqualTo("d"));
227227
Assert.That("a:b\r\nc:d".ParseKeyValueText()["c"], Is.EqualTo("d"));
228228
}
229+
230+
[Test]
231+
public void Can_SafeSubstring_with_no_length {
232+
233+
var input = "TestString";
234+
Assert.That(input.SafeSubstring(0), Is.EqualTo("TestString"));
235+
Assert.That(input.SafeSubstring(2), Is.EqualTo("stString"));
236+
Assert.That(input.SafeSubstring(20), Is.EqualTo(""));
237+
}
238+
239+
[Test]
240+
public void Can_SafeSubstring_with_length {
241+
var input = "TestString";
242+
Assert.That(input.SafeSubstring(0,4), Is.EqualTo("Test"));
243+
Assert.That(input.SafeSubstring(2,4), Is.EqualTo("stSt"));
244+
Assert.That(input.SafeSubstring(20,4), Is.EqualTo(""));
245+
Assert.That(input.SafeSubstring(0,20), Is.EqualTo("TestString"));
246+
247+
}
248+
}
249+
}
229250
}
230-
}
251+
}

0 commit comments

Comments
 (0)