diff options
author | MacDue <macdue@dueutil.tech> | 2022-08-03 00:22:08 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-04 02:49:29 +0200 |
commit | bcf0e879d3c6e76fddb8d871cd93d3e60ecd1b9d (patch) | |
tree | 08ae8d01e7f3a75ffefc19f0f01d38b70da9c6c2 /Tests/LibMarkdown/TestImageSizeExtension.cpp | |
parent | 8140b1fa1803f0d4269b45ec1dd01e443017325a (diff) | |
download | serenity-bcf0e879d3c6e76fddb8d871cd93d3e60ecd1b9d.zip |
Tests: Add a test for markdown image sizes
Diffstat (limited to 'Tests/LibMarkdown/TestImageSizeExtension.cpp')
-rw-r--r-- | Tests/LibMarkdown/TestImageSizeExtension.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Tests/LibMarkdown/TestImageSizeExtension.cpp b/Tests/LibMarkdown/TestImageSizeExtension.cpp new file mode 100644 index 0000000000..428dc46d9c --- /dev/null +++ b/Tests/LibMarkdown/TestImageSizeExtension.cpp @@ -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 = "![](foo.png)"sv, .expected_html = R"(<p><img src="foo.png" alt="" ></p>)"sv }, + // Only width given: + TestCase { .markdown = "![](foo.png =100x)"sv, .expected_html = R"(<p><img src="foo.png" style="width: 100px;" alt="" ></p>)"sv }, + // Only height given: + TestCase { .markdown = "![](foo.png =x200)"sv, .expected_html = R"(<p><img src="foo.png" style="height: 200px;" alt="" ></p>)"sv }, + // Both width and height given + TestCase { .markdown = "![](foo.png =50x25)"sv, .expected_html = R"(<p><img src="foo.png" style="width: 50px;height: 25px;" alt="" ></p>)"sv }, + // Size contains invalid width + TestCase { .markdown = "![](foo.png =1oox50)"sv, .expected_html = R"(<p><img src="foo.png =1oox50" alt="" ></p>)"sv }, + // Size contains invalid height + TestCase { .markdown = "![](foo.png =900xfour)"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); + } +} |