public static void GetString_Encoding_ReadOnlySequence() { // First try the single-segment code path. ReadOnlySequence <byte> sequence = new ReadOnlySequence <byte>(Encoding.UTF8.GetBytes("Hello!")); Assert.Equal("Hello!", EncodingExtensions.GetString(Encoding.UTF8, sequence)); // Next try the multi-segment code path. // We've intentionally split multi-byte subsequences here to test flushing mechanisms. sequence = SequenceFactory.Create( new byte[] { 0x20 }, // U+0020 new byte[] { 0x61, 0xC2 }, // U+0061 and U+0080 (continues on next line) new byte[] { 0x80, 0xED }, // (cont.) + U+D7FF (continues on next line) new byte[] { }, // empty segment, just to make sure we handle it correctly new byte[] { 0x9F, 0xBF, 0xF4, 0x80 }, // (cont.) + U+100000 (continues on next line) new byte[] { 0x80, 0x80 }, // (cont.) new byte[] { 0xC2 }); // leftover data (should be replaced) Assert.Equal("\u0020\u0061\u0080\ud7ff\U00100000\ufffd", EncodingExtensions.GetString(Encoding.UTF8, sequence)); }
public static void GetString_Encoding_ReadOnlySequence_ParamChecks() { ReadOnlySequence <byte> sequence = new ReadOnlySequence <byte>(new byte[0]); Assert.Throws <ArgumentNullException>("encoding", () => EncodingExtensions.GetString(null, sequence)); }