2021-08-29 20:19:12 +00:00
|
|
|
/*
|
2021-09-01 02:32:46 +00:00
|
|
|
* Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
|
2021-08-29 20:19:12 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2021-08-29 20:19:12 +00:00
|
|
|
#include <AK/JsonArray.h>
|
|
|
|
#include <AK/JsonObject.h>
|
|
|
|
#include <AK/JsonParser.h>
|
2023-02-09 02:02:46 +00:00
|
|
|
#include <LibCore/File.h>
|
2021-08-29 20:19:12 +00:00
|
|
|
#include <LibMarkdown/Document.h>
|
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
#include <LibTest/TestSuite.h>
|
|
|
|
|
|
|
|
TEST_SETUP
|
|
|
|
{
|
2023-02-09 02:02:46 +00:00
|
|
|
auto file_or_error = Core::File::open("/home/anon/Tests/commonmark.spec.json"sv, Core::File::OpenMode::Read);
|
2022-03-10 13:45:14 +00:00
|
|
|
if (file_or_error.is_error())
|
2023-02-09 02:02:46 +00:00
|
|
|
file_or_error = Core::File::open("./commonmark.spec.json"sv, Core::File::OpenMode::Read);
|
2022-03-10 13:45:14 +00:00
|
|
|
VERIFY(!file_or_error.is_error());
|
|
|
|
auto file = file_or_error.release_value();
|
|
|
|
auto file_size = MUST(file->size());
|
|
|
|
auto content = MUST(ByteBuffer::create_uninitialized(file_size));
|
2023-03-01 14:27:35 +00:00
|
|
|
MUST(file->read_until_filled(content.bytes()));
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString test_data { content.bytes() };
|
2021-08-29 20:19:12 +00:00
|
|
|
|
|
|
|
auto tests = JsonParser(test_data).parse().value().as_array();
|
|
|
|
for (size_t i = 0; i < tests.size(); ++i) {
|
|
|
|
auto testcase = tests[i].as_object();
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
auto name = ByteString::formatted("{}_ex{}_{}..{}",
|
2022-12-21 14:42:45 +00:00
|
|
|
testcase.get("section"sv).value(),
|
|
|
|
testcase.get("example"sv).value(),
|
|
|
|
testcase.get("start_line"sv).value(),
|
|
|
|
testcase.get("end_line"sv).value());
|
2021-08-29 20:19:12 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString markdown = testcase.get_byte_string("markdown"sv).value();
|
|
|
|
ByteString html = testcase.get_byte_string("html"sv).value();
|
2021-08-29 20:19:12 +00:00
|
|
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
}
|