コード例 #1
0
 private void AssertRoundTripAssembly(LNode node)
 {
     ConstantCodecTest.AssertRoundTrip <LNode, IAssembly>(
         node,
         decoder.DecodeAssembly,
         encoder.EncodeDefinition);
 }
コード例 #2
0
        private void AssertRoundTrip(IType type, bool alsoUseLes = true)
        {
            if (alsoUseLes)
            {
                ConstantCodecTest.AssertRoundTrip <IType, string>(
                    type,
                    value => Les3LanguageService.Value.Print(encoder.Encode(value)),
                    node => decoder.DecodeType(Les3LanguageService.Value.ParseSingle(node)));
            }

            ConstantCodecTest.AssertRoundTrip <IType, LNode>(
                type,
                encoder.Encode,
                decoder.DecodeType);
        }
コード例 #3
0
        public void PickCorrectElement()
        {
            var a = new A();
            var b = new B();
            var c = new D();

            var codec = new PiecewiseCodec <object>();

            codec = codec.Add(new CodecElement <A, LNode>(
                                  "A",
                                  (obj, state) => LNode.Call((Symbol)"A"),
                                  (node, state) => a));
            codec = codec.Add(new CodecElement <B, LNode>(
                                  "B",
                                  (obj, state) => LNode.Call((Symbol)"B"),
                                  (node, state) => b));
            codec = codec.Add(new CodecElement <C, LNode>(
                                  "C",
                                  (obj, state) => LNode.Call((Symbol)"C"),
                                  (node, state) => c));

            var encoder = new EncoderState();
            var decoder = new DecoderState(log, new TypeResolver().ReadOnlyView);

            ConstantCodecTest.AssertRoundTrip <object, LNode>(
                a,
                obj => codec.Encode(obj, encoder),
                enc => codec.Decode(enc, decoder));

            ConstantCodecTest.AssertRoundTrip <object, LNode>(
                b,
                obj => codec.Encode(obj, encoder),
                enc => codec.Decode(enc, decoder));

            ConstantCodecTest.AssertRoundTrip <object, LNode>(
                c,
                obj => codec.Encode(obj, encoder),
                enc => codec.Decode(enc, decoder));
        }