221 lines
8.5 KiB
C++
221 lines
8.5 KiB
C++
module;
|
|
|
|
export module lsp.test.lsp_any.common;
|
|
|
|
import std;
|
|
import lsp.test.framework;
|
|
import lsp.protocol.common.basic_types;
|
|
import lsp.codec.common;
|
|
|
|
export namespace lsp::test
|
|
{
|
|
namespace transform = lsp::codec;
|
|
|
|
class CommonTests
|
|
{
|
|
public:
|
|
static void registerTests(TestRunner& runner);
|
|
|
|
private:
|
|
static TestResult testIsLSPBasicInteger();
|
|
static TestResult testIsLSPBasicUInteger();
|
|
static TestResult testIsLSPBasicBoolean();
|
|
static TestResult testIsLSPBasicString();
|
|
static TestResult testIsLSPBasicDecimal();
|
|
static TestResult testIsLSPBasicNullptr();
|
|
static TestResult testIsLSPBasicNegativeCases();
|
|
|
|
static TestResult testIsLSPContainerObject();
|
|
static TestResult testIsLSPContainerArray();
|
|
static TestResult testIsLSPContainerAny();
|
|
static TestResult testIsLSPContainerNegativeCases();
|
|
|
|
static TestResult testIsUserStructPositive();
|
|
static TestResult testIsUserStructExcludeArithmetic();
|
|
static TestResult testIsUserStructExcludeString();
|
|
static TestResult testIsUserStructExcludeLSPTypes();
|
|
static TestResult testIsUserStructExcludeVector();
|
|
static TestResult testIsUserStructExcludeMap();
|
|
static TestResult testIsUserStructExcludeOptional();
|
|
static TestResult testIsUserStructExcludeVariant();
|
|
static TestResult testIsUserStructExcludePointers();
|
|
};
|
|
}
|
|
|
|
namespace lsp::test
|
|
{
|
|
struct UserStruct
|
|
{
|
|
int value;
|
|
std::string name;
|
|
};
|
|
|
|
void CommonTests::registerTests(TestRunner& runner)
|
|
{
|
|
runner.addTest("Common - is_lsp_basic_type (integer)", testIsLSPBasicInteger);
|
|
runner.addTest("Common - is_lsp_basic_type (uinteger)", testIsLSPBasicUInteger);
|
|
runner.addTest("Common - is_lsp_basic_type (boolean)", testIsLSPBasicBoolean);
|
|
runner.addTest("Common - is_lsp_basic_type (string)", testIsLSPBasicString);
|
|
runner.addTest("Common - is_lsp_basic_type (decimal)", testIsLSPBasicDecimal);
|
|
runner.addTest("Common - is_lsp_basic_type (nullptr_t)", testIsLSPBasicNullptr);
|
|
runner.addTest("Common - is_lsp_basic_type (负面案例)", testIsLSPBasicNegativeCases);
|
|
|
|
runner.addTest("Common - is_lsp_container_type (LSPObject)", testIsLSPContainerObject);
|
|
runner.addTest("Common - is_lsp_container_type (LSPArray)", testIsLSPContainerArray);
|
|
runner.addTest("Common - is_lsp_container_type (LSPAny)", testIsLSPContainerAny);
|
|
runner.addTest("Common - is_lsp_container_type (负面案例)", testIsLSPContainerNegativeCases);
|
|
|
|
runner.addTest("Common - is_user_struct (用户结构体)", testIsUserStructPositive);
|
|
runner.addTest("Common - is_user_struct (排除算术类型)", testIsUserStructExcludeArithmetic);
|
|
runner.addTest("Common - is_user_struct (排除字符串)", testIsUserStructExcludeString);
|
|
runner.addTest("Common - is_user_struct (排除LSP类型)", testIsUserStructExcludeLSPTypes);
|
|
runner.addTest("Common - is_user_struct (排除vector)", testIsUserStructExcludeVector);
|
|
runner.addTest("Common - is_user_struct (排除map)", testIsUserStructExcludeMap);
|
|
runner.addTest("Common - is_user_struct (排除optional)", testIsUserStructExcludeOptional);
|
|
runner.addTest("Common - is_user_struct (排除variant)", testIsUserStructExcludeVariant);
|
|
runner.addTest("Common - is_user_struct (排除指针)", testIsUserStructExcludePointers);
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicInteger()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_basic_type_v<protocol::integer>, "integer应该是LSP基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicUInteger()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_basic_type_v<protocol::uinteger>, "uinteger应该是LSP基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicBoolean()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_basic_type_v<protocol::boolean>, "boolean应该是LSP基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicString()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_basic_type_v<protocol::string>, "string应该是LSP基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicDecimal()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_basic_type_v<protocol::decimal>, "decimal应该是LSP基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicNullptr()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_basic_type_v<std::nullptr_t>, "nullptr应该是LSP基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPBasicNegativeCases()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_lsp_basic_type_v<std::vector<int>>, "vector<int>不应是基本类型");
|
|
assertFalse(transform::is_lsp_basic_type_v<UserStruct>, "用户结构体不应是基本类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPContainerObject()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_container_type_v<protocol::LSPObject>, "LSPObject应该是容器类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPContainerArray()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_container_type_v<protocol::LSPArray>, "LSPArray应该是容器类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPContainerAny()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_lsp_container_type_v<protocol::LSPAny>, "LSPAny应该是容器类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsLSPContainerNegativeCases()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_lsp_container_type_v<int>, "int不是容器类型");
|
|
assertFalse(transform::is_lsp_container_type_v<std::vector<int>>, "vector<int>不是容器类型");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructPositive()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertTrue(transform::is_user_struct_v<UserStruct>, "UserStruct应该被识别为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeArithmetic()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<int>, "int不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeString()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<std::string>, "string不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeLSPTypes()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<protocol::LSPAny>, "LSPAny不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeVector()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<std::vector<int>>, "vector不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeMap()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<std::map<std::string, int>>, "map不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeOptional()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<std::optional<int>>, "optional不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludeVariant()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<std::variant<int, double>>, "variant不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
|
|
TestResult CommonTests::testIsUserStructExcludePointers()
|
|
{
|
|
TestResult result{ "", true, "成功" };
|
|
assertFalse(transform::is_user_struct_v<int*>, "指针不应被视为用户结构体");
|
|
return result;
|
|
}
|
|
}
|