Tighten XCUI schema consistency rules
This commit is contained in:
@@ -18,6 +18,31 @@ void WriteTextFile(const std::filesystem::path& path, const std::string& content
|
||||
ASSERT_TRUE(static_cast<bool>(output));
|
||||
}
|
||||
|
||||
void ExpectSchemaCompileFailure(
|
||||
const char* testFolderName,
|
||||
const char* markup,
|
||||
const char* expectedMessageFragment) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
const fs::path root = fs::temp_directory_path() / testFolderName;
|
||||
const fs::path schemaPath = root / "invalid.xcschema";
|
||||
fs::remove_all(root);
|
||||
|
||||
WriteTextFile(schemaPath, markup);
|
||||
|
||||
UISchemaLoader loader;
|
||||
UIDocumentCompileResult compileResult = {};
|
||||
EXPECT_FALSE(loader.CompileDocument(schemaPath.string().c_str(), compileResult));
|
||||
EXPECT_FALSE(compileResult.succeeded);
|
||||
EXPECT_FALSE(compileResult.errorMessage.Empty());
|
||||
ASSERT_FALSE(compileResult.document.diagnostics.Empty());
|
||||
|
||||
const std::string errorMessage = compileResult.errorMessage.CStr();
|
||||
EXPECT_NE(errorMessage.find(expectedMessageFragment), std::string::npos);
|
||||
|
||||
fs::remove_all(root);
|
||||
}
|
||||
|
||||
TEST(UISchemaDocument, CompileAndArtifactLoadPopulateSchemaDefinition) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -150,4 +175,48 @@ TEST(UISchemaDocument, CompileRejectsDuplicateAttributeDefinitions) {
|
||||
fs::remove_all(root);
|
||||
}
|
||||
|
||||
TEST(UISchemaDocument, CompileRejectsAllowedValuesOnNonEnumAttribute) {
|
||||
ExpectSchemaCompileFailure(
|
||||
"xc_ui_schema_allowed_values_non_enum_test",
|
||||
"<Schema>\n"
|
||||
" <Element tag=\"View\">\n"
|
||||
" <Attribute name=\"gap\" type=\"number\" allowedValues=\"8,12\" />\n"
|
||||
" </Element>\n"
|
||||
"</Schema>\n",
|
||||
"allowedValues");
|
||||
}
|
||||
|
||||
TEST(UISchemaDocument, CompileRejectsDocumentKindOnNonDocumentAttribute) {
|
||||
ExpectSchemaCompileFailure(
|
||||
"xc_ui_schema_document_kind_non_document_test",
|
||||
"<Schema>\n"
|
||||
" <Element tag=\"View\">\n"
|
||||
" <Attribute name=\"id\" type=\"string\" documentKind=\"theme\" />\n"
|
||||
" </Element>\n"
|
||||
"</Schema>\n",
|
||||
"documentKind");
|
||||
}
|
||||
|
||||
TEST(UISchemaDocument, CompileRejectsRestrictDocumentKindOnNonDocumentAttribute) {
|
||||
ExpectSchemaCompileFailure(
|
||||
"xc_ui_schema_restrict_non_document_test",
|
||||
"<Schema>\n"
|
||||
" <Element tag=\"View\">\n"
|
||||
" <Attribute name=\"id\" type=\"string\" restrictDocumentKind=\"true\" />\n"
|
||||
" </Element>\n"
|
||||
"</Schema>\n",
|
||||
"restrictDocumentKind");
|
||||
}
|
||||
|
||||
TEST(UISchemaDocument, CompileRejectsRestrictDocumentKindWithoutExplicitDocumentKind) {
|
||||
ExpectSchemaCompileFailure(
|
||||
"xc_ui_schema_restrict_without_kind_test",
|
||||
"<Schema>\n"
|
||||
" <Element tag=\"View\">\n"
|
||||
" <Attribute name=\"theme\" type=\"document\" restrictDocumentKind=\"true\" />\n"
|
||||
" </Element>\n"
|
||||
"</Schema>\n",
|
||||
"must declare 'documentKind'");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user