[misc] add unit test:trimsemicolon.

This commit is contained in:
qixinzhi
2024-10-16 10:07:02 +08:00
committed by 宋辰轩
parent cebca4b761
commit 32fd260553
2 changed files with 37 additions and 1 deletions
+1 -1
View File
@@ -804,7 +804,7 @@ class pivotModel extends model
*/
public function trimSemicolon(string $sql): string
{
return str_replace(';', '', $sql);
return trim($sql, " ;");
}
/**
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php
/**
title=测试 pivotModel->trimSemicolon().
timeout=0
cid=1
- 测试末尾存在分号。 @select id,name from zt_project
- 测试末尾存在空格。 @select id,name from zt_project
- 测试末尾存在多个分号。 @select id,name from zt_project
- 测试末尾存在多个空格。 @select id,name from zt_project
- 测试末尾存在分号和空格。 @select id,name from zt_project
- 测试末尾存在空格和分号。 @select id,name from zt_project
*/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/pivot.unittest.class.php';
$pivot = new pivotTest();
$sql = 'select id,name from zt_user;;;;;;;;;;;;';
r($pivot->trimSemicolon('select id,name from zt_project;')) && p() && e('select id,name from zt_project'); // 测试末尾存在分号。
r($pivot->trimSemicolon('select id,name from zt_project ')) && p() && e('select id,name from zt_project'); // 测试末尾存在空格。
r($pivot->trimSemicolon('select id,name from zt_project;;;')) && p() && e('select id,name from zt_project'); // 测试末尾存在多个分号。
r($pivot->trimSemicolon('select id,name from zt_project ')) && p() && e('select id,name from zt_project'); // 测试末尾存在多个空格。
r($pivot->trimSemicolon('select id,name from zt_project; ')) && p() && e('select id,name from zt_project'); // 测试末尾存在分号和空格。
r($pivot->trimSemicolon('select id,name from zt_project ;')) && p() && e('select id,name from zt_project'); // 测试末尾存在空格和分号。