Пример #1
0
        public static void TryParseLengthFails(ErrorCase <Length> @case)
        {
            var success = QuantityParser.TryParse <LengthUnit, Length>(
                @case.Text,
                Length.From,
                NumberStyles.Float,
                @case.CultureInfo,
                out var length);

            Assert.AreEqual(false, success);
            Assert.AreEqual(@case.Expected, length);

            success = Length.TryParse(@case.Text, NumberStyles.Float, @case.CultureInfo, out length);
            Assert.AreEqual(false, success);
            Assert.AreEqual(@case.Expected, length);

            success = Length.TryParse(@case.Text, @case.CultureInfo, out length);
            Assert.AreEqual(false, success);
            Assert.AreEqual(@case.Expected, length);

            using (Thread.CurrentThread.UsingTempCulture(@case.CultureInfo))
            {
                success = Length.TryParse(@case.Text, out length);
                Assert.AreEqual(false, success);
                Assert.AreEqual(@case.Expected, length);
            }
        }
Пример #2
0
        public void ParseError(ErrorCase <int> @case)
        {
            int pos = @case.Start;

            Assert.Throws <FormatException>(() => IntReader.ReadInt32(@case.Text, ref pos));
            Assert.AreEqual(pos, @case.ExpectedEnd);
        }
Пример #3
0
        public void TryParseError(ErrorCase <int> @case)
        {
            var pos = @case.Start;

            Assert.AreEqual(false, IntReader.TryReadInt32(@case.Text, ref pos, out var actual));
            Assert.AreEqual(@case.Expected, actual);
            Assert.AreEqual(@case.ExpectedEnd, pos);
        }
Пример #4
0
        public void TryParseError(ErrorCase <int> @case)
        {
            int pos = @case.Start;
            int actual;
            var success = IntReader.TryReadInt32(@case.Text, ref pos, out actual);

            Assert.AreEqual(false, success);
            Assert.AreEqual(@case.Expected, actual);
            Assert.AreEqual(@case.ExpectedEnd, pos);
        }
Пример #5
0
        public void ParseLengthThrows(ErrorCase <Length> testCase)
        {
            var numberStyles = NumberStyles.Float;
            var ex           = Assert.Throws <FormatException>(() => QuantityParser.Parse <LengthUnit, Length>(testCase.Text, Length.From, numberStyles, testCase.CultureInfo));

            Assert.AreEqual(testCase.ExpectedMessage, ex.Message);

            ex = Assert.Throws <FormatException>(() => Length.Parse(testCase.Text, numberStyles, testCase.CultureInfo));
            Assert.AreEqual(testCase.ExpectedMessage, ex.Message);

            ex = Assert.Throws <FormatException>(() => Length.Parse(testCase.Text, testCase.CultureInfo));
            Assert.AreEqual(testCase.ExpectedMessage, ex.Message);

            using (Thread.CurrentThread.UsingTempCulture(testCase.CultureInfo))
            {
                ex = Assert.Throws <FormatException>(() => Length.Parse(testCase.Text));
                Assert.AreEqual(testCase.ExpectedMessage, ex.Message);
            }
        }
Пример #6
0
        public static void ParseLengthThrows(ErrorCase <Length> testCase)
        {
            var numberStyles = NumberStyles.Float;
            var ex           = Assert.Throws <FormatException>(() => QuantityParser.Parse <LengthUnit, Length>(testCase.Text, Length.From, numberStyles, testCase.CultureInfo));

            Assert.AreEqual(testCase.ExpectedMessage, ex.Message);

            ex = Assert.Throws <FormatException>(() => Length.Parse(testCase.Text, numberStyles, testCase.CultureInfo));
            Assert.AreEqual(testCase.ExpectedMessage, ex.Message);

            ex = Assert.Throws <FormatException>(() => Length.Parse(testCase.Text, testCase.CultureInfo));
            Assert.AreEqual(testCase.ExpectedMessage, ex.Message);

            using (Thread.CurrentThread.UsingTempCulture(testCase.CultureInfo))
            {
#pragma warning disable CA1305 // Specify IFormatProvider
                ex = Assert.Throws <FormatException>(() => Length.Parse(testCase.Text));
#pragma warning restore CA1305 // Specify IFormatProvider
                Assert.AreEqual(testCase.ExpectedMessage, ex.Message);
            }
        }