Example #1
0
        public override void StepIn(IonType type)
        {
            IonContainer c;

            switch (type)
            {
            case IonType.List:
                c = new IonList();
                break;

            case IonType.Sexp:
                c = new IonSexp();
                break;

            case IonType.Struct:
                c = new IonStruct();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            _containers.Push(c);
            AppendValue(c);
            _currentContainer = c;
        }
Example #2
0
        public void SingleSymbolTest()
        {
            //{single_symbol:'something'}
            var value = new IonStruct {
                { "single_symbol", _ionValueFactory.NewSymbol("something") }
            };
            var reader = new UserTreeReader(value);

            ReaderTestCommon.SingleSymbol(reader);
        }
Example #3
0
        public void SimpleDatagramTest()
        {
            //simple datagram: {yolo:true}
            var value = new IonStruct {
                { "yolo", _ionValueFactory.NewBool(true) }
            };
            var reader = new UserTreeReader(value);

            ReaderTestCommon.OneBoolInStruct(reader);
        }
Example #4
0
        public void BlobTest()
        {
            //Must be in a struct:
            // { blobbbb: {{data}} }
            var arrayOfbytes          = Enumerable.Repeat <byte>(1, 100).ToArray();
            ReadOnlySpan <byte> bytes = new ReadOnlySpan <byte>(arrayOfbytes);
            var blob  = _ionValueFactory.NewBlob(bytes);
            var value = new IonStruct {
                { "blobbbb", blob }
            };
            var reader = new UserTreeReader(value);

            ReaderTestCommon.Struct_OneBlob(reader);
        }
Example #5
0
        public void HasAnnotationFalseTest()
        {
            //Must be: {withannot: years::months::days::hours::minutes::seconds::18}
            var intValue = _ionValueFactory.NewInt(18);

            intValue.AddTypeAnnotation("years");
            intValue.AddTypeAnnotation("months");
            intValue.AddTypeAnnotation("days");
            intValue.AddTypeAnnotation("hours");
            intValue.AddTypeAnnotation("minutes");
            intValue.AddTypeAnnotation("seconds");
            var value = new IonStruct {
                { "withannot", intValue }
            };
            var reader = new UserTreeReader(value);

            ReaderTestCommon.HasAnnotationFalse_SingleField(reader);
        }
Example #6
0
        public void StructEquivalence_True()
        {
            var s1 = BuildFlatStruct(1, 10);
            var s2 = BuildFlatStruct(1, 10);

            Assert.IsTrue(s1.IsEquivalentTo(s2));

            //add fields with the same name
            s1.Add("new_field", new IonBool(true));
            s1.Add("new_field", new IonBool(true));
            s2.Add("new_field", new IonBool(true));
            s2.Add("new_field", new IonBool(true));
            Assert.IsTrue(s1.IsEquivalentTo(s2));

            var n1 = IonStruct.NewNull();
            var n2 = IonStruct.NewNull();

            Assert.IsTrue(n1.IsEquivalentTo(n2));
        }
Example #7
0
        public void StructEquivalence_False()
        {
            var s1 = BuildFlatStruct(1, 10);
            var s2 = BuildFlatStruct(1, 9);
            var n  = IonStruct.NewNull();

            Assert.IsFalse(s1.IsEquivalentTo(s2));
            Assert.IsFalse(s1.IsEquivalentTo(n));
            Assert.IsFalse(n.IsEquivalentTo(s1));
            s2["field10"] = new IonBool(true);
            Assert.IsFalse(s1.IsEquivalentTo(s2));

            s2.RemoveField("field10");
            s2["field10"] = new IonInt(10);
            Assert.IsTrue(s1.IsEquivalentTo(s2));

            //different field name
            s2.RemoveField("field10");
            s2["another"] = new IonInt(10);
            Assert.IsFalse(s1.IsEquivalentTo(s2));
        }
Example #8
0
        public void FlatStructScalarTest()
        {
            //Must be a flat struct of scalar values:
            //boolean:true
            //str:"yes"
            //integer:123456
            //longInt:int.Max*2
            //bigInt:long.Max*10
            //double:2213.1267567f
            var value = new IonStruct
            {
                { "boolean", _ionValueFactory.NewBool(true) },
                { "str", _ionValueFactory.NewString("yes") },
                { "integer", _ionValueFactory.NewInt(123456) },
                { "longInt", _ionValueFactory.NewInt((long)int.MaxValue * 2) },
                { "bigInt", _ionValueFactory.NewInt(BigInteger.Multiply(new BigInteger(long.MaxValue), 10)) },
                { "double", _ionValueFactory.NewFloat(2213.1267567) }
            };
            var reader = new UserTreeReader(value);

            ReaderTestCommon.FlatScalar(reader);
        }
Example #9
0
 internal override IonContainer MakeNullValue()
 {
     return(IonStruct.NewNull());
 }
Example #10
0
        public override void WriteNull(IonType type)
        {
            IonValue v;

            switch (type)
            {
            case IonType.Null:
                v = new IonNull();
                break;

            case IonType.Bool:
                v = IonBool.NewNull();
                break;

            case IonType.Int:
                v = IonInt.NewNull();
                break;

            case IonType.Float:
                v = IonFloat.NewNull();
                break;

            case IonType.Decimal:
                v = IonDecimal.NewNull();
                break;

            case IonType.Timestamp:
                v = IonTimestamp.NewNull();
                break;

            case IonType.Symbol:
                v = IonSymbol.NewNull();
                break;

            case IonType.String:
                v = new IonString(null);
                break;

            case IonType.Clob:
                v = IonClob.NewNull();
                break;

            case IonType.Blob:
                v = IonBlob.NewNull();
                break;

            case IonType.List:
                v = IonList.NewNull();
                break;

            case IonType.Sexp:
                v = IonSexp.NewNull();
                break;

            case IonType.Struct:
                v = IonStruct.NewNull();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            AppendValue(v);
        }
Example #11
0
        public void NestedAndCombinedListStructTest()
        {
            //Must be:
            // {
            //   menu: {
            //     id: "file",
            //     popup: [
            //       "Open",
            //       "Load",
            //       "Close"
            //     ],
            //     deep1: {
            //       deep2: {
            //         deep3: {
            //           deep4val: "enddeep"
            //         }
            //       }
            //     },
            //     positions: [
            //       1234,
            //       5678,
            //       90
            //     ]
            //   }
            // }

            var popupList = _ionValueFactory.NewEmptyList();

            popupList.Add(_ionValueFactory.NewString("Open"));
            popupList.Add(_ionValueFactory.NewString("Load"));
            popupList.Add(_ionValueFactory.NewString("Close"));

            var positionList = _ionValueFactory.NewEmptyList();

            positionList.Add(_ionValueFactory.NewInt(1234));
            positionList.Add(_ionValueFactory.NewInt(5678));
            positionList.Add(_ionValueFactory.NewInt(90));

            var deep3 = new IonStruct {
                { "deep4val", _ionValueFactory.NewString("enddeep") }
            };

            var deep2 = new IonStruct {
                { "deep3", deep3 }
            };

            var deep1 = new IonStruct {
                { "deep2", deep2 }
            };

            var menu = new IonStruct
            {
                { "id", _ionValueFactory.NewString("file") },
                { "popup", popupList },
                { "deep1", deep1 },
                { "positions", positionList }
            };

            var value = new IonStruct {
                { "menu", menu }
            };
            var reader = new UserTreeReader(value);

            ReaderTestCommon.Combined1(reader);
        }
Example #12
0
 protected override IonContainer MakeNullValue()
 {
     return(IonStruct.NewNull());
 }