示例#1
0
        public static void ReadTypeAnnotationSymbols_ZeroSymbol(IIonReader reader)
        {
            // an int with zero symbol annotation
            // $0::18
            reader.MoveNext();

            Assert.AreEqual(IonType.Int, reader.CurrentType);
            Assert.AreEqual(18, reader.IntValue());
            Assert.AreEqual(1, reader.GetTypeAnnotationSymbols().Count());
            Assert.IsTrue(reader.GetTypeAnnotationSymbols().Any(a => a.Text == null && a.ImportLocation == default));
        }
示例#2
0
        private static void CompareAnnotationSymbols(IIonReader it1, IIonReader it2)
        {
            SymbolToken[] syms1 = it1.GetTypeAnnotationSymbols().ToArray();
            SymbolToken[] syms2 = it2.GetTypeAnnotationSymbols().ToArray();

            AssertSymbolEquals("annotation", syms1, syms2);
        }
        private void TryWriteAnnotationSymbols(IIonReader reader)
        {
            var annots = reader.GetTypeAnnotationSymbols();

            foreach (var a in annots)
            {
                this.AddTypeAnnotationSymbol(a);
            }
        }
示例#4
0
        public static void ReadTypeAnnotationSymbols_SingleField(IIonReader reader)
        {
            // a singlefield structure with annotations
            // {withannot:years::months::days::hours::minutes::seconds::18}
            var symbols = new[] { "years", "months", "days", "hours", "minutes", "seconds" };

            reader.MoveNext();
            reader.StepIn();
            reader.MoveNext();
            Assert.AreEqual(IonType.Int, reader.CurrentType);
            Assert.AreEqual("withannot", reader.CurrentFieldName);
            Assert.AreEqual(18, reader.IntValue());

            Assert.AreEqual(symbols.Count(), reader.GetTypeAnnotationSymbols().Count());

            foreach (var s in symbols)
            {
                Assert.IsTrue(reader.GetTypeAnnotationSymbols().Any(a => a.Text == s));
            }
        }
示例#5
0
        private static void CompareAnnotations(IIonReader it1, IIonReader it2)
        {
            //Skip assertion if annotation is zero symbol
            if (it1.GetTypeAnnotationSymbols().Any(a => a.Text == null && a.Sid == 0))
            {
                return;
            }
            string[] syms_text1 = it1.GetTypeAnnotations();
            string[] syms_text2 = it2.GetTypeAnnotations();

            Assert.IsTrue(syms_text1.SequenceEqual(syms_text2));
        }
示例#6
0
 public static void ReadTypeAnnotationSymbols_AssertNoUnknownSymbolException(IIonReader reader)
 {
     // $ion_symbol_table::{ imports:[{ name: \"abc\", version: 1, max_id: 1}],symbols: [\"foo\"]}$10::$11::\"value\"
     try
     {
         reader.MoveNext();
         reader.GetTypeAnnotationSymbols();
     }
     catch (UnknownSymbolException e)
     {
         Assert.Fail(e.Message);
     }
 }
示例#7
0
        private static void CompareHasAnnotations(IIonReader it1, IIonReader it2)
        {
            //Skip assertion if annotation is zero symbol
            if (it1.GetTypeAnnotationSymbols().Any(a => a.Text == null && a.Sid == 0))
            {
                return;
            }
            string[] syms_text1 = it1.GetTypeAnnotations();
            string[] syms_text2 = it2.GetTypeAnnotations();

            Assert.IsTrue(syms_text1.Count() == syms_text2.Count());

            for (int index = 0; index < syms_text1.Count(); index++)
            {
                Assert.IsTrue(it1.HasAnnotation(syms_text2[index]));
                Assert.IsTrue(it2.HasAnnotation(syms_text1[index]));
            }
        }
示例#8
0
        private void InternalWriteValue(IIonReader reader, int depth = 0)
        {
            IonType type = reader.CurrentType;

            if (type == IonType.None)
            {
                return;
            }

            if (depth > 0 && this.IsInStruct)
            {
                this.SetFieldNameSymbol(reader.GetFieldNameSymbol());
            }

            foreach (var annotation in reader.GetTypeAnnotationSymbols())
            {
                this.AddTypeAnnotationSymbol(annotation);
            }

            if (reader.CurrentIsNull)
            {
                this.WriteNull(type);
            }
            else
            {
                switch (type)
                {
                case IonType.Bool:
                    this.WriteBool(reader.BoolValue());
                    break;

                case IonType.Int:
                    this.WriteInt(reader.BigIntegerValue());
                    break;

                case IonType.Float:
                    this.WriteFloat(reader.DoubleValue());
                    break;

                case IonType.Decimal:
                    this.WriteDecimal(reader.DecimalValue());
                    break;

                case IonType.Timestamp:
                    this.WriteTimestamp(reader.TimestampValue());
                    break;

                case IonType.Symbol:
                    this.WriteSymbolToken(reader.SymbolValue());
                    break;

                case IonType.String:
                    this.WriteString(reader.StringValue());
                    break;

                case IonType.Clob:
                    this.WriteClob(reader.NewByteArray());
                    break;

                case IonType.Blob:
                    this.WriteBlob(reader.NewByteArray());
                    break;

                case IonType.List:
                    this.StepIn(IonType.List);
                    break;

                case IonType.Sexp:
                    this.StepIn(IonType.Sexp);
                    break;

                case IonType.Struct:
                    this.StepIn(IonType.Struct);
                    break;

                default:
                    throw new InvalidOperationException("Unexpected type '" + type + "'");
                }

                if (type.IsContainer())
                {
                    reader.StepIn();
                    this.InternalWriteValues(reader, depth + 1);
                    this.StepOut();
                    reader.StepOut();
                }
            }
        }