move tests into separate files

This commit is contained in:
Michael Sippel 2023-10-01 17:10:40 +02:00
parent 2f26dcc936
commit 358ad4d147
Signed by: senvas
GPG key ID: F96CF119C34B64A6
7 changed files with 154 additions and 129 deletions

View file

@ -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("<Seq Char>".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(" <Seq Char >".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("<Seq Date~<TimeSince UnixEpoch>~<Duration Seconds>~~<PosInt 10 BigEndian>~<Seq <Digit 10>~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
}
}

6
src/test/curry.rs Normal file
View file

@ -0,0 +1,6 @@
#[test]
fn test_curry() {
// todo
}

119
src/test/lexer.rs Normal file
View file

@ -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("<Seq Char>".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(" <Seq Char >".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("<Seq Date~<TimeSince UnixEpoch>~<Duration Seconds>~~<PosInt 10 BigEndian>~<Seq <Digit 10>~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 );
}

6
src/test/lnf.rs Normal file
View file

@ -0,0 +1,6 @@
#[test]
fn test_lnf() {
// todo
}

7
src/test/mod.rs Normal file
View file

@ -0,0 +1,7 @@
pub mod lexer;
pub mod parser;
pub mod curry;
pub mod lnf;
pub mod subtype;

7
src/test/parser.rs Normal file
View file

@ -0,0 +1,7 @@
#[test]
fn test_parser() {
// todo
}

6
src/test/subtype.rs Normal file
View file

@ -0,0 +1,6 @@
#[test]
fn test_subtype() {
// todo
}