p101_enc 0.11.0

Library to convert Olivetti P101 program to and from different encodings
Documentation
use p101_is::{Instruction, JumpDestination, Register, CaiSign, CaiOrder, CaiDigit, CaiComma};
use p101_enc::encoding::*;
use p101_enc::encoder::*;
use p101_enc::decoder::*;

#[test]
pub fn encoding_idempotence() {
    let p = vec!(Instruction::Label(JumpDestination::AV),
        Instruction::CopyToA(Register::C),
        Instruction::Div(Register::M),
        Instruction::Mul(Register::A),
        Instruction::Div(Register::A),
        Instruction::Div(Register::M),
        Instruction::SwapA(Register::c),
        Instruction::Mul(Register::C),
        Instruction::SwapA(Register::C),
        Instruction::Label(JumpDestination::aV),
        Instruction::NewLine,
        Instruction::Reset(Register::A),
        Instruction::Add(Register::d),
        Instruction::Print(Register::R),
        Instruction::CopyToA(Register::d),
        Instruction::CaiStart,
        Instruction::Cai(CaiSign::Positive, CaiOrder::Low, CaiDigit::N0, CaiComma::No),
        Instruction::Cai(CaiSign::Positive, CaiOrder::Low, CaiDigit::N8, CaiComma::No),
        Instruction::Cai(CaiSign::Positive, CaiOrder::High, CaiDigit::N1, CaiComma::No),
        Instruction::Div(Register::M),
        Instruction::Mul(Register::A),
        Instruction::SwapA(Register::B),
        Instruction::CopyToA(Register::B),
        Instruction::CaiStart,
        Instruction::Cai(CaiSign::Negative, CaiOrder::Low, CaiDigit::N7, CaiComma::No),
        Instruction::Cai(CaiSign::Negative, CaiOrder::Low, CaiDigit::N7, CaiComma::No),
        Instruction::Cai(CaiSign::Negative, CaiOrder::Low, CaiDigit::N5, CaiComma::No),
        Instruction::Cai(CaiSign::Negative, CaiOrder::Low, CaiDigit::N0, CaiComma::No),
        Instruction::Cai(CaiSign::Negative, CaiOrder::Low, CaiDigit::N2, CaiComma::No),
        Instruction::Cai(CaiSign::Negative, CaiOrder::Low, CaiDigit::N0, CaiComma::No),
        Instruction::Cai(CaiSign::Negative, CaiOrder::High, CaiDigit::N0, CaiComma::Yes),
        Instruction::Mul(Register::M),
    );

    let enc = Encoder::<StandardEncoding, NullAnnotator>::new();
    let text = enc.encode(&p);

    let mut dec = Decoder::<StandardEncoding>::new();
    match dec.decode(&text) {
        Ok(p1) => {
            assert_eq!(p.len(), p1.len());

            for ip in 0..p.len() {
                assert_eq!(p.get(ip), p1.get(ip), "Equality test failed at ip {}", ip);
            }
        },
        Err(e) => {
            panic!("Decoder failed with error {}", e);
        }
    };
}