Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html2/test: Migrate to etest2 #1123

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions html2/character_reference_test.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
// SPDX-FileCopyrightText: 2022 Robin Lindén <[email protected]>
// SPDX-FileCopyrightText: 2022-2024 Robin Lindén <[email protected]>
//
// SPDX-License-Identifier: BSD-2-Clause

#include "html2/character_reference.h"

#include "etest/etest.h"
#include "etest/etest2.h"

#include <string_view>

using namespace std::literals;

using etest::expect;
using etest::require;

using namespace html2;

int main() {
etest::test("no entity found", [] {
etest::Suite s;
s.add_test("no entity found", [](etest::IActions &a) {
auto ref = find_named_character_reference_for("A"sv);
expect(!ref.has_value());
a.expect(!ref.has_value());
});

etest::test("single-codepoint entity", [] {
s.add_test("single-codepoint entity", [](etest::IActions &a) {
auto ref = find_named_character_reference_for("&lt"sv);
require(ref.has_value());
expect(ref->name == "&lt"sv);
expect(ref->first_codepoint == '<');
expect(!ref->second_codepoint.has_value());
a.require(ref.has_value());
a.expect(ref->name == "&lt"sv);
a.expect(ref->first_codepoint == '<');
a.expect(!ref->second_codepoint.has_value());
});

etest::test("double-codepoint entity", [] {
s.add_test("double-codepoint entity", [](etest::IActions &a) {
auto ref = find_named_character_reference_for("&NotSucceedsEqual;"sv);
require(ref.has_value());
expect(ref->name == "&NotSucceedsEqual;"sv);
expect(ref->first_codepoint == 0x02AB0u);
expect(ref->second_codepoint == 0x00338u);
a.require(ref.has_value());
a.expect(ref->name == "&NotSucceedsEqual;"sv);
a.expect(ref->first_codepoint == 0x02AB0u);
a.expect(ref->second_codepoint == 0x00338u);
});

etest::test("longest prefix is chosen", [] {
s.add_test("longest prefix is chosen", [](etest::IActions &a) {
auto ref = find_named_character_reference_for("&lt;"sv);
require(ref.has_value());
expect(ref->name == "&lt;"sv); // And not &lt which also matches.
a.require(ref.has_value());
a.expect(ref->name == "&lt;"sv); // And not &lt which also matches.
});

etest::test("extra characters are ignored", [] {
s.add_test("extra characters are ignored", [](etest::IActions &a) {
auto ref = find_named_character_reference_for("&lt;&lt;&abc;123"sv);
require(ref.has_value());
expect(ref->name == "&lt;"sv);
a.require(ref.has_value());
a.expect(ref->name == "&lt;"sv);
});

return etest::run_all_tests();
return s.run();
}
Loading