Tests: Test LibMarkdown against commonmark test suite

TestCommonmark runs the CommonMark test suite
(https://spec.commonmark.org/0.30/spec.json) against LibMarkdown.
Currently 44/652 tests pass.
This commit is contained in:
Peter Elliott 2021-08-29 13:19:12 -07:00 committed by Andreas Kling
parent 57ec19f963
commit 8d2c04821f
6 changed files with 71 additions and 1 deletions

View file

@ -1,7 +1,7 @@
[Global]
SkipDirectories=Kernel/Legacy
SkipRegex=^ue-.*$
SkipTests=test-web
SkipTests=test-web TestCommonmark
NotTestsPattern=^.*(txt|frm|inc)$
[test-js]

View file

@ -0,0 +1,9 @@
option(ENABLE_COMMONMARK_SPEC_DOWNLOAD "Enable download of commonmark test suite at build time" ON)
set(MARKDOWN_TEST_PATH ${CMAKE_BINARY_DIR}/commonmark.spec.json)
set(MARKDOWN_TEST_URL https://spec.commonmark.org/0.30/spec.json)
if(ENABLE_COMMONMARK_SPEC_DOWNLOAD)
file(DOWNLOAD ${MARKDOWN_TEST_URL} ${MARKDOWN_TEST_PATH})
install(FILES ${MARKDOWN_TEST_PATH} DESTINATION home/anon)
endif()

View file

@ -518,6 +518,14 @@ if (BUILD_LAGOM)
)
set_tests_properties(JS PROPERTIES ENVIRONMENT SERENITY_SOURCE_DIR=${SERENITY_PROJECT_ROOT})
# Markdown
include(${SERENITY_PROJECT_ROOT}/Meta/CMake/commonmark_spec.cmake)
file(GLOB LIBMARKDOWN_TEST_SOURCES CONFIGURE_DEPENDS "../../Tests/LibMarkdown/*.cpp")
foreach(source ${LIBMARKDOWN_TEST_SOURCES})
lagom_test(${source} LIBS LagomMarkdown)
endforeach()
set_tests_properties(TestCommonmark PROPERTIES DISABLED YES)
# test-wasm
add_executable(test-wasm_lagom
../../Tests/LibWasm/test-wasm.cpp

View file

@ -9,6 +9,7 @@ add_subdirectory(LibGfx)
add_subdirectory(LibIMAP)
add_subdirectory(LibJS)
add_subdirectory(LibM)
add_subdirectory(LibMarkdown)
add_subdirectory(LibPthread)
add_subdirectory(LibRegex)
add_subdirectory(LibSQL)

View file

@ -0,0 +1,6 @@
include(${SERENITY_PROJECT_ROOT}/Meta/CMake/commonmark_spec.cmake)
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "*.cpp")
foreach(source ${TEST_SOURCES})
serenity_test(${source} LibMarkdown LIBS LibMarkdown)
endforeach()

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2021, Peter Elliott <pelliott@ualberta.ca>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/String.h>
#include <LibCore/File.h>
#include <LibMarkdown/Document.h>
#include <LibTest/TestCase.h>
#include <LibTest/TestSuite.h>
TEST_SETUP
{
auto file = Core::File::construct("/home/anon/commonmark.spec.json");
if (!file->open(Core::OpenMode::ReadOnly)) {
file = Core::File::construct("./commonmark.spec.json");
VERIFY(file->open(Core::OpenMode::ReadOnly));
}
String test_data(file->read_all(), AK::ShouldChomp::NoChomp);
auto tests = JsonParser(test_data).parse().value().as_array();
for (size_t i = 0; i < tests.size(); ++i) {
auto testcase = tests[i].as_object();
auto name = String::formatted("{}_ex{}_{}..{}",
testcase.get("section"),
testcase.get("example"),
testcase.get("start_line"),
testcase.get("end_line"));
String markdown = testcase.get("markdown").as_string();
String html = testcase.get("html").as_string();
Test::TestSuite::the().add_case(adopt_ref(*new Test::TestCase(
name, [markdown, html]() {
auto document = Markdown::Document::parse(markdown);
EXPECT_EQ(document->render_to_inline_html(), html);
},
false)));
}
}