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

MutableString_IndexOf1() private method

private MutableString_IndexOf1 ( ) : void
return void
        public void MutableString_IndexOf1() {
            string s = "12123";

            var strs = new[] {
                MutableString.CreateBinary(Utils.Concatenate(BinaryEncoding.Instance.GetBytes(s), new byte[] { 0, 0 })).Remove(s.Length, 2),
                MutableString.CreateMutable(s + "α", RubyEncoding.UTF8),
                MutableString.CreateMutable(s, RubyEncoding.UTF8).Append('α'),
                MutableString.CreateMutable(s, RubyEncoding.Binary).Append(new byte[] { 0xff }),
            };

            for (int i = 0; i < strs.Length; i++) {
                var a = strs[i];

                Action<string> test1 = (value) => {
                    Assert(a.IndexOf(BinaryEncoding.Instance.GetBytes(value)) == s.IndexOf(value));
                };

                Action<string, int> test2 = (value, start) => {
                    Assert(a.IndexOf(BinaryEncoding.Instance.GetBytes(value), start) == s.IndexOf(value, start));
                };

                Action<string, int, int> test3 = (value, start, count) => {
                    Assert(a.IndexOf(BinaryEncoding.Instance.GetBytes(value), start, count) == s.IndexOf(value, start, count));
                };

                test1("");
                test1("0");
                test1("12");
                test1("3");
                test2("", 4);
                test2("", 5);
                test2("12", 0);
                test2("12", 1);
                test2("12", 2);
                test2("30", 4);
                test3("", 2, 0);
                test3("12", 2, 1);
                test3("12", 2, 2);

                Assert(a.IndexOf('3', 100) == -1);
                Assert(a.IndexOf('2', 2) == s.IndexOf('2', 2));
                Assert(a.IndexOf('\0') == -1);

                Assert(a.IndexOf((byte)'3', 100) == -1);
                Assert(a.IndexOf((byte)'2', 2) == s.IndexOf('2', 2));
                Assert(a.IndexOf(0) == -1);

                Assert(a.IndexOf("123", 100) == -1);
                Assert(a.IndexOf("123", 1) == s.IndexOf("123", 1));
            }

            AssertExceptionThrown<ArgumentNullException>(() => strs[0].IndexOf((byte[])null, 1, 2));
            AssertExceptionThrown<ArgumentNullException>(() => strs[0].IndexOf((string)null, 1, 2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf((byte)6, -1, 2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf((byte)6, 1, -2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf('6', -1, 2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf('6', 1, -2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf(new byte[] { 6 }, -1, 2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf(new byte[] { 6 }, 6, -1));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf("6", -1, 2));
            AssertExceptionThrown<ArgumentException>(() => strs[0].IndexOf("6", 6, -1));
        }
Tests