move tests into separate files
This commit is contained in:
parent
2f26dcc936
commit
358ad4d147
7 changed files with 154 additions and 129 deletions
132
src/lib.rs
132
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("<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
6
src/test/curry.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
#[test]
|
||||
fn test_curry() {
|
||||
// todo
|
||||
}
|
||||
|
119
src/test/lexer.rs
Normal file
119
src/test/lexer.rs
Normal 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
6
src/test/lnf.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
#[test]
|
||||
fn test_lnf() {
|
||||
// todo
|
||||
}
|
||||
|
7
src/test/mod.rs
Normal file
7
src/test/mod.rs
Normal 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
7
src/test/parser.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
#[test]
|
||||
fn test_parser() {
|
||||
// todo
|
||||
}
|
||||
|
||||
|
6
src/test/subtype.rs
Normal file
6
src/test/subtype.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
#[test]
|
||||
fn test_subtype() {
|
||||
// todo
|
||||
}
|
||||
|
Loading…
Reference in a new issue