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

MutableString_CompareTo1() private method

private MutableString_CompareTo1 ( ) : void
return void
        public void MutableString_CompareTo1() {
            MutableString x, y;
            RubyEncoding SJIS = RubyEncoding.SJIS;

            // invalid bytes <=> valid string:
            var invalid = new byte[] { 0xe2, 0x85, 0x9c, 0xef };

            x = MS(invalid, RubyEncoding.UTF8);
            y = MS("α", RubyEncoding.UTF8);
            Assert(Math.Sign(x.CompareTo(y)) == Math.Sign(0xe2 - 0xce));

            x = MS(invalid, RubyEncoding.UTF8);
            y = MS("α", RubyEncoding.UTF8);
            Assert(Math.Sign(y.CompareTo(x)) == Math.Sign(0xce - 0xe2));

            x = MS(invalid, RubyEncoding.UTF8);
            y = MS(invalid, RubyEncoding.UTF8);
            Assert(x.CompareTo(y) == 0);

            x = MS("α", RubyEncoding.UTF8);
            y = MS("α", RubyEncoding.UTF8);
            Assert(x.CompareTo(y) == 0);

            // encoding ordering:
            Assert(Math.Sign(RubyEncoding.UTF8.CompareTo(SJIS)) == -1);

            // difference in encodings is ignored if both strings are ascii:
            x = MS("a", RubyEncoding.UTF8);
            y = MS(new byte[] { (byte)'b' }, SJIS);
            Assert(Math.Sign(x.CompareTo(y)) == -1);

            // different encodings => compare binary data:
            x = MS("α", RubyEncoding.UTF8);
            y = MS("α", SJIS);
            Assert(Math.Sign(x.CompareTo(y)) == +1);

            x = MS(new byte[] { (byte)'a' }, RubyEncoding.UTF8);
            y = MS("α", SJIS);
            Assert(Math.Sign(x.CompareTo(y)) == -1);

            x = MS("α", RubyEncoding.UTF8);
            y = MS("a", SJIS);
            Assert(Math.Sign(x.CompareTo(y)) == +1);
        }
Tests