public void CanDecode() { var pyint = new PyInt(10).GetPythonType(); var pyfloat = new PyFloat(10).GetPythonType(); var pystr = new PyString("world").GetPythonType(); var decoder1 = new DecoderReturningPredefinedValue <long>(pyint, decodeResult: 42); var decoder2 = new DecoderReturningPredefinedValue <string>(pyfloat, decodeResult: "atad:"); var group = new DecoderGroup { decoder1, decoder2, }; Assert.IsTrue(group.CanDecode(pyint, typeof(long))); Assert.IsFalse(group.CanDecode(pyint, typeof(int))); Assert.IsTrue(group.CanDecode(pyfloat, typeof(string))); Assert.IsFalse(group.CanDecode(pystr, typeof(string))); }
public void Decodes() { var pyint = new PyInt(10).GetPythonType(); var pyfloat = new PyFloat(10).GetPythonType(); var decoder1 = new DecoderReturningPredefinedValue <long>(pyint, decodeResult: 42); var decoder2 = new DecoderReturningPredefinedValue <string>(pyfloat, decodeResult: "atad:"); var group = new DecoderGroup { decoder1, decoder2, }; Assert.IsTrue(group.TryDecode(new PyInt(10), out long longResult)); Assert.AreEqual(42, longResult); Assert.IsTrue(group.TryDecode(new PyFloat(10), out string strResult)); Assert.AreSame("atad:", strResult); Assert.IsFalse(group.TryDecode(new PyInt(10), out int _)); }
public void GetDecodersByTypes() { var pyint = new PyInt(10).GetPythonType(); var pyfloat = new PyFloat(10).GetPythonType(); var pystr = new PyString("world").GetPythonType(); var decoder1 = new DecoderReturningPredefinedValue <long>(pyint, decodeResult: 42); var decoder2 = new DecoderReturningPredefinedValue <string>(pyfloat, decodeResult: "atad:"); var group = new DecoderGroup { decoder1, decoder2, }; var decoder = group.GetDecoder(pyfloat, typeof(string)); Assert.AreSame(decoder2, decoder); decoder = group.GetDecoder(pystr, typeof(string)); Assert.IsNull(decoder); decoder = group.GetDecoder(pyint, typeof(long)); Assert.AreSame(decoder1, decoder); }