예제 #1
0
        public void EndsWithCodeUnit(string s, char c)
        {
            Utf8String   u8s      = new Utf8String(s);
            Utf8CodeUnit codeUnit = (Utf8CodeUnit)(byte)c;

            Assert.Equal(s.EndsWith(c.ToString()), u8s.EndsWith(codeUnit));
        }
예제 #2
0
        public void IndexOfUtf8Character(string s, char character)
        {
            int expected = s.IndexOf(character);

            Utf8String   u8s        = new Utf8String(s);
            Utf8CodeUnit u8codeUnit = (Utf8CodeUnit)(byte)(character);

            Assert.Equal(expected, u8s.IndexOf(u8codeUnit));
        }
 public void ConvertToChar(bool shouldThrow, Utf8CodeUnit codeUnit)
 {
     if (shouldThrow)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { var c = (char)codeUnit; });
     }
     else
     {
         Assert.Equal((int)codeUnit.Value, (int)((char)codeUnit));
     }
 }
 public void CtorChar(bool shouldThrow, char value)
 {
     if (shouldThrow)
     {
         Assert.Throws <ArgumentOutOfRangeException>(() => { var codeUnit = new Utf8CodeUnit(value); });
     }
     else
     {
         Assert.Equal((byte)value, (new Utf8CodeUnit(value)).Value);
     }
 }
        public void TryCreateFrom(bool expectedNegated, char value)
        {
            bool expected = !expectedNegated;

            Utf8CodeUnit codeUnit;

            Assert.Equal(expected, Utf8CodeUnit.TryCreateFrom(value, out codeUnit));
            if (expected)
            {
                Assert.Equal((int)value, (int)codeUnit.Value);
            }
        }
예제 #6
0
        public void GetHashCodeIsDifferentForEveryPossibleCodeUnit()
        {
            HashSet<int> hashes = new HashSet<int>();
            for (int i = byte.MinValue; i <= byte.MaxValue; i++)
            {
                Utf8CodeUnit codeUnit = new Utf8CodeUnit((byte)i);
                Assert.True(hashes.Add(codeUnit.GetHashCode()));
            }

            // sanity
            Assert.Equal(256, hashes.Count);
        }
        public void GetHashCodeIsDifferentForEveryPossibleCodeUnit()
        {
            HashSet <int> hashes = new HashSet <int>();

            for (int i = byte.MinValue; i <= byte.MaxValue; i++)
            {
                Utf8CodeUnit codeUnit = new Utf8CodeUnit((byte)i);
                Assert.True(hashes.Add(codeUnit.GetHashCode()));
            }

            // sanity
            Assert.Equal(256, hashes.Count);
        }
예제 #8
0
        public void SubstringToCodeUnit(string s, char c)
        {
            Utf8String   u8s      = new Utf8String(s);
            Utf8CodeUnit codeUnit = (Utf8CodeUnit)(byte)(c);
            Utf8String   u8result;

            int  idx            = s.IndexOf(c);
            bool expectedToFind = idx != -1;

            Assert.Equal(expectedToFind, u8s.TrySubstringTo(codeUnit, out u8result));
            if (expectedToFind)
            {
                string expected = s.Substring(0, idx);
                Assert.Equal(new Utf8String(expected), u8result);
                Assert.Equal(expected, u8result.ToString());
            }
        }
        private static bool IsFalse(Utf8String text)
        {
            if (text.Length < 5)
            {
                return(false);
            }

            Utf8CodeUnit firstChar = text[0];

            if (firstChar != 'f' && firstChar != 'F')
            {
                return(false);
            }

            Utf8CodeUnit secondChar = text[1];

            if (secondChar != 'a' && secondChar != 'A')
            {
                return(false);
            }

            Utf8CodeUnit thirdChar = text[2];

            if (thirdChar != 'l' && thirdChar != 'L')
            {
                return(false);
            }

            Utf8CodeUnit fourthChar = text[3];

            if (fourthChar != 's' && fourthChar != 'S')
            {
                return(false);
            }

            Utf8CodeUnit fifthChar = text[4];

            if (fifthChar != 'e' && fifthChar != 'E')
            {
                return(false);
            }

            return(true);
        }
        public static bool TryParseBoolean(Utf8String text, Format.Parsed format,
                                           out bool value, out int bytesConsumed)
        {
            bytesConsumed = 0;
            value         = default(bool);
            if (text.Length < 1)
            {
                return(false);
            }

            Utf8CodeUnit firstCodeUnit = text[0];

            if (firstCodeUnit == '1')
            {
                bytesConsumed = 1;
                value         = true;
                return(true);
            }
            else if (firstCodeUnit == '0')
            {
                bytesConsumed = 1;
                value         = false;
                return(true);
            }
            else if (IsTrue(text))
            {
                bytesConsumed = 4;
                value         = true;
                return(true);
            }
            else if (IsFalse(text))
            {
                bytesConsumed = 5;
                value         = false;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private static bool IsTrue(Utf8String text)
        {
            if (text.Length < 4)
            {
                return(false);
            }

            Utf8CodeUnit firstChar = text[0];

            if (firstChar != 't' && firstChar != 'T')
            {
                return(false);
            }

            Utf8CodeUnit secondChar = text[1];

            if (secondChar != 'r' && secondChar != 'R')
            {
                return(false);
            }

            Utf8CodeUnit thirdChar = text[2];

            if (thirdChar != 'u' && thirdChar != 'U')
            {
                return(false);
            }

            Utf8CodeUnit fourthChar = text[3];

            if (fourthChar != 'e' && fourthChar != 'E')
            {
                return(false);
            }

            return(true);
        }
예제 #12
0
 public void EqualsChar(bool expected, Utf8CodeUnit codeUnit, char c)
 {
     Assert.Equal(expected, codeUnit.Equals(c));
 }
예제 #13
0
 public void EqualsBoxedChar(bool expected, Utf8CodeUnit codeUnit, char c)
 {
     Assert.Equal(expected, codeUnit.Equals((object)c));
 }
예제 #14
0
 public void EqualsAnyOtherObject(bool expected, Utf8CodeUnit codeUnit, object obj)
 {
     Assert.Equal(expected, codeUnit.Equals(obj));
 }
예제 #15
0
 public void EqualsAnyOtherObject(bool expected, Utf8CodeUnit codeUnit, object obj)
 {
     Assert.Equal(expected, codeUnit.Equals(obj));
 }
예제 #16
0
 public void EqualsBoxedUtf8CodeUnit(bool expected, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(expected, a.Equals((object)b));
     Assert.Equal(expected, b.Equals((object)a));
 }
예제 #17
0
 public void IsFirstCodeUnitInEncodedCodePoint(bool expected, Utf8CodeUnit codeUnit)
 {
     Assert.Equal(expected, Utf8CodeUnit.IsFirstCodeUnitInEncodedCodePoint(codeUnit));
 }
예제 #18
0
 public void EqualsOperator(bool expected, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(expected, a == b);
     Assert.Equal(expected, b == a);
 }
예제 #19
0
 public void EqualsBoxedUtf8CodeUnit(bool expected, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(expected, a.Equals((object)b));
     Assert.Equal(expected, b.Equals((object)a));
 }
예제 #20
0
 public void EqualsChar(bool expected, Utf8CodeUnit codeUnit, char c)
 {
     Assert.Equal(expected, codeUnit.Equals(c));
 }
예제 #21
0
 public void ConvertToByte(Utf8CodeUnit codeUnit)
 {
     Assert.Equal(codeUnit.Value, (byte)codeUnit);
 }
예제 #22
0
 public void IsAscii(bool expected, Utf8CodeUnit codeUnit)
 {
     Assert.Equal(expected, Utf8CodeUnit.IsAscii(codeUnit));
 }
예제 #23
0
 public void NotEqualsOperator(bool expectedNegated, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(!expectedNegated, a != b);
     Assert.Equal(!expectedNegated, b != a);
 }
예제 #24
0
 public void EqualsOperator(bool expected, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(expected, a == b);
     Assert.Equal(expected, b == a);
 }
예제 #25
0
 public void ConvertToByte(Utf8CodeUnit codeUnit)
 {
     Assert.Equal(codeUnit.Value, (byte)codeUnit);
 }
예제 #26
0
 public void CtorChar(bool shouldThrow, char value)
 {
     if (shouldThrow)
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => { var codeUnit = new Utf8CodeUnit(value); });
     }
     else
     {
         Assert.Equal((byte)value, (new Utf8CodeUnit(value)).Value);
     }
 }
예제 #27
0
 public void EqualsUtf8CodeUnit(bool expected, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(expected, a.Equals(b));
     Assert.Equal(expected, b.Equals(a));
 }
예제 #28
0
 public void IsAscii(bool expected, Utf8CodeUnit codeUnit)
 {
     Assert.Equal(expected, Utf8CodeUnit.IsAscii(codeUnit));
 }
예제 #29
0
 public void ConvertToChar(bool shouldThrow, Utf8CodeUnit codeUnit)
 {
     if (shouldThrow)
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => { var c = (char)codeUnit; });
     }
     else
     {
         Assert.Equal((int)codeUnit.Value, (int)((char)codeUnit));
     }
 }
예제 #30
0
 public void NotEqualsOperator(bool expectedNegated, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(!expectedNegated, a != b);
     Assert.Equal(!expectedNegated, b != a);
 }
예제 #31
0
 public void EqualsUtf8CodeUnit(bool expected, Utf8CodeUnit a, Utf8CodeUnit b)
 {
     Assert.Equal(expected, a.Equals(b));
     Assert.Equal(expected, b.Equals(a));
 }
예제 #32
0
 public void IsFirstCodeUnitInEncodedCodePoint(bool expected, Utf8CodeUnit codeUnit)
 {
     Assert.Equal(expected, Utf8CodeUnit.IsFirstCodeUnitInEncodedCodePoint(codeUnit));
 }
예제 #33
0
 public void EqualsBoxedChar(bool expected, Utf8CodeUnit codeUnit, char c)
 {
     Assert.Equal(expected, codeUnit.Equals((object)c));
 }