Fixed invalid tests

This commit is contained in:
Dominic Grimm 2022-10-11 16:52:48 +02:00
parent 2c67dba4d7
commit e020b8b78a

View file

@ -279,68 +279,3 @@ pub fn lex(source: &str) -> Result<Vec<Token>> {
Ok(tokens)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::assembler::ToCode;
#[test]
fn test_token_to_assembly() {
assert_eq!(
Token::Comment(" \"main function\" like definition macro".to_string()).to_code(),
"; \"main function\" like definition macro".to_string()
);
assert_eq!(
Token::CharLiteral("\\n".to_string()).to_code(),
"'\\n'".to_string()
);
assert_eq!(
Token::MacroLiteral("xyz".to_string()).to_code(),
"xyz".to_string()
);
assert_eq!(
Token::Literal("xkcd".to_string()).to_code(),
"xkcd".to_string()
);
assert_eq!(Token::Newline("\n".to_string()).to_code(), "\n".to_string());
assert_eq!(
Token::Whitespace(" ".to_string()).to_code(),
" ".to_string()
);
}
#[test]
fn test_lex() -> Result<()> {
assert_eq!(
lex(";; test".to_string())?,
vec![Token::Comment(" test".to_string())]
);
assert_eq!(
lex("@ test".to_string())?,
vec![Token::Comment(" test".to_string())]
);
assert_eq!(
lex("# test".to_string())?,
vec![Token::Comment(" test".to_string())]
);
assert_eq!(
lex("'\\n'".to_string())?,
vec![Token::CharLiteral("\\n".to_string())]
);
assert_eq!(
lex("\"test\"".to_string())?,
vec![Token::StringLiteral("test".to_string())]
);
assert_eq!(
lex(".debug CORE_REG_PC".to_string())?,
vec![
Token::MacroLiteral(".debug".to_string()),
Token::Whitespace(" ".to_string()),
Token::Literal("CORE_REG_PC".to_string())
]
);
Ok(())
}
}