Docs
This commit is contained in:
52
tests/parser/stat/constant.rs
Normal file
52
tests/parser/stat/constant.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use mclangc::{
|
||||
cli::CliArgs,
|
||||
common::{Loc, loc::LocBox},
|
||||
parser::{self, ast::{
|
||||
Ident, Keyword, Number, Punctuation, TokenType, expr::Expr, literal::Literal,
|
||||
statement::{Statement, ConstVar},
|
||||
}},
|
||||
tokeniser::Token, validator::predefined::BuiltinType
|
||||
};
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_parse_const_stat() {
|
||||
let mut tokens = vec![
|
||||
Token::new_test(TokenType::Keyword(Keyword::Const)),
|
||||
Token::new_test(TokenType::ident("MyConstant")),
|
||||
Token::new_test(TokenType::Punct(Punctuation::Colon)),
|
||||
Token::new_test(TokenType::ident("usize")),
|
||||
Token::new_test(TokenType::Punct(Punctuation::Eq)),
|
||||
Token::new_test(TokenType::number(69, 10, false)),
|
||||
Token::new_test(TokenType::Punct(Punctuation::Semi)),
|
||||
Token::new_test(TokenType::ident("overflow")),
|
||||
Token::new_test(TokenType::ident("overflow")),
|
||||
Token::new_test(TokenType::ident("overflow")),
|
||||
];
|
||||
tokens.reverse();
|
||||
let res = parser::stat::parse_statement(&mut tokens, &CliArgs::default(), &mut super::get_prog());
|
||||
assert!(res.is_ok(), "{res:?}");
|
||||
|
||||
match res {
|
||||
Ok(res) => {
|
||||
assert!(res.is_some(), "{res:?}");
|
||||
match res {
|
||||
Some(res) => {
|
||||
assert_eq!(res.inner().clone(), Statement::ConstVar(ConstVar {
|
||||
name: Ident::new("MyConstant"),
|
||||
typ: LocBox::new(&Loc::default(), BuiltinType::usize()),
|
||||
val: LocBox::new(&Loc::default(), Expr::Literal(String::new(), Literal::Number(Number { val: 69, base: 10, signed: false })))
|
||||
}));
|
||||
}
|
||||
None => unreachable!()
|
||||
}
|
||||
|
||||
}
|
||||
Err(_) => unreachable!()
|
||||
}
|
||||
assert!(tokens.len() == 3, "leftover token count incorrect");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user