diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 17:32:03 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 17:32:03 +0200 |
| commit | 668fa02f46bf7d22703b98d431ac48f2c07bc090 (patch) | |
| tree | 501f92cb9178fa18e02efda3cd449eb7ae97f109 | |
| parent | 5a738121c04989e1bdcb728347f12e677adf3bd4 (diff) | |
| download | ele-668fa02f46bf7d22703b98d431ac48f2c07bc090.tar.gz ele-668fa02f46bf7d22703b98d431ac48f2c07bc090.zip | |
Fix Clippy matching and portable filter limit coverage
| -rw-r--r-- | src/lex.rs | 12 | ||||
| -rw-r--r-- | tests/limit_tests.rs | 18 |
2 files changed, 20 insertions, 10 deletions
@@ -323,14 +323,10 @@ impl Lexer { Some(r) if is_white(r) => { self.advance(); } - Some('-') => { - if self.input.get(self.cursor + 1) == Some(&'-') { - self.advance(); - self.advance(); - self.skip_comment(); - } else { - return; - } + Some('-') if self.input.get(self.cursor + 1) == Some(&'-') => { + self.advance(); + self.advance(); + self.skip_comment(); } _ => return, } diff --git a/tests/limit_tests.rs b/tests/limit_tests.rs index a54463b..b3f6575 100644 --- a/tests/limit_tests.rs +++ b/tests/limit_tests.rs @@ -1,4 +1,4 @@ -use aif::parse; +use aif::{parse, parser::MAX_FILTER_BYTES}; use std::process::Command; #[test] @@ -11,7 +11,9 @@ fn excessive_filters_report_errors_without_crashing() { "x ".repeat(300), "x.".repeat(300) + "x", "x AND ".repeat(300) + "x", - "x".repeat(65537), + // Three-byte UTF-8 characters keep the argument below Windows' UTF-16 + // command-line limit while exceeding the filter byte limit. + "界".repeat(MAX_FILTER_BYTES / "界".len() + 1), ]; for filter in filters { let output = Command::new(env!("CARGO_BIN_EXE_aif")) @@ -30,6 +32,18 @@ fn excessive_filters_report_errors_without_crashing() { } #[test] +fn filter_byte_limit_counts_utf8_bytes() { + for character in ["x", "界"] { + let within_limit = character.repeat(MAX_FILTER_BYTES / character.len()); + assert!(parse(&within_limit).is_ok()); + assert_eq!( + parse(&(within_limit + character)).unwrap_err(), + format!("filter exceeds {MAX_FILTER_BYTES} bytes") + ); + } +} + +#[test] fn parser_limits_work_on_a_normal_thread_stack() { std::thread::Builder::new() .stack_size(2 * 1024 * 1024) |
