add simple test for decoding
This commit is contained in:
parent
d4b659c04e
commit
83a784c745
|
@ -1,12 +1,12 @@
|
|||
use crate::builtins::DefaultFunction;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Program {
|
||||
pub version: (usize, usize, usize),
|
||||
pub term: Term,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Term {
|
||||
// tag: 0
|
||||
Var(String),
|
||||
|
@ -32,7 +32,7 @@ pub enum Term {
|
|||
Builtin(DefaultFunction),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Constant {
|
||||
// TODO: figure out the right size for this
|
||||
// tag: 0
|
||||
|
|
|
@ -2,7 +2,7 @@ use strum_macros::EnumString;
|
|||
|
||||
#[repr(u8)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, EnumString)]
|
||||
#[derive(Debug, Clone, EnumString, PartialEq)]
|
||||
#[strum(serialize_all = "camelCase")]
|
||||
pub enum DefaultFunction {
|
||||
// Integer functions
|
||||
|
|
|
@ -237,6 +237,8 @@ pub fn decode_constant_tag(d: &mut Decoder) -> Result<u8, String> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use flat::Flat;
|
||||
|
||||
use super::{Constant, Program, Term};
|
||||
|
||||
#[test]
|
||||
|
@ -253,4 +255,19 @@ mod test {
|
|||
vec![0b00001011, 0b00010110, 0b00100001, 0b01001000, 0b00000101, 0b10000001]
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flat_decode_integer() {
|
||||
let flat_encoded = vec![
|
||||
0b00001011, 0b00010110, 0b00100001, 0b01001000, 0b00000101, 0b10000001,
|
||||
];
|
||||
let expected_program = Program {
|
||||
version: (11, 22, 33),
|
||||
term: Term::Constant(Constant::Integer(11)),
|
||||
};
|
||||
|
||||
let actual_program: Program = Program::unflat(flat_encoded.as_slice()).unwrap();
|
||||
|
||||
assert_eq!(actual_program, expected_program)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue