From 6cb8d0dd32b657b3b200c36912257ffbe88cb3fe Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 7 Nov 2025 12:10:41 +0800 Subject: [PATCH] + [misc] Add unit tests for searchTao::unify() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/search/test/lib/tao.class.php | 15 +++++++++++ module/search/test/tao/unify.php | 37 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 module/search/test/tao/unify.php diff --git a/module/search/test/lib/tao.class.php b/module/search/test/lib/tao.class.php index ea9e657a14..0f8a9dc741 100644 --- a/module/search/test/lib/tao.class.php +++ b/module/search/test/lib/tao.class.php @@ -328,4 +328,19 @@ class searchTaoTest extends baseTest if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test unify method. + * + * @param string $string + * @param string $to + * @access public + * @return string + */ + public function unifyTest(string $string, string $to = ','): string + { + $result = $this->invokeArgs('unify', [$string, $to]); + if(dao::isError()) return dao::getError(); + return $result; + } } diff --git a/module/search/test/tao/unify.php b/module/search/test/tao/unify.php new file mode 100755 index 0000000000..0a973279a8 --- /dev/null +++ b/module/search/test/tao/unify.php @@ -0,0 +1,37 @@ +#!/usr/bin/env php +unifyTest('hello_world、test-data')) && p() && e('hello,world,test,data'); // 测试将多种特殊符号统一替换为逗号 +r($searchTest->unifyTest('hello_world、test-data', ' ')) && p() && e('hello world test data'); // 测试将特殊符号替换为空格 +r($searchTest->unifyTest('hello___world', ',')) && p() && e('hello,world'); // 测试将多个连续符号合并为一个 +r($searchTest->unifyTest('_hello、world-test_', ',')) && p() && e('hello,world,test'); // 测试去除首尾的目标符号 +r($searchTest->unifyTest('你好、世界。测试')) && p() && e('你好,世界,测试'); // 测试包含中文标点的字符串替换 +r($searchTest->unifyTest('')) && p() && e('0'); // 测试空字符串输入 +r($searchTest->unifyTest('_、-。,', ',')) && p() && e('0'); // 测试仅包含特殊符号的字符串 \ No newline at end of file