private IonStruct BuildFlatStruct(int start, int count) { var str = (IonStruct)MakeMutableValue(); for (var i = 0; i < count; i++) { str[$"field{start + i}"] = new IonInt(start + i); } return(str); }
public void Null() { var n = IonInt.NewNull(); Assert.AreEqual(IonType.Int, n.Type()); Assert.IsTrue(n.IsNull); Assert.AreEqual(IntegerSize.Unknown, n.IntegerSize); Assert.ThrowsException <NullValueException>(() => n.IntValue); Assert.ThrowsException <NullValueException>(() => n.LongValue); Assert.ThrowsException <NullValueException>(() => n.BigIntegerValue); }
public void SetReadOnly() { var v = new IonInt(0); Assert.IsFalse(v.IsReadOnly); v.MakeReadOnly(); Assert.IsTrue(v.IsReadOnly); Assert.ThrowsException <InvalidOperationException>(() => v.AddTypeAnnotation("something")); Assert.ThrowsException <InvalidOperationException>(() => v.MakeNull()); }
public void SimpleLongValue(long value) { void AssertEqual(IonInt iv, long expected) { Assert.AreEqual(IntegerSize.Long, iv.IntegerSize); Assert.AreEqual(expected, iv.LongValue); Assert.AreEqual(expected, iv.BigIntegerValue); } var v = new IonInt(value); Assert.IsFalse(v.IsNull); AssertEqual(v, value); }
public void SimpleBigIntValue() { void AssertEqual(IonInt iv, BigInteger expected) { Assert.AreEqual(IntegerSize.BigInteger, iv.IntegerSize); Assert.AreEqual(expected, iv.BigIntegerValue); } var b1 = new BigInteger(long.MaxValue); b1 = b1 + 1000; var v = new IonInt(b1); AssertEqual(v, b1); }
public void FloatEquality(double value) { var v = new IonFloat(value); var vd = new IonFloat(value + 10e-14); var v2 = new IonFloat(value); var n = IonFloat.NewNull(); var n2 = IonFloat.NewNull(); var intVal = new IonInt(3); Assert.IsFalse(v.IsEquivalentTo(n)); Assert.IsFalse(n.IsEquivalentTo(v)); Assert.IsTrue(v.IsEquivalentTo(v2)); Assert.IsFalse(v.IsEquivalentTo(vd)); Assert.IsFalse(v.IsEquivalentTo(intVal)); Assert.IsTrue(n.IsEquivalentTo(n2)); }
public void BooleanEquality(bool value) { var nullBool = IonBool.NewNull(); var null2 = IonBool.NewNull(); var v = new IonBool(value); var v2 = new IonBool(value); var ionInt = new IonInt(3); var vd = new IonBool(!value); Assert.IsFalse(v.IsEquivalentTo(nullBool)); Assert.IsFalse(v.IsEquivalentTo(vd)); Assert.IsFalse(nullBool.IsEquivalentTo(v)); Assert.IsTrue(nullBool.IsEquivalentTo(IonBool.NewNull())); Assert.IsTrue(v.IsEquivalentTo(v2)); Assert.IsFalse(v.IsEquivalentTo(ionInt)); Assert.IsTrue(nullBool.IsEquivalentTo(null2)); }
public void SimpleIntValue(int value) { void AssertEqual(IonInt iv, int expected) { Assert.AreEqual(IntegerSize.Int, iv.IntegerSize); Assert.AreEqual(expected, iv.IntValue); Assert.AreEqual(expected, iv.LongValue); Assert.AreEqual(expected, iv.BigIntegerValue); } var v = new IonInt(value); Assert.IsFalse(v.IsNull); AssertEqual(v, value); v.IntValue = 10; AssertEqual(v, 10); }
public void StringEquality(string value) { var v = new IonString(value); var v2 = new IonString(value); var n = new IonString(null); var ionInt = new IonInt(3); Assert.IsTrue(v.IsEquivalentTo(v2)); if (value is null) { Assert.IsTrue(v.IsEquivalentTo(n)); } else { Assert.IsFalse(v.IsEquivalentTo(n)); } Assert.IsFalse(v.IsEquivalentTo(ionInt)); }
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)); }
public void IntEquality(int value) { var v = new IonInt(value); var v2 = new IonInt(value); var vd = new IonInt(value + (value > 0 ? -5 : 5)); var n = IonInt.NewNull(); var vb = new IonInt(new BigInteger(value)); void AssertEquals() { Assert.IsTrue(v.IsEquivalentTo(vb)); Assert.IsTrue(v.IsEquivalentTo(v2)); Assert.IsFalse(v.IsEquivalentTo(n)); Assert.IsFalse(v.IsEquivalentTo(vd)); } AssertEquals(); v = new IonInt((long)int.MaxValue + 10); v2 = new IonInt((long)int.MaxValue + 10); vb = new IonInt(new BigInteger((long)int.MaxValue + 10)); AssertEquals(); }
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); }
public override void WriteInt(BigInteger value) { var v = new IonInt(value); AppendValue(v); }
public override void WriteInt(long value) { var v = new IonInt(value); AppendValue(v); }