From 358ad4d14759d78591ba18f1609245832cd76fde Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 1 Oct 2023 17:10:40 +0200 Subject: [PATCH] move tests into separate files --- src/lib.rs | 132 +------------------------------------------- src/test/curry.rs | 6 ++ src/test/lexer.rs | 119 +++++++++++++++++++++++++++++++++++++++ src/test/lnf.rs | 6 ++ src/test/mod.rs | 7 +++ src/test/parser.rs | 7 +++ src/test/subtype.rs | 6 ++ 7 files changed, 154 insertions(+), 129 deletions(-) create mode 100644 src/test/curry.rs create mode 100644 src/test/lexer.rs create mode 100644 src/test/lnf.rs create mode 100644 src/test/mod.rs create mode 100644 src/test/parser.rs create mode 100644 src/test/subtype.rs diff --git a/src/lib.rs b/src/lib.rs index 08b487a..c156d89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,140 +1,14 @@ - pub mod lexer; pub mod bimap; pub mod dict; pub mod term; +#[cfg(test)] +mod test; + pub use { dict::*, term::*, }; -#[cfg(test)] -mod tests { - #[test] - fn test_lexer() { - use crate::lexer::*; - - { - let mut lex = LadderTypeLexer::new("symbol".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("symbol".into()))) ); - assert_eq!( lex.next(), None ); - } - { - let mut lex = LadderTypeLexer::new("1234".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Num(1234))) ); - assert_eq!( lex.next(), None ); - } - { - let mut lex = LadderTypeLexer::new("123xxx".chars()); - assert_eq!( lex.next(), Some(Err(LexError::InvalidDigit)) ); - } - { - let mut lex = LadderTypeLexer::new("'x'".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Char('x'))) ); - assert_eq!( lex.next(), None ); - } - { - let mut lex = LadderTypeLexer::new("'xx'".chars()); - assert_eq!( lex.next(), Some(Err(LexError::InvalidChar)) ); - } - { - let mut lex = LadderTypeLexer::new("abc~def".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("abc".into()))) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder)) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("def".into()))) ); - assert_eq!( lex.next(), None ); - } - { - let mut lex = LadderTypeLexer::new("abc ~ def".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("abc".into()))) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder)) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("def".into()))) ); - assert_eq!( lex.next(), None ); - } - - { - let mut lex = LadderTypeLexer::new("".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open)) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into()))) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Char".into()))) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close)) ); - assert_eq!( lex.next(), None ); - } - { - let mut lex = LadderTypeLexer::new(" ".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open)) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into()))) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Char".into()))) ); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close)) ); - assert_eq!( lex.next(), None ); - } - - { - let mut lex = LadderTypeLexer::new("~~ℕ~~~Unicode>".chars()); - - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Date".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("TimeSince".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("UnixEpoch".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Duration".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seconds".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("ℕ".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("PosInt".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Num(10)))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("BigEndian".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Digit".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Num(10)))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Unicode".into())))); - assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); - assert_eq!( lex.next(), None ); - } - } - - #[test] - fn test_parse() { - // todo - } - - #[test] - fn test_normalize() { - // todo - } - - #[test] - fn test_curry() { - // todo - } - - #[test] - fn test_subtype() { - // todo - } -} - - diff --git a/src/test/curry.rs b/src/test/curry.rs new file mode 100644 index 0000000..1e6b676 --- /dev/null +++ b/src/test/curry.rs @@ -0,0 +1,6 @@ + +#[test] +fn test_curry() { + // todo +} + diff --git a/src/test/lexer.rs b/src/test/lexer.rs new file mode 100644 index 0000000..f0b259e --- /dev/null +++ b/src/test/lexer.rs @@ -0,0 +1,119 @@ +use crate::lexer::*; + +#[test] +fn test_lexer_symbol() { + let mut lex = LadderTypeLexer::new("symbol".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("symbol".into()))) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_num() { + let mut lex = LadderTypeLexer::new("1234".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Num(1234))) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_num_error() +{ + let mut lex = LadderTypeLexer::new("123xxx".chars()); + assert_eq!( lex.next(), Some(Err(LexError::InvalidDigit)) ); +} + +#[test] +fn test_lexer_char() { + let mut lex = LadderTypeLexer::new("'x'".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Char('x'))) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_char_error() { + let mut lex = LadderTypeLexer::new("'xx'".chars()); + assert_eq!( lex.next(), Some(Err(LexError::InvalidChar)) ); +} + +#[test] +fn test_lexer_ladder() { + let mut lex = LadderTypeLexer::new("abc~def".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("abc".into()))) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder)) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("def".into()))) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_ladder_space() { + let mut lex = LadderTypeLexer::new("abc ~ def".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("abc".into()))) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder)) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("def".into()))) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_app() { + let mut lex = LadderTypeLexer::new("".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open)) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into()))) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Char".into()))) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close)) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_app_space() { + let mut lex = LadderTypeLexer::new(" ".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open)) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into()))) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Char".into()))) ); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close)) ); + assert_eq!( lex.next(), None ); +} + +#[test] +fn test_lexer_large() { + let mut lex = LadderTypeLexer::new("~~ℕ~~~Unicode>".chars()); + + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Date".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("TimeSince".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("UnixEpoch".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Duration".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seconds".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("ℕ".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("PosInt".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Num(10)))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("BigEndian".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Seq".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Open))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Digit".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Num(10)))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Ladder))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Symbol("Unicode".into())))); + assert_eq!( lex.next(), Some(Ok(LadderTypeToken::Close))); + assert_eq!( lex.next(), None ); +} + diff --git a/src/test/lnf.rs b/src/test/lnf.rs new file mode 100644 index 0000000..0915387 --- /dev/null +++ b/src/test/lnf.rs @@ -0,0 +1,6 @@ + +#[test] +fn test_lnf() { + // todo +} + diff --git a/src/test/mod.rs b/src/test/mod.rs new file mode 100644 index 0000000..9d13c07 --- /dev/null +++ b/src/test/mod.rs @@ -0,0 +1,7 @@ + +pub mod lexer; +pub mod parser; +pub mod curry; +pub mod lnf; +pub mod subtype; + diff --git a/src/test/parser.rs b/src/test/parser.rs new file mode 100644 index 0000000..996ee06 --- /dev/null +++ b/src/test/parser.rs @@ -0,0 +1,7 @@ + +#[test] +fn test_parser() { + // todo +} + + diff --git a/src/test/subtype.rs b/src/test/subtype.rs new file mode 100644 index 0000000..77f6d1e --- /dev/null +++ b/src/test/subtype.rs @@ -0,0 +1,6 @@ + +#[test] +fn test_subtype() { + // todo +} +