public void ErlBinaryTest() { { var tt = new byte[] { 10, 11, 12 }; var t1 = new ErlBinary(tt, false); tt[0] = 20; Assert.AreEqual(20, t1.Value[0]); var bb = new byte[] { 10, 11, 12 }; var t2 = new ErlBinary(bb); bb[0] = 20; Assert.AreEqual(10, t2.Value[0]); } var tb = new byte[] { 1, 2, 3 }; var t = new ErlBinary(tb); Assert.IsTrue(t.Equals(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(t, new ErlBinary(tb)); Assert.IsTrue(new ErlBinary(new byte[] { 1, 2 }).CompareTo(t) < 0); Assert.AreEqual(tb, t.Value); Assert.IsTrue(t.ValueAsBool); Assert.IsFalse(new ErlBinary(new byte[] { }).ValueAsBool); Assert.AreEqual("<<1,2,3>>", t.ToString()); Assert.AreEqual("<<1,2,3>>", t.ToBinaryString()); Assert.IsFalse(t.IsScalar); Assert.AreEqual(ErlTypeOrder.ErlBinary, t.TypeOrder); var bbb = new ErlBinary(new byte[] { 97, 98, 99, 10, 49, 50, 51 }); Assert.AreEqual("<<\"abc\n123\">>", bbb.ToString()); Assert.AreEqual("<<\"abc\n123\">>", bbb.ToPrintableString()); Assert.AreEqual("<<\"abc...\">>", bbb.ToPrintableString(6)); Assert.AreEqual("<<97,98,99,10,49,50,51>>", bbb.ToBinaryString()); Assert.AreEqual("<<97,98...>>", bbb.ToBinaryString(10)); Assert.IsTrue(t.Matches(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(new ErlVarBind(), t.Match(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.DoesNotThrow(() => { var x = t.ValueAsObject; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); Assert.DoesNotThrow(() => { var x = t.ValueAsString; }); Assert.DoesNotThrow(() => { var x = t.ValueAsBool; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Assert.DoesNotThrow(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Assert.IsFalse(t.Subst(ref temp, new ErlVarBind())); Assert.AreEqual(3, t.Visit(0, (acc, o) => acc + ((ErlBinary)o).Length)); byte[] b = t; Assert.AreEqual(tb, b); }
public void ErlBinaryTest() { { var tt = new byte[] { 10, 11, 12 }; var t1 = new ErlBinary(tt, false); tt[0] = 20; Assert.AreEqual(20, t1.Value[0]); var bb = new byte[] { 10, 11, 12 }; var t2 = new ErlBinary(bb); bb[0] = 20; Assert.AreEqual(10, t2.Value[0]); } var tb = new byte[] { 1, 2, 3 }; var t = new ErlBinary(tb); Assert.IsTrue(t.Equals(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(t, new ErlBinary(tb)); Assert.IsTrue(new ErlBinary(new byte[] { 1, 2 }).CompareTo(t) < 0); Assert.AreEqual(tb, t.Value); Assert.IsTrue(t.ValueAsBool); Assert.IsFalse(new ErlBinary(new byte[] { }).ValueAsBool); Assert.AreEqual("#Bin<3>", t.ToString()); Assert.AreEqual("<<1,2,3>>", t.ToBinaryString()); Assert.IsFalse(t.IsScalar); Assert.AreEqual(ErlTypeOrder.ErlBinary, t.TypeOrder); Assert.IsTrue(t.Matches(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(new ErlVarBind(), t.Match(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.DoesNotThrow(() => { var x = t.ValueAsObject; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); Assert.DoesNotThrow(() => { var x = t.ValueAsString; }); Assert.DoesNotThrow(() => { var x = t.ValueAsBool; }); Assert.Throws <ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Assert.DoesNotThrow(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Assert.IsFalse(t.Subst(ref temp, new ErlVarBind())); byte[] b = t; Assert.AreEqual(tb, b); }
public void ErlBinaryTest() { { var tt = new byte[] { 10, 11, 12 }; var t1 = new ErlBinary(tt, false); tt[0] = 20; Assert.AreEqual(20, t1.Value[0]); var bb = new byte[] { 10, 11, 12 }; var t2 = new ErlBinary(bb); bb[0] = 20; Assert.AreEqual(10, t2.Value[0]); } var tb = new byte[] { 1, 2, 3 }; var t = new ErlBinary(tb); Assert.IsTrue(t.Equals(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(t, new ErlBinary(tb)); Assert.IsTrue(new ErlBinary(new byte[] { 1, 2 }).CompareTo(t) < 0); Assert.AreEqual(tb, t.Value); Assert.IsTrue(t.ValueAsBool); Assert.IsFalse(new ErlBinary(new byte[] { }).ValueAsBool); Assert.AreEqual("<<1,2,3>>", t.ToString()); Assert.AreEqual("<<1,2,3>>", t.ToBinaryString()); Assert.IsFalse(t.IsScalar); Assert.AreEqual(ErlTypeOrder.ErlBinary, t.TypeOrder); var bbb = new ErlBinary(new byte[] { 97, 98, 99, 10, 49, 50, 51 }); Assert.AreEqual("<<\"abc\n123\">>", bbb.ToString()); Assert.AreEqual("<<\"abc\n123\">>", bbb.ToPrintableString()); Assert.AreEqual("<<\"abc...\">>", bbb.ToPrintableString(6)); Assert.AreEqual("<<97,98,99,10,49,50,51>>", bbb.ToBinaryString()); Assert.AreEqual("<<97,98...>>", bbb.ToBinaryString(10)); Assert.IsTrue(t.Matches(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(new ErlVarBind(), t.Match(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.DoesNotThrow(() => { var x = t.ValueAsObject; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); Assert.DoesNotThrow(() => { var x = t.ValueAsString; }); Assert.DoesNotThrow(() => { var x = t.ValueAsBool; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Assert.DoesNotThrow(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Assert.IsFalse(t.Subst(ref temp, new ErlVarBind())); Assert.AreEqual(3, t.Visit(0, (acc, o) => acc + ((ErlBinary)o).Length)); byte[] b = t; Assert.AreEqual(tb, b); }
public void ErlBinaryTest() { { var tt = new byte[] { 10, 11, 12 }; var t1 = new ErlBinary(tt, false); tt[0] = 20; Assert.AreEqual(20, t1.Value[0]); var bb = new byte[] { 10, 11, 12 }; var t2 = new ErlBinary(bb); bb[0] = 20; Assert.AreEqual(10, t2.Value[0]); } var tb = new byte[] { 1, 2, 3 }; var t = new ErlBinary(tb); Assert.IsTrue(t.Equals(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(t, new ErlBinary(tb)); Assert.IsTrue(new ErlBinary(new byte[] { 1, 2 }).CompareTo(t) < 0); Assert.AreEqual(tb, t.Value); Assert.IsTrue(t.ValueAsBool); Assert.IsFalse(new ErlBinary(new byte[] { }).ValueAsBool); Assert.AreEqual("#Bin<3>", t.ToString()); Assert.AreEqual("<<1,2,3>>", t.ToBinaryString()); Assert.IsFalse(t.IsScalar); Assert.AreEqual(ErlTypeOrder.ErlBinary, t.TypeOrder); Assert.IsTrue(t.Matches(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.AreEqual(new ErlVarBind(), t.Match(new ErlBinary(new byte[] { 1, 2, 3 }))); Assert.DoesNotThrow(() => { var x = t.ValueAsObject; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsInt; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsLong; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsDecimal; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsDateTime; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsTimeSpan; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsDouble; }); Assert.DoesNotThrow(() => { var x = t.ValueAsString; }); Assert.DoesNotThrow(() => { var x = t.ValueAsBool; }); Assert.Throws<ErlIncompatibleTypesException>(() => { var x = t.ValueAsChar; }); Assert.DoesNotThrow(() => { var x = t.ValueAsByteArray; }); IErlObject temp = null; Assert.IsFalse(t.Subst(ref temp, new ErlVarBind())); byte[] b = t; Assert.AreEqual(tb, b); }