Serenity Operating System
at master 48 lines 1.8 kB view raw
1/* 2 * Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <AK/DeprecatedString.h> 8#include <AK/JsonArray.h> 9#include <AK/JsonObject.h> 10#include <AK/JsonParser.h> 11#include <LibCore/File.h> 12#include <LibMarkdown/Document.h> 13#include <LibTest/TestCase.h> 14#include <LibTest/TestSuite.h> 15 16TEST_SETUP 17{ 18 auto file_or_error = Core::File::open("/home/anon/Tests/commonmark.spec.json"sv, Core::File::OpenMode::Read); 19 if (file_or_error.is_error()) 20 file_or_error = Core::File::open("./commonmark.spec.json"sv, Core::File::OpenMode::Read); 21 VERIFY(!file_or_error.is_error()); 22 auto file = file_or_error.release_value(); 23 auto file_size = MUST(file->size()); 24 auto content = MUST(ByteBuffer::create_uninitialized(file_size)); 25 MUST(file->read_until_filled(content.bytes())); 26 DeprecatedString test_data { content.bytes() }; 27 28 auto tests = JsonParser(test_data).parse().value().as_array(); 29 for (size_t i = 0; i < tests.size(); ++i) { 30 auto testcase = tests[i].as_object(); 31 32 auto name = DeprecatedString::formatted("{}_ex{}_{}..{}", 33 testcase.get("section"sv).value(), 34 testcase.get("example"sv).value(), 35 testcase.get("start_line"sv).value(), 36 testcase.get("end_line"sv).value()); 37 38 DeprecatedString markdown = testcase.get_deprecated_string("markdown"sv).value(); 39 DeprecatedString html = testcase.get_deprecated_string("html"sv).value(); 40 41 Test::TestSuite::the().add_case(adopt_ref(*new Test::TestCase( 42 name, [markdown, html]() { 43 auto document = Markdown::Document::parse(markdown); 44 EXPECT_EQ(document->render_to_inline_html(), html); 45 }, 46 false))); 47 } 48}