public void FixedStringNAppendString()
        {
            FixedStringN aa = default;

            aa.Append("aa");
            Assert.AreEqual("aa", aa.ToString());
            aa.Append("bb");
            Assert.AreEqual("aabb", aa.ToString());
        }
        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());
        }
        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();

            aa.Append("tail");
            Assert.AreEqual(a + "tail", aa.ToString());
            aa.AssertNullTerminated();
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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;
            }
        }