Files
squirrelVsis/test_error_detection.nut

61 lines
1.6 KiB
Plaintext
Raw Normal View History

2025-09-17 10:54:25 +08:00
// 测试文件 - 用于验证代码错误检测功能
// 正常的字符串 - 应该没有错误
local validString = "This is a valid string";
local validSingleQuote = 'This is also valid';
// 正常的括号 - 应该没有错误
function validFunction() {
local array = [1, 2, 3];
if (array.len() > 0) {
return array[0];
}
return null;
}
// 测试拼写错误 - 应该被检测到并提供修复
functoin badSpelling() { // functoin -> function
loacl x = 10; // loacl -> local
retun x; // retun -> return
}
// 测试赋值操作符错误 - 应该被检测到
function testAssignment() {
local x = 5;
if (x = 10) { // = 应该是 ==
return true;
}
return false;
}
// 测试未闭合的字符串 - 应该被检测到
// local unclosedString = "This string is not closed
// 测试未闭合的括号 - 应该被检测到
// function unclosedBrackets() {
// local array = [1, 2, 3;
// if (true {
// return false;
// }
// }
// 测试字符串中的引号 - 不应该报错
local stringWithQuotes = "He said 'Hello World'";
local escapedQuotes = "She said \"Hello\" to me";
// 测试括号在字符串中 - 不应该报错
local stringWithBrackets = "Array access: array[0]";
// 测试注释中的内容 - 不应该报错
// This is a comment with "unclosed string and (brackets
/*
Multi-line comment with "quotes" and (brackets)
functoin should not be flagged here
*/
// 测试正常的标识符 - 不应该报错
local myVariable = 100;
local MAX_COUNT = 50;
local getUserName = function() { return "user"; };
local isReady = true;
local hasPermission = false;