test(lsp_server): update test scripts and tsf cases

This commit is contained in:
csh 2026-01-08 15:51:54 +08:00
parent b2a1bb6685
commit f056b0cad1
3 changed files with 34 additions and 5 deletions

View File

@ -21,14 +21,13 @@ find_test_ast() {
if [ ! -d "$search_dir" ]; then if [ ! -d "$search_dir" ]; then
return 1 return 1
fi fi
find "$search_dir" -type f -name test_ast -path "*/test/test_ast/*" -print -quit 2>/dev/null find "$search_dir" -type f -name test_ast \( -path "*/test/test_ast" -o -path "*/test/test_ast/*" \) -print -quit 2>/dev/null
} }
TEST_AST="${TEST_AST_OVERRIDE:-$(find_test_ast "$REPO_ROOT/build/$BUILD_PRESET")}"
# 需要测试的目录列表(可以自行添加) # 需要测试的目录列表(可以自行添加)
DIRECTORIES=( DIRECTORIES=(
"$REPO_ROOT/test/test_tree_sitter/test" "$REPO_ROOT/test/test_tree_sitter/test"
"$HOME/windows_share/tsf"
# "./another_directory" # "./another_directory"
) )
@ -86,6 +85,9 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
# 解析参数后再定位 test_ast
TEST_AST="${TEST_AST_OVERRIDE:-$(find_test_ast "$REPO_ROOT/build/$BUILD_PRESET")}"
# 检查 test_ast 是否存在 # 检查 test_ast 是否存在
if [ -z "$TEST_AST" ] || [ ! -f "$TEST_AST" ]; then if [ -z "$TEST_AST" ] || [ ! -f "$TEST_AST" ]; then
echo -e "${RED}错误: 找不到 test_ast 可执行文件${NC}" echo -e "${RED}错误: 找不到 test_ast 可执行文件${NC}"

View File

@ -19,16 +19,16 @@ find_test_symbol() {
return 1 return 1
fi fi
find "$search_dir" -type f -name test_symbol -path "*/test/test_symbol/*" -print -quit 2>/dev/null find "$search_dir" -type f -name test_symbol \( -path "*/test/test_symbol" -o -path "*/test/test_symbol/*" \) -print -quit 2>/dev/null
} }
BUILD_PRESET=${BUILD_PRESET:-clang-ninja} BUILD_PRESET=${BUILD_PRESET:-clang-ninja}
TEST_SYMBOL="${TEST_SYMBOL_OVERRIDE:-$(find "$REPO_ROOT/build/$BUILD_PRESET" -type f -name test_symbol -path "*/test/test_symbol/*" -print -quit 2>/dev/null)}"
IGNORES=("IDS_AuditExpr.tsf") IGNORES=("IDS_AuditExpr.tsf")
# 需要测试的目录列表(可以自行添加) # 需要测试的目录列表(可以自行添加)
DIRECTORIES=( DIRECTORIES=(
"$REPO_ROOT/test/test_tree_sitter/test" "$REPO_ROOT/test/test_tree_sitter/test"
"$HOME/windows_share/tsf"
# "./another_directory" # "./another_directory"
) )
@ -86,6 +86,9 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
# 解析参数后再定位 test_symbol
TEST_SYMBOL="${TEST_SYMBOL_OVERRIDE:-$(find_test_symbol "$REPO_ROOT/build/$BUILD_PRESET")}"
# 检查 test_symbol 是否存在 # 检查 test_symbol 是否存在
if [ -z "$TEST_SYMBOL" ] || [ ! -f "$TEST_SYMBOL" ]; then if [ -z "$TEST_SYMBOL" ] || [ ! -f "$TEST_SYMBOL" ]; then
echo -e "${RED}错误: 找不到 test_symbol 可执行文件${NC}" echo -e "${RED}错误: 找不到 test_symbol 可执行文件${NC}"

View File

@ -708,6 +708,14 @@ else
echo " ❌ if语句解析失败" echo " ❌ if语句解析失败"
fi fi
echo "12.1.1 test if without semicolon before else"
echo 'function test(); begin if a > b then x := a else x := b; end;' | tree-sitter parse > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo " ✅ if (no semicolon) parsed"
else
echo " ❌ if (no semicolon) parse failed"
fi
echo "12.2 测试复杂if语句" echo "12.2 测试复杂if语句"
cat > temp_if_test.tsf << 'EOF' cat > temp_if_test.tsf << 'EOF'
function test(); function test();
@ -763,6 +771,14 @@ else
echo " ❌ for循环解析失败" echo " ❌ for循环解析失败"
fi fi
echo "12.4.1 test for body without semicolon"
echo 'function test(); begin for i:=0 to 10 do x += 1 end;' | tree-sitter parse > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo " ✅ for (no semicolon) parsed"
else
echo " ❌ for (no semicolon) parse failed"
fi
echo "12.5 测试for...to循环" echo "12.5 测试for...to循环"
echo 'function test(); begin for i:=0 to 10 do x := i; end;' | tree-sitter parse > /dev/null 2>&1 echo 'function test(); begin for i:=0 to 10 do x := i; end;' | tree-sitter parse > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
@ -779,6 +795,14 @@ else
echo " ❌ while循环解析失败" echo " ❌ while循环解析失败"
fi fi
echo "12.6.1 test while body without semicolon"
echo 'function test(); begin while x > 0 do x := x - 1 end;' | tree-sitter parse > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo " ✅ while (no semicolon) parsed"
else
echo " ❌ while (no semicolon) parse failed"
fi
echo "12.7 测试repeat循环" echo "12.7 测试repeat循环"
echo 'function test(); begin repeat x := x + 1; until x > 10; end;' | tree-sitter parse > /dev/null 2>&1 echo 'function test(); begin repeat x := x + 1; until x > 10; end;' | tree-sitter parse > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then