Ejemplo n.º 1
0
 static unsafe void AssertNotEqualUnsafe(string s, char[] chars)
 {
     fixed(char *ptr = chars)
     {
         Assert.False(UnsafeStringComparer.AreEqual(s, ptr, s.Length), $"Incorrect match. String: \"{s}\", Chars: \"{new string(chars)}\"");
     }
 }
Ejemplo n.º 2
0
        public void StringToCharArray()
        {
            // length checks
            Assert.True(UnsafeStringComparer.AreEqual("", new char[0]));
            Assert.False(UnsafeStringComparer.AreEqual("1", new char[0]));
            Assert.False(UnsafeStringComparer.AreEqual("", new char[1]));
            Assert.False(UnsafeStringComparer.AreEqual("1", new char[2]));
            Assert.False(UnsafeStringComparer.AreEqual("11", new char[1]));

            // invalid length for char buffer (outside bounds of buffer)
            Assert.False(UnsafeStringComparer.AreEqual("123", "123".ToCharArray(), 1, 3));

            // starting at an offset greater than zero
            Assert.True(UnsafeStringComparer.AreEqual("123", "0123".ToCharArray(), 1, 3));

            foreach (var sample in s_samplesByLength.Values)
            {
                AssertEqual(sample.StringA, sample.CharsA);
                AssertEqual(sample.StringB, sample.CharsB);
                AssertEqual(sample.StringC, sample.CharsC);

                AssertNotEqual(sample.StringA, sample.CharsB);
                AssertNotEqual(sample.StringA, sample.CharsC);
                AssertNotEqual(sample.StringB, sample.CharsA);
                AssertNotEqual(sample.StringB, sample.CharsC);
                AssertNotEqual(sample.StringC, sample.CharsA);
                AssertNotEqual(sample.StringC, sample.CharsB);
            }
        }
Ejemplo n.º 3
0
 static unsafe void AssertNotEqualUnsafe(char[] a, char[] b)
 {
     fixed(char *aPtr = a)
     fixed(char *bPtr = b)
     {
         Assert.False(UnsafeStringComparer.AreEqual(aPtr, bPtr, a.Length), $"Incorrect match. String: \"{new string(a)}\", Chars: \"{new string(b)}\"");
     }
 }
Ejemplo n.º 4
0
 static void AssertNotEqual(string s, char[] chars)
 {
     Assert.False(UnsafeStringComparer.AreEqual(s, chars), $"Incorrect match. String: \"{s}\", Chars: \"{new string(chars)}\"");
 }
Ejemplo n.º 5
0
 static void AssertEqual(string s, char[] chars)
 {
     Assert.True(UnsafeStringComparer.AreEqual(s, chars), $"Didn't match. String: \"{s}\", Chars: \"{new string(chars)}\"");
 }