From e3628221c8dcc567d26d2e46eaf43da97b4f3268 Mon Sep 17 00:00:00 2001 From: Benjamin Rogge Date: Thu, 10 Oct 2024 15:57:18 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20java/parser:=20=F0=9F=A7=AA=20add=20mo?= =?UTF-8?q?re=20test=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/code/java/parser/mod.rs | 1 + src/code/java/parser/tests.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/code/java/parser/mod.rs b/src/code/java/parser/mod.rs index 5607a62..599dcdf 100644 --- a/src/code/java/parser/mod.rs +++ b/src/code/java/parser/mod.rs @@ -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) -> CompilationUnit { let mut iter = tokens.iter().peekable(); let mut compilation_unit = CompilationUnit::new(); diff --git a/src/code/java/parser/tests.rs b/src/code/java/parser/tests.rs index 9f26003..6fa4f19 100644 --- a/src/code/java/parser/tests.rs +++ b/src/code/java/parser/tests.rs @@ -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")); } } \ No newline at end of file