public static void Ctor_CreateRelaxed_FromDelegate() { object expectedState = new object(); SpanAction <byte, object> spanAction = (span, actualState) => { Assert.Same(expectedState, actualState); Assert.NotEqual(0, span.Length); // shouldn't have been called for a zero-length span for (int i = 0; i < span.Length; i++) { Assert.Equal(0, span[i]); // should've been zero-inited span[i] = 0xFF; // never a valid UTF-8 byte } }; ArgumentException exception = Assert.Throws <ArgumentOutOfRangeException>(() => Utf8String.CreateRelaxed(-1, expectedState, spanAction)); Assert.Equal("length", exception.ParamName); exception = Assert.Throws <ArgumentNullException>(() => Utf8String.CreateRelaxed(10, expectedState, action: null)); Assert.Equal("action", exception.ParamName); Assert.Same(Utf8String.Empty, Utf8String.CreateRelaxed(0, expectedState, spanAction)); Assert.Equal(u8("\uFFFD\uFFFD"), Utf8String.CreateRelaxed(2, expectedState, spanAction)); }