Пример #1
0
        public unsafe void TestEquals()
        {
            byte[] b1 = Encoding.UTF8.GetBytes("hello\0");
            byte[] b2 = Encoding.UTF8.GetBytes("__hello__\0");
            byte[] b3 = Encoding.UTF8.GetBytes("__hell\0");
            byte[] b4 = Encoding.UTF8.GetBytes("\0");

            fixed(byte *fb1 = &b1[0])
            {
                MetadataName name = new MetadataName(fb1, null);

                Assert.That(name.Equals(b2, 2, 5), Is.True);
                Assert.That(name.Equals(b2, 2, 6), Is.False);
                Assert.That(name.Equals(b2, 2, 4), Is.False);
                Assert.That(name.Equals(b2, 1, 4), Is.False);
            }

            fixed(byte *fb4 = &b4[0])
            {
                MetadataName name = new MetadataName(fb4, null);

                Assert.That(name.Equals(b2, 2, 0), Is.True);
                Assert.That(name.Equals(b2, 0, 1), Is.False);
            }
        }
Пример #2
0
        private static unsafe void TestEmpty()
        {
            byte[] empty = new byte[] { 0 };
            fixed(byte *fempty = &empty[0])
            {
                MetadataName e = new MetadataName(fempty, null);

                Assert(e.Equals(MetadataName.Empty));
                Assert(e.Equals(MetadataNamePart.Empty));

                Assert(MetadataName.Empty.IsEmpty);
                Assert(MetadataName.Empty.GetHashCode() == e.GetHashCode());
                Assert(MetadataName.Empty.Equals(e));
                Assert(MetadataName.Empty.Equals(MetadataNamePart.Empty));
                Assert(MetadataName.Empty.GetLength() == 0);
                Assert(MetadataName.Empty.ToString() == "");
                Assert(MetadataName.Empty.GetExtent().Equals(MetadataNamePart.Empty));

                Assert(MetadataNamePart.Empty.Length == 0);
                Assert(MetadataNamePart.Empty.Equals(e));
                Assert(MetadataNamePart.Empty.Equals(MetadataName.Empty));
                Assert(MetadataNamePart.Empty.GetPart(0).Equals((object)MetadataNamePart.Empty));
                Assert(MetadataNamePart.Empty.GetPart(0).Equals(MetadataNamePart.Empty));
                Assert(MetadataNamePart.Empty.GetPart(0, 0).Equals(MetadataNamePart.Empty));
                Assert(MetadataNamePart.Empty.ToString() == "");
                Assert(MetadataNamePart.Empty.IndexOf(1) == -1);
                Assert(MetadataNamePart.Empty.IndexOf(1, 0, 0) == -1);
                Assert(MetadataNamePart.Empty.LastIndexOf(1, 0, 0) == -1);
                Assert(MetadataNamePart.Empty.IndexOf(0) == -1);
                Assert(MetadataNamePart.Empty.IndexOf(0, 0, 0) == -1);
                Assert(MetadataNamePart.Empty.LastIndexOf(0, 0, 0) == -1);
            }
        }
Пример #3
0
        private static unsafe void TestEquals()
        {
            byte[] b1 = Encoding.UTF8.GetBytes("hello\0");
            byte[] b2 = Encoding.UTF8.GetBytes("__hello__\0");
            byte[] b3 = Encoding.UTF8.GetBytes("__hell\0");
            byte[] b4 = Encoding.UTF8.GetBytes("\0");

            fixed(byte *fb1 = &b1[0])
            {
                MetadataName name = new MetadataName(fb1, null);

                Assert(name.Equals(b2, 2, 5));
                Assert(!name.Equals(b2, 2, 6));
                Assert(!name.Equals(b2, 2, 4));
                Assert(!name.Equals(b2, 1, 4));
            }

            fixed(byte *fb4 = &b4[0])
            {
                MetadataName name = new MetadataName(fb4, null);

                Assert(name.Equals(b2, 2, 0));
                Assert(!name.Equals(b2, 0, 1));
            }
        }
Пример #4
0
        private static unsafe void TestEquals()
        {
            byte[] b1 = Encoding.UTF8.GetBytes("hello\0");
            byte[] b2 = Encoding.UTF8.GetBytes("__hello__\0");
            byte[] b3 = Encoding.UTF8.GetBytes("__hell\0");
            byte[] b4 = Encoding.UTF8.GetBytes("\0");

            fixed (byte* fb1 = &b1[0]) {
                MetadataName name = new MetadataName(fb1, null);
                Assert(name.Equals(b2, 2, 5));
                Assert(!name.Equals(b2, 2, 6));
                Assert(!name.Equals(b2, 2, 4));
                Assert(!name.Equals(b2, 1, 4));
            }

            fixed (byte* fb4 = &b4[0]) {
                MetadataName name = new MetadataName(fb4, null);
                Assert(name.Equals(b2, 2, 0));
                Assert(!name.Equals(b2, 0, 1));
            }
        }
Пример #5
0
        private static unsafe void TestEmpty()
        {
            byte[] empty = new byte[] { 0 };
            fixed (byte* fempty = &empty[0]) {
                MetadataName e = new MetadataName(fempty, null);
                Assert(e.Equals(MetadataName.Empty));
                Assert(e.Equals(MetadataNamePart.Empty));

                Assert(MetadataName.Empty.IsEmpty);
                Assert(MetadataName.Empty.GetHashCode() == e.GetHashCode());
                Assert(MetadataName.Empty.Equals(e));
                Assert(MetadataName.Empty.Equals(MetadataNamePart.Empty));
                Assert(MetadataName.Empty.GetLength() == 0);
                Assert(MetadataName.Empty.ToString() == "");
                Assert(MetadataName.Empty.GetExtent().Equals(MetadataNamePart.Empty));

                Assert(MetadataNamePart.Empty.Length == 0);
                Assert(MetadataNamePart.Empty.Equals(e));
                Assert(MetadataNamePart.Empty.Equals(MetadataName.Empty));
                Assert(MetadataNamePart.Empty.GetPart(0).Equals((object)MetadataNamePart.Empty));
                Assert(MetadataNamePart.Empty.GetPart(0).Equals(MetadataNamePart.Empty));
                Assert(MetadataNamePart.Empty.GetPart(0, 0).Equals(MetadataNamePart.Empty));
                Assert(MetadataNamePart.Empty.ToString() == "");
                Assert(MetadataNamePart.Empty.IndexOf(1) == -1);
                Assert(MetadataNamePart.Empty.IndexOf(1, 0, 0) == -1);
                Assert(MetadataNamePart.Empty.LastIndexOf(1, 0, 0) == -1);
                Assert(MetadataNamePart.Empty.IndexOf(0) == -1);
                Assert(MetadataNamePart.Empty.IndexOf(0, 0, 0) == -1);
                Assert(MetadataNamePart.Empty.LastIndexOf(0, 0, 0) == -1);
            }
        }