From e0c6e6f180945a8641a5201702b8dad08b069a6d Mon Sep 17 00:00:00 2001 From: chengyongru Date: Fri, 10 Apr 2026 10:22:50 +0800 Subject: [PATCH] test: add regression tests for tag stripping --- tests/utils/test_strip_think.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/utils/test_strip_think.py diff --git a/tests/utils/test_strip_think.py b/tests/utils/test_strip_think.py new file mode 100644 index 000000000..6710dfc93 --- /dev/null +++ b/tests/utils/test_strip_think.py @@ -0,0 +1,36 @@ +import pytest + +from nanobot.utils.helpers import strip_think + + +class TestStripThinkTag: + """Test ... block stripping (Gemma 4 and similar models).""" + + def test_closed_tag(self): + assert strip_think("Hello reasoning World") == "Hello World" + + def test_unclosed_trailing_tag(self): + assert strip_think("ongoing...") == "" + + def test_multiline_tag(self): + assert strip_think("\nline1\nline2\nEnd") == "End" + + def test_tag_with_nested_angle_brackets(self): + text = "a < 3 and b > 2result" + assert strip_think(text) == "result" + + def test_multiple_tag_blocks(self): + text = "AxByC" + assert strip_think(text) == "ABC" + + def test_tag_only_whitespace_inside(self): + assert strip_think("before after") == "beforeafter" + + def test_self_closing_tag_not_matched(self): + assert strip_think("some text") == "some text" + + def test_normal_text_unchanged(self): + assert strip_think("Just normal text") == "Just normal text" + + def test_empty_string(self): + assert strip_think("") == ""