Skip to content

Commit

Permalink
chore: java/parser: 🧪 add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
plastic-karma committed Oct 10, 2024
1 parent 17e4806 commit e362822
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/code/java/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::code::java::tokenizer::TokenType::{Keyword, Identifier};
#[cfg(test)]
mod tests;

/// Parses a vector of tokens into a compilation unit
fn parse(tokens: &Vec<Token>) -> CompilationUnit {
let mut iter = tokens.iter().peekable();
let mut compilation_unit = CompilationUnit::new();
Expand Down
17 changes: 17 additions & 0 deletions src/code/java/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,24 @@ mod tests {
class return {
int i = 3;
}"#);
parse(&tokens);
}

#[test]
fn test_multiple_clases() {
let tokens = tokenize(r#"
import java.util.List;
class Test {
int i = 3;
}
class Test2 {
int i = 3;
}"#);
let compilation_unit = parse(&tokens);

assert_eq!(compilation_unit.classes.len(), 2);
assert!(compilation_unit.classes.iter().any(|class| class.name == "Test"));
assert!(compilation_unit.classes.iter().any(|class| class.name == "Test2"));
}

}

0 comments on commit e362822

Please sign in to comment.