Пример #1
0
        public void Decimal64BitBoundary(InputStyle inputStyle)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Decimal, reader.MoveNext());
                Assert.AreEqual(18446744073709551615m, reader.DecimalValue().ToDecimal());

                Assert.AreEqual(IonType.Decimal, reader.MoveNext());
                Assert.AreEqual(-18446744073709551615.0m, reader.DecimalValue().ToDecimal());

                Assert.AreEqual(IonType.Decimal, reader.MoveNext());
                Assert.AreEqual(18446744073709551616.0m, reader.DecimalValue().ToDecimal());

                Assert.AreEqual(IonType.Decimal, reader.MoveNext());
                Assert.AreEqual(-18446744073709551616.0m, reader.DecimalValue().ToDecimal());
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteDecimal(18446744073709551615m);
                writer.WriteDecimal(-18446744073709551615m);
                writer.WriteDecimal(18446744073709551616m);
                writer.WriteDecimal(-18446744073709551616m);
                writer.Finish();
            }

            var file = DirStructure.IonTestFile("good/decimal64BitBoundary.ion");
            var r    = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #2
0
        public void GoodFieldName(string fileName, string fieldName)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Struct, reader.MoveNext());
                reader.StepIn();
                Assert.AreEqual(IonType.Bool, reader.MoveNext());
                Assert.AreEqual(fieldName, reader.CurrentFieldName);
                Assert.IsFalse(reader.BoolValue());
            }

            void writeFunc(IIonWriter writer)
            {
                writer.StepIn(IonType.Struct);
                writer.SetFieldName(fieldName);
                writer.WriteBool(false);
                writer.StepOut();
                writer.Finish();
            }

            var r = ReaderFromFile(DirStructure.IonTestFile($"good/{fileName}.ion"), InputStyle.FileStream);

            assertReader(r);
            AssertReaderWriter(assertReader, writeFunc);
        }
Пример #3
0
        public void Float_zeros()
        {
            var file   = DirStructure.IonTestFile("good/float_zeros.ion");
            var reader = ReaderFromFile(file, InputStyle.FileStream);

            while (reader.MoveNext() != IonType.None)
            {
                Assert.AreEqual(IonType.Float, reader.CurrentType);
                Assert.AreEqual(0d, reader.DoubleValue());

                using (var memoryStream = new MemoryStream())
                {
                    using (var writer = IonBinaryWriterBuilder.Build(memoryStream, forceFloat64: true))
                    {
                        writer.WriteFloat(reader.DoubleValue());
                        writer.Finish();
                    }

                    // Confirm the reader's and writer's byte presentations are the same
                    var readerByte = BitConverter.GetBytes(reader.DoubleValue());
                    Array.Reverse(readerByte);
                    // Get byte reprsentation of value from the stream
                    var writerByte = memoryStream.ToArray().Skip(5).ToArray();

                    Assert.IsTrue(Enumerable.SequenceEqual(writerByte, readerByte));
                }
            }
        }
Пример #4
0
        public void BadFieldName(string fileName)
        {
            var reader = ReaderFromFile(DirStructure.IonTestFile($"bad/{fileName}.ion"), InputStyle.FileStream);

            Assert.AreEqual(IonType.Struct, reader.MoveNext());
            reader.StepIn();
            //should throw here
            reader.MoveNext();
        }
Пример #5
0
        public void FloatWithTerminatingEof()
        {
            var file = DirStructure.IonTestFile("good/floatWithTerminatingEof.ion");
            var r    = ReaderFromFile(file, InputStyle.FileStream);

            Assert.AreEqual(IonType.Float, r.MoveNext());
            ReaderTestCommon.AssertFloatEqual(12.3, r.DoubleValue());

            Assert.AreEqual(IonType.None, r.MoveNext());
        }
Пример #6
0
        public void FloatDblMax()
        {
            var file   = DirStructure.IonTestFile("good/floatDblMax.ion");
            var floats = new[]
            {
                1.7976931348623157e308
            };

            AssertReaderWriterPrescision(file, floats);
        }
Пример #7
0
        public void Float_zeros()
        {
            var file   = DirStructure.IonTestFile("good/float_zeros.ion");
            var reader = ReaderFromFile(file, InputStyle.FileStream);

            while (reader.MoveNext() != IonType.None)
            {
                Assert.AreEqual(IonType.Float, reader.CurrentType);
                Assert.AreEqual(0d, reader.DoubleValue());
            }
        }
Пример #8
0
        public void FloatTrappedZeros()
        {
            var file   = DirStructure.IonTestFile("good/float_trapped_zeros.ion");
            var floats = new[]
            {
                1.0000000000000002e0,
                -1.0000000000000002e0
            };

            AssertReaderWriterPrescision(file, floats);
        }
Пример #9
0
        public void FloatDblMin()
        {
            var file   = DirStructure.IonTestFile("good/floatDblMin.ion");
            var floats = new[]
            {
                2.2250738585072012e-308,
                0.00022250738585072012e-304,
                2.225073858507201200000e-308,
                2.2250738585072012e-00308,
                2.2250738585072012997800001e-308,
                2.2250738585072014e-308,
                2.2250738585072009e-308
            };

            AssertReaderWriterPrescision(file, floats);
        }
