Ejemplo n.º 1
0
        public void CanTranslateAllTokenTypes()
        {
            string input = "text 9999999999999999999999999999 -32768 2,147,483,647 -9,223,372,036,854,775,808 129 NaN -3.402823e38 true 65,535 4,294,967,295 18,446,744,073,709,551,615 -128";

            using (var s = new TextScanner(input)
                           .UseCulture(new CultureInfo("en-US")))
            {
                Assert.That(s.HasNext(), Is.True);
                Assert.That(s.Next(), Is.EqualTo("text"));

                Assert.That(s.HasNextDecimal(), Is.True);
                Assert.That(s.NextDecimal(), Is.EqualTo(9999999999999999999999999999m));

                Assert.That(s.HasNextInt16(), Is.True);
                Assert.That(s.NextInt16(), Is.EqualTo((short)-32768));

                Assert.That(s.HasNextInt32(), Is.True);
                Assert.That(s.NextInt32(), Is.EqualTo(2147483647));

                Assert.That(s.HasNextInt64(), Is.True);
                Assert.That(s.NextInt64(), Is.EqualTo(-9223372036854775808L));

                Assert.That(s.HasNextByte(), Is.True);
                Assert.That(s.NextByte(), Is.EqualTo((byte)129));

                Assert.That(s.HasNextDouble(), Is.True);
                Assert.That(s.NextDouble(), Is.EqualTo(double.NaN));

                Assert.That(s.HasNextSingle(), Is.True);
                Assert.That(s.NextSingle(), Is.EqualTo(-3.402823e38f));

                Assert.That(s.HasNextBoolean(), Is.True);
                Assert.That(s.NextBoolean(), Is.EqualTo(true));

                Assert.That(s.HasNextUInt16(), Is.True);
                Assert.That(s.NextUInt16(), Is.EqualTo((ushort)65535));

                Assert.That(s.HasNextUInt32(), Is.True);
                Assert.That(s.NextUInt32(), Is.EqualTo((uint)4294967295U));

                Assert.That(s.HasNextUInt64(), Is.True);
                Assert.That(s.NextUInt64(), Is.EqualTo((ulong)18446744073709551615U));

                Assert.That(s.HasNextSByte(), Is.True);
                Assert.That(s.NextSByte(), Is.EqualTo((sbyte)-128));
            }

            using (var s = new TextScanner("5/1/2008 8:30:52 AM").UseDelimiter(",\\s*"))
            {
                Assert.That(s.HasNextDateTime(), Is.True);
                Assert.That(s.NextDateTime(), Is.EqualTo(new DateTime(2008, 5, 1, 8, 30, 52)));
            }
        }
Ejemplo n.º 2
0
        public void CanTranslateTokenAfterFail()
        {
            string input = "18,446,744,073,709,551,615 -128";

            using (var s = new TextScanner(input)
                           .UseCulture(new CultureInfo("en-US")))
            {
                Assert.That(s.HasNextUInt32(), Is.False);
                Assert.Catch <OverflowException>(() => s.NextUInt32());

                Assert.That(s.HasNextUInt64(), Is.True);
                Assert.That(s.NextUInt64(), Is.EqualTo((ulong)18446744073709551615U));

                Assert.That(s.HasNextSByte(), Is.True);
                Assert.That(s.NextSByte(), Is.EqualTo((sbyte)-128));
            }
        }