Skip to content

Commit

Permalink
html2/test: Migrate to etest2
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Dec 9, 2024
1 parent 7837632 commit 146b117
Show file tree
Hide file tree
Showing 4 changed files with 723 additions and 720 deletions.
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

0 comments on commit 146b117

Please sign in to comment.