Tests: Add a test for markdown image sizes
This commit is contained in:
parent
8140b1fa18
commit
bcf0e879d3
Notes:
sideshowbarker
2024-07-17 08:27:14 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/bcf0e879d3 Pull-request: https://github.com/SerenityOS/serenity/pull/14764 Reviewed-by: https://github.com/petelliott ✅
2 changed files with 40 additions and 0 deletions
|
@ -2,6 +2,7 @@ include(commonmark_spec)
|
|||
|
||||
set(TEST_SOURCES
|
||||
TestCommonmark.cpp
|
||||
TestImageSizeExtension.cpp
|
||||
)
|
||||
|
||||
foreach(source IN LISTS TEST_SOURCES)
|
||||
|
|
39
Tests/LibMarkdown/TestImageSizeExtension.cpp
Normal file
39
Tests/LibMarkdown/TestImageSizeExtension.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <LibMarkdown/Document.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
struct TestCase {
|
||||
StringView markdown;
|
||||
StringView expected_html;
|
||||
};
|
||||
|
||||
static constexpr Array image_size_tests {
|
||||
// No image size:
|
||||
TestCase { .markdown = ""sv, .expected_html = R"(<p><img src="foo.png" alt="" ></p>)"sv },
|
||||
// Only width given:
|
||||
TestCase { .markdown = ""sv, .expected_html = R"(<p><img src="foo.png" style="width: 100px;" alt="" ></p>)"sv },
|
||||
// Only height given:
|
||||
TestCase { .markdown = ""sv, .expected_html = R"(<p><img src="foo.png" style="height: 200px;" alt="" ></p>)"sv },
|
||||
// Both width and height given
|
||||
TestCase { .markdown = ""sv, .expected_html = R"(<p><img src="foo.png" style="width: 50px;height: 25px;" alt="" ></p>)"sv },
|
||||
// Size contains invalid width
|
||||
TestCase { .markdown = ""sv, .expected_html = R"(<p><img src="foo.png =1oox50" alt="" ></p>)"sv },
|
||||
// Size contains invalid height
|
||||
TestCase { .markdown = ""sv, .expected_html = R"(<p><img src="foo.png =900xfour" alt="" ></p>)"sv },
|
||||
};
|
||||
|
||||
TEST_CASE(test_image_size_markdown_extension)
|
||||
{
|
||||
for (auto const& test_case : image_size_tests) {
|
||||
auto document = Markdown::Document::parse(test_case.markdown);
|
||||
auto raw_rendered_html = document->render_to_inline_html();
|
||||
auto rendered_html = StringView(raw_rendered_html).trim_whitespace();
|
||||
EXPECT_EQ(rendered_html, test_case.expected_html);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue