public void FixedStringNContains()
        {
            FixedStringN a = "bookkeeper";
            FixedStringN b = "ookkee";

            Assert.AreEqual(true, a.Contains(b));
        }
        public void FixedStringNToStringWorks(String a)
        {
            FixedStringN aa = new FixedStringN(a);

            Assert.AreEqual(a, aa.ToString());
            aa.AssertNullTerminated();
        }
        public void FixedStringNLastIndexOf()
        {
            FixedStringN a = "bookkeeper bookkeeper";
            FixedStringN b = "ookkee";

            Assert.AreEqual(12, a.LastIndexOf(b));
            Assert.AreEqual(-1, b.LastIndexOf(a));
        }
        public void FixedStringNComparisons()
        {
            FixedStringN a = "apple";
            FixedStringN b = "banana";

            Assert.AreEqual(false, a.Equals(b));
            Assert.AreEqual(true, !b.Equals(a));
        }
        public void FixedStringNAppendString()
        {
            FixedStringN aa = default;

            aa.Append("aa");
            Assert.AreEqual("aa", aa.ToString());
            aa.Append("bb");
            Assert.AreEqual("aabb", aa.ToString());
        }
        public void FixedStringNEqualsWorks(String a, String b)
        {
            FixedStringN aa = new FixedStringN(a);
            FixedStringN bb = new FixedStringN(b);

            Assert.AreEqual(aa.Equals(bb), a.Equals(b));
            aa.AssertNullTerminated();
            bb.AssertNullTerminated();
        }
        unsafe public void FixedStringNLayout(String a, byte[] expected)
        {
            fixed(byte *expectedBytes = expected)
            {
                FixedStringN actual      = a;
                byte *       actualBytes = (byte *)&actual;

                Assert.AreEqual(0, UnsafeUtility.MemCmp(expectedBytes, actualBytes, expected.Length));
            }
        }
Exemple #8
0
        public void FixedStringNParseFloatInfinity()
        {
            FixedStringN aa     = new FixedStringN("Infinity");
            int          offset = 0;
            float        output = 0;
            var          result = aa.Parse(ref offset, ref output);

            Assert.AreEqual(ParseError.None, result);
            Assert.IsTrue(Single.IsPositiveInfinity(output));
        }
Exemple #9
0
        public void FixedStringNParseFloatNan()
        {
            FixedStringN aa     = new FixedStringN("NaN");
            int          offset = 0;
            float        output = 0;
            var          result = aa.Parse(ref offset, ref output);

            Assert.AreEqual(ParseError.None, result);
            Assert.IsTrue(Single.IsNaN(output));
        }
Exemple #10
0
        public void FixedStringNFormatUInt(uint input)
        {
            var          expectedOutput = input.ToString();
            FixedStringN aa             = new FixedStringN();
            var          result         = aa.Append(input);

            Assert.AreEqual(FormatError.None, result);
            var actualOutput = aa.ToString();

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Exemple #11
0
        public void FixedStringNAppendULong(ulong input)
        {
            var          expectedOutput = "foo" + input.ToString();
            FixedStringN aa             = "foo";
            var          result         = aa.Append(input);

            Assert.AreEqual(FormatError.None, result);
            var actualOutput = aa.ToString();

            Assert.AreEqual(expectedOutput, actualOutput);
        }
        public void FixedStringRuneWorks()
        {
            var rune = new Unicode.Rune(0xfbad);

            FixedStringN a = new FixedStringN(rune, 3);
            FixedStringN b = default;

            b.Append(rune);
            b.Append(rune, 2);
            Assert.AreEqual(a.ToString(), b.ToString());
        }
Exemple #13
0
        public void FixedStringNFormatNegativeZero()
        {
            float        input          = -0.0f;
            var          expectedOutput = input.ToString(CultureInfo.InvariantCulture);
            FixedStringN aa             = new FixedStringN();
            var          result         = aa.Append(input);

            Assert.AreEqual(FormatError.None, result);
            var actualOutput = aa.ToString();

            Assert.AreEqual(expectedOutput, actualOutput);
        }
        public void FixedStringNFormatExtension1Params()
        {
            FixedStringN aa = default;

            aa.Junk();
            FixedStringN  format = "{0}";
            FixedString32 arg0   = "a";

            aa.AppendFormat(format, arg0);
            Assert.AreEqual("a", aa);
            aa.AssertNullTerminated();
        }
Exemple #15
0
        public void FixedStringNParseIntWorks(String a, int expectedOffset, int expectedOutput, ParseError expectedResult)
        {
            FixedStringN aa     = new FixedStringN(a);
            int          offset = 0;
            int          output = 0;
            var          result = aa.Parse(ref offset, ref output);

            Assert.AreEqual(expectedResult, result);
            Assert.AreEqual(expectedOffset, offset);
            if (result == ParseError.None)
            {
                Assert.AreEqual(expectedOutput, output);
            }
        }
Exemple #16
0
        public void FixedStringNAppendFloat(float input, FormatError expectedResult)
        {
            var          localizedDecimalSeparator = Convert.ToChar(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            var          expectedOutput            = "foo" + input.ToString();
            FixedStringN aa     = "foo";
            var          result = aa.Append(input, localizedDecimalSeparator);

            Assert.AreEqual(expectedResult, result);
            if (result == FormatError.None)
            {
                var actualOutput = aa.ToString();
                Assert.AreEqual(expectedOutput, actualOutput);
            }
        }
        public void FixedStringNFormatExtension3Params()
        {
            FixedStringN aa = default;

            aa.Junk();
            FixedStringN  format = "{0} {1} {2}";
            FixedString32 arg0   = "a";
            FixedString32 arg1   = "b";
            FixedString32 arg2   = "c";

            aa.AppendFormat(format, arg0, arg1, arg2);
            Assert.AreEqual("a b c", aa);
            aa.AssertNullTerminated();
        }
Exemple #18
0
        public void FixedStringNCopyFromBytesWorks(String a)
        {
            FixedStringN aa = default;

            aa.Junk();
            var utf8 = Encoding.UTF8.GetBytes(a);

            unsafe
            {
                fixed(byte *b = utf8)
                aa.Append(b, (ushort)utf8.Length);
            }
            Assert.AreEqual(a, aa.ToString());
            aa.AssertNullTerminated();
        }
        public void FixedStringNFormatExtension6Params()
        {
            FixedStringN aa = default;

            aa.Junk();
            FixedStringN  format = "{0} {1} {2} {3} {4} {5}";
            FixedString32 arg0   = "a";
            FixedString32 arg1   = "b";
            FixedString32 arg2   = "c";
            FixedString32 arg3   = "d";
            FixedString32 arg4   = "e";
            FixedString32 arg5   = "f";

            aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5);
            Assert.AreEqual("a b c d e f", aa);
            aa.AssertNullTerminated();
        }
        public void FixedStringNForEach()
        {
            FixedStringN   actual   = "A🌕Z🌑";
            FixedListInt32 expected = default;

            expected.Add('A');
            expected.Add(0x1F315);
            expected.Add('Z');
            expected.Add(0x1F311);
            int index = 0;

            foreach (var rune in actual)
            {
                Assert.AreEqual(expected[index], rune.value);
                ++index;
            }
        }
Exemple #21
0
        public void FixedStringNParseFloat(String unlocalizedString, int expectedOffset, ParseError expectedResult)
        {
            var   localizedDecimalSeparator = Convert.ToChar(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            var   localizedString           = unlocalizedString.Replace('.', localizedDecimalSeparator);
            float expectedOutput            = 0;

            try { expectedOutput = Single.Parse(localizedString); } catch {}
            FixedStringN nativeLocalizedString = new FixedStringN(localizedString);
            int          offset = 0;
            float        output = 0;
            var          result = nativeLocalizedString.Parse(ref offset, ref output, localizedDecimalSeparator);

            Assert.AreEqual(expectedResult, result);
            Assert.AreEqual(expectedOffset, offset);
            if (result == ParseError.None)
            {
                Assert.AreEqual(expectedOutput, output);
            }
        }
Exemple #22
0
        public void FixedStringNParseFloatLocale(String locale)
        {
            var original = CultureInfo.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(locale);
                var          localizedDecimalSeparator = Convert.ToChar(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                float        value  = 1.5f;
                FixedStringN native = new FixedStringN();
                native.Append(value, localizedDecimalSeparator);
                var nativeResult  = native.ToString();
                var managedResult = value.ToString();
                Assert.AreEqual(managedResult, nativeResult);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = original;
            }
        }
        public void FixedStringNFormatExtension9Params()
        {
            FixedStringN aa = default;

            aa.Junk();
            FixedStringN  format = "{0} {1} {2} {3} {4} {5} {6} {7} {8}";
            FixedString32 arg0   = "a";
            FixedString32 arg1   = "b";
            FixedString32 arg2   = "c";
            FixedString32 arg3   = "d";
            FixedString32 arg4   = "e";
            FixedString32 arg5   = "f";
            FixedString32 arg6   = "g";
            FixedString32 arg7   = "h";
            FixedString32 arg8   = "i";

            aa.AppendFormat(format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
            Assert.AreEqual("a b c d e f g h i", aa);
            aa.AssertNullTerminated();
        }
Exemple #24
0
 static int BurstAppendFn(ref FixedStringN fs, in FixedString32 other)