From 0643e57e0bad4d699bdec2cbee0e502ec62236a2 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Mon, 2 Oct 2023 16:04:25 -0700 Subject: [PATCH] fix: add a regression test cased for stop words regex matching --- crates/tabby-inference/src/decoding.rs | 14 ++++++++++++++ crates/tabby/src/serve/completions/languages.rs | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/tabby-inference/src/decoding.rs b/crates/tabby-inference/src/decoding.rs index 78cb1a764de0..dfb93a28be3f 100644 --- a/crates/tabby-inference/src/decoding.rs +++ b/crates/tabby-inference/src/decoding.rs @@ -121,3 +121,17 @@ impl IncrementalDecoding { Some(new_text.to_owned()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_it_should_not_match() { + let stop_words = vec!["\n\n", "\n\n "]; + let re = create_stop_regex(&stop_words); + let text = reverse("void write_u32(std::uint32_t val) const {\n write_raw(&val, sizeof(val));\n }\n\n ~llama_file() {\n if (fp) {\n std::fclose(fp);\n }\n }\n};\n\nvoid"); + let matched = re.find(&text).is_some(); + assert!(!matched); + } +} diff --git a/crates/tabby/src/serve/completions/languages.rs b/crates/tabby/src/serve/completions/languages.rs index eed3325f6f85..8dbe04fdfede 100644 --- a/crates/tabby/src/serve/completions/languages.rs +++ b/crates/tabby/src/serve/completions/languages.rs @@ -12,7 +12,6 @@ lazy_static! { "\n\n ", "\n\n ", "\n\n ", - "\n\n", "\n\n\t", "\n\n\t\t", "\n\n\t\t\t",