IronRuby.Tests.Tests.MutableString_Append C# (CSharp) Method

MutableString_Append() private method

private MutableString_Append ( ) : void
return void
        public void MutableString_Append() {
            MutableString x, y;
            
            // Appending Unicode string literal to a string doesn't check correctness of the resulting string.
            // An exception is thrown during subssequent operation that needs to convert the content.
            x = MS(((char)250).ToString(), RubyEncoding.Binary);
            x.Append('α');
            AssertExceptionThrown<EncoderFallbackException>(() => x.ToByteArray());

            // invalid bytes + valid string -> invalid bytes, but not an error:
            var invalid_utf8 = new byte[] { 0xe2, 0x85, 0x9c, 0xef };
            var valid_utf8 = Encoding.UTF8.GetBytes("α");

            x = MS(invalid_utf8, RubyEncoding.UTF8);
            y = MS("α", RubyEncoding.UTF8);
            Assert(x.Append(y).ToByteArray().ValueEquals(Utils.Concatenate(invalid_utf8, valid_utf8)));

            x = MS(invalid_utf8, RubyEncoding.UTF8);
            y = MS("α", RubyEncoding.UTF8);
            Assert(y.Append(x).ToByteArray().ValueEquals(Utils.Concatenate(valid_utf8, invalid_utf8)));

            x = MS(invalid_utf8, RubyEncoding.UTF8);
            Assert(x.Append(x).ToByteArray().ValueEquals(Utils.Concatenate(invalid_utf8, invalid_utf8)));


            x = MS(invalid_utf8, RubyEncoding.UTF8);
            y = MS("βαγ", RubyEncoding.UTF8);
            Assert(x.Append(y, 1, 1).ToByteArray().ValueEquals(Utils.Concatenate(invalid_utf8, valid_utf8)));

            x = MS(invalid_utf8, RubyEncoding.UTF8);
            y = MS("α", RubyEncoding.UTF8);
            Assert(y.Append(x, 1, 2).ToByteArray().ValueEquals(Utils.Concatenate(valid_utf8, new byte[] { 0x85, 0x9c })));

            x = MS(invalid_utf8, RubyEncoding.UTF8);
            Assert(x.Append(x, 1, 2).ToByteArray().ValueEquals(Utils.Concatenate(invalid_utf8, new byte[] { 0x85, 0x9c })));
        }
Tests