Пример #10
0
        public void Float_values(InputStyle inputStyle)
        {
            var file = DirStructure.IonTestFile("good/float_values.ion");
            var nums = new List <double>();

            using (var fileStream = file.OpenRead())
            {
                using (var streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        nums.Add(double.Parse(line));
                    }
                }
            }

            void assertReader(IIonReader reader)
            {
                foreach (var num in nums)
                {
                    var type = reader.MoveNext();
                    Assert.AreEqual(IonType.Float, type);
                    Assert.AreEqual(num, reader.DoubleValue());
                }
            }

            void writerFunc(IIonWriter writer)
            {
                foreach (var num in nums)
                {
                    writer.WriteFloat(num);
                }

                writer.Finish();
            }

            var r = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #11
0
        public void DecimalWithTerminatingEof(InputStyle inputStyle)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Decimal, reader.MoveNext());
                Assert.AreEqual(1.23m, reader.DecimalValue().ToDecimal());
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteDecimal(1.23m);
                writer.Finish();
            }

            var file = DirStructure.IonTestFile("good/decimalWithTerminatingEof.ion");
            var r    = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #12
0
        public void NullBoolBinary(InputStyle inputStyle)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Bool, reader.MoveNext());
                Assert.IsTrue(reader.CurrentIsNull);
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteNull(IonType.Bool);
                writer.Finish();
            }

            var file = DirStructure.IonTestFile("good/nullBool.10n");
            var r    = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #13
0
        public void DecimalNegativeOneDotTwoEight(InputStyle inputStyle)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Decimal, reader.MoveNext());
                Assert.AreEqual(-1.28m, reader.DecimalValue().ToDecimal());
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteDecimal(-1.28m);
                writer.Finish();
            }

            var file = DirStructure.IonTestFile("good/decimalNegativeOneDotTwoEight.ion");
            var r    = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #14
0
        public void HexWithTerminatingEof(InputStyle inputStyle)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Int, reader.MoveNext());
                Assert.AreEqual(3, reader.IntValue());
                Assert.AreEqual(IonType.None, reader.MoveNext());
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteInt(3);
                writer.Finish();
            }

            var file = DirStructure.IonTestFile("good/hexWithTerminatingEof.ion");
            var r    = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #15
0
        public void FloatDblMin()
        {
            var file   = DirStructure.IonTestFile("good/floatDblMin.ion");
            var floats = new[]
            {
                2.2250738585072012e-308,
                0.00022250738585072012e-304,
                2.225073858507201200000e-308,
                2.2250738585072012e-00308,
                2.2250738585072012997800001e-308
            };

            void assertReader(IIonReader reader)
            {
                foreach (var f in floats)
                {
                    Assert.AreEqual(IonType.Float, reader.MoveNext());
                    ReaderTestCommon.AssertFloatEqual(f, reader.DoubleValue());
                }

                Assert.AreEqual(IonType.None, reader.MoveNext());
            }

            void writerFunc(IIonWriter writer)
            {
                foreach (var f in floats)
                {
                    writer.WriteFloat(f);
                }

                writer.Finish();
            }

            var r = ReaderFromFile(file, InputStyle.FileStream);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #16
0
        public void IntBigSize512(string fileName)
        {
            var        file = DirStructure.IonTestFile(fileName);
            var        r    = ReaderFromFile(file, InputStyle.FileStream);
            BigInteger b;

            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Int, reader.MoveNext());
                Assert.AreEqual(IntegerSize.BigInteger, reader.GetIntegerSize());
                b = reader.BigIntegerValue();
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteInt(b);
                writer.Finish();
            }

            assertReader(r);
            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #17
0
        public void FloatSpecials()
        {
            var file = DirStructure.IonTestFile("good/floatSpecials.ion");

            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.List, reader.MoveNext());
                reader.StepIn();

                Assert.AreEqual(IonType.Float, reader.MoveNext());
                Assert.IsTrue(double.IsNaN(reader.DoubleValue()));

                Assert.AreEqual(IonType.Float, reader.MoveNext());
                Assert.IsTrue(double.IsPositiveInfinity(reader.DoubleValue()));

                Assert.AreEqual(IonType.Float, reader.MoveNext());
                Assert.IsTrue(double.IsNegativeInfinity(reader.DoubleValue()));

                Assert.AreEqual(IonType.None, reader.MoveNext());
            }

            void writerFunc(IIonWriter writer)
            {
                writer.StepIn(IonType.List);

                writer.WriteFloat(double.NaN);
                writer.WriteFloat(double.PositiveInfinity);
                writer.WriteFloat(double.NegativeInfinity);

                writer.StepOut();
                writer.Finish();
            }

            var r = ReaderFromFile(file, InputStyle.FileStream);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }
Пример #18
0
        public void BooleanText(InputStyle inputStyle)
        {
            void assertReader(IIonReader reader)
            {
                Assert.AreEqual(IonType.Bool, reader.MoveNext());
                Assert.AreEqual(true, reader.BoolValue());
                Assert.AreEqual(IonType.Bool, reader.MoveNext());
                Assert.AreEqual(false, reader.BoolValue());
            }

            void writerFunc(IIonWriter writer)
            {
                writer.WriteBool(true);
                writer.WriteBool(false);
                writer.Finish();
            }

            var file = DirStructure.IonTestFile("good/booleans.ion");
            var r    = ReaderFromFile(file, inputStyle);

            assertReader(r);

            AssertReaderWriter(assertReader, writerFunc);
        }