public void virtual_string_out_of_range_issue_7() { using (Stream stream = new StupidStream()) { var v = new VirtualString(stream, 0, 256); { // Reproduces: https://github.com/Invenietis/CK-Text/issues/7 v.GetText(6810, 1).Should().Be(StupidStream.CharAt(6810).ToString()); v.Invoking(_ => _.GetText(7042, 24)).Should().NotThrow(); } // Since we are here, a little systematic stress test: for (int start = 0; start < 300; ++start) { for (int width = 2; width < 300; ++width) { v.Invoking(_ => _.GetText(start, width)).Should().NotThrow(); } } } }
public void virtual_string_does_not_support_multibyte_characters() { Assume.That(false, "VirtualString does not support multi-byte characters."); var encoding = new UTF8Encoding(false); // i = 0 to 25: Single-byte // i = 26 and 27: Multi-byte // i = 28 to 53: Single-byte string testStr = @"ABCDEFGHIJKLMNOPQRSTUVWXYZüABCDEFGHIJKLMNOPQRSTUVWXYZ"; byte[] utf8bytes = encoding.GetBytes(testStr); using (MemoryStream ms = new MemoryStream()) { ms.Write(utf8bytes); ms.Position = 0; var v = new VirtualString(ms, 0, 256, encoding); { v.Invoking(_ => _.GetText(0, utf8bytes.Length)).Should().NotThrow(); // ArgumentOutOfRangeException } } }