public void FromStringTest() { string[] expectedSections = { "te", "st", " s", "tr", "in", "g" }; StringSections sections = StringSections.FromString("test string", 2); Assert.IsNotNull(sections); Assert.IsNotNull(sections.Sections); Assert.IsTrue(sections.Sections.Length == expectedSections.Length, $"Expected sections length \"{expectedSections.Length}\", got \"{sections.Sections.Length}\""); for (int i = 0; i < expectedSections.Length; i++) { string expected = expectedSections[i]; string result = sections.Sections[i].Text?.text; Assert.AreEqual(expected, result, $"Failed at section index {i}: Expected section text to be \"{expected ?? "null"}\", got \"{result ?? "null"}\""); } }
public void FromStringThrowsTest(string testString, int sectionLength, string leftIndictator = null, string rightIndictator = null) { Assert.Throws <ArgumentException>(() => { StringSections.FromString(testString, sectionLength, leftIndictator != null ? new ColoredMessage(leftIndictator) : null, rightIndictator != null ? new ColoredMessage(rightIndictator) : null); }); }
public void FromStringTest(string testString, string[] expectedSections, int sectionLength, string leftIndictator = null, string rightIndictator = null) { StringSections sections = StringSections.FromString(testString, sectionLength, leftIndictator != null ? new ColoredMessage(leftIndictator) : null, rightIndictator != null ? new ColoredMessage(rightIndictator) : null); Assert.NotNull(sections); Assert.NotNull(sections.Sections); Assert.Equal(expectedSections.Length, sections.Sections.Length); for (int i = 0; i < expectedSections.Length; i++) { string expected = expectedSections[i]; string result = sections.Sections[i].Section.GetText(); output.WriteLine($"Index {i} - Comparing \"{expected}\" to \"{result}\"..."); Assert.Equal(expected, result); } }
public void FromStringTest() { try { StringSections.FromString("test string", 2, new ColoredMessage("."), new ColoredMessage(".")); Assert.Fail("This case should not be allowed, no further characters can be output because of the prefix and suffix"); } catch (ArgumentException) { // Expected behaviour } FromStringTemplate[] sectionTests = { new FromStringTemplate("test string", new string[] { "te", "st", " s", "tr", "in", "g" }, 2), new FromStringTemplate("test string", new string[] { "tes..", ".t ..", ".st..", ".ring" },5, new ColoredMessage("."), new ColoredMessage("..")) }; for (int i = 0; i < sectionTests.Length; i++) { FromStringTemplate sectionTest = sectionTests[i]; StringSections sections = StringSections.FromString(sectionTest.testString, sectionTest.sectionLength, sectionTest.leftIndictator, sectionTest.rightIndictator); Assert.IsNotNull(sections); Assert.IsNotNull(sections.Sections); Assert.IsTrue(sections.Sections.Length == sectionTest.expectedSections.Length, $"Failed at index {i}: Expected sections length \"{sectionTest.expectedSections.Length}\", got \"{sections.Sections.Length}\""); for (int j = 0; j < sectionTest.expectedSections.Length; j++) { string expected = sectionTest.expectedSections[j]; string result = sections.Sections[j].Section.GetText(); Assert.AreEqual(expected, result, $"Failed at index {i}: Failed at section index {j}: Expected section text to be \"{expected ?? "null"}\", got \"{result ?? "null"}\""); } } }