use mclangc::{ cli::CliArgs, common::{Loc, loc::LocBox}, parser::{self, ast::{ Ident, Keyword, Number, Punctuation, TokenType, expr::Expr, literal::Literal, statement::{Statement, StaticVar}, }}, tokeniser::Token, validator::predefined::BuiltinType }; #[test] fn test_parse_static_stat() { let mut tokens = vec![ Token::new_test(TokenType::Keyword(Keyword::Static)), Token::new_test(TokenType::ident("MyStatic")), 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::StaticVar(StaticVar { name: Ident::new("MyStatic"), 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"); }