# ContentDB # Copyright (C) rubenwardy # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from app.utils.minetest_hypertext import html_to_minetest conquer_html = """

Welcome to Conquer, a mod that adds RTS gameplay. It allows players to start Conquer sub-games, where they can place buildings, train units, and fight other players.

Starting or joining a session

You can list running sessions by typing:

/conquer list
new line

another new line

You'll switch into Conquer playing mode, where you will be given buildings that you can place. You'll need to place a keep, which you must protect at all costs.

You may leave a game and return to normal playing mode at anytime by typing:

Conquer GUI

The Conquer GUI is the central place for monitoring your kingdom. Once in a session, you can view it by pressing the inventory key (I), or by punching/right-clicking the keep node.

""" conquer_expected = """ Welcome to Conquer, a mod that adds RTS gameplay. It allows players to start Conquer sub-games, where they can place buildings, train units, and fight other players. Starting or joining a session You can list running sessions by typing: /conquer list new line another new line You'll switch into Conquer playing mode, where you will be given buildings that you can place. You'll need to place a keep, which you must protect at all costs. You may leave a game and return to normal playing mode at anytime by typing: Conquer GUI The Conquer GUI is the central place for monitoring your kingdom. Once in a session, you can view it by pressing the inventory key (I), or by punching/right-clicking the keep node. """ page_url = "https://example.com/a/b/" def test_conquer(): assert html_to_minetest(conquer_html, page_url)["body"].strip() == conquer_expected.strip() def test_images(): html = """ """ expected = "" result = html_to_minetest(html, page_url) assert result["body"].strip() == expected.strip() assert len(result["images"]) == 1 assert result["images"]["image_0"] == "https://example.com/path/to/img.png" def test_images_removed(): html = """ alt """ expected = "Image: alt" result = html_to_minetest(html, page_url, 7, False) assert result["body"].strip() == expected.strip() assert len(result["images"]) == 0 assert result["links"]["image_0"] == "https://example.com/path/to/img.png" def test_links_relative_absolute(): html = """ Relative Absolute Other domain """ expected = "Relative " \ "Absolute " \ "Other domain" result = html_to_minetest(html, page_url, 7, False) assert result["body"].strip() == expected.strip() assert result["links"]["link_0"] == "https://example.com/a/b/relative" assert result["links"]["link_1"] == "https://example.com/absolute" assert result["links"]["link_2"] == "https://www.minetest.net/downloads/" def test_bullets(): html = """ """ expected = "• One\n" \ "• two three\n" \ "• sub one\n" \ "• sub two\n\n" \ "• four\n" result = html_to_minetest(html, page_url) assert result["body"].strip() == expected.strip() def test_table(): html = """
Col ACol BCol C
A1B1C1
A2B2C2
A3B3C3

Heading

Col ACol BCol C
A1B1C1
A2B2C2
A3B3C3
""" expected = "(view table in browser)\n\n" \ "Heading\n" \ "(view table in browser)" result = html_to_minetest(html, page_url) assert result["body"].strip() == expected.strip() assert result["links"]["link_0"] == f"{page_url}#with-id" assert result["links"]["link_1"] == f"{page_url}#heading" def test_inline(): html = """ One two three """ expected = "One two three" result = html_to_minetest(html, page_url) assert result["body"].strip() == expected.strip() def test_escape(): html = r""" One t\w<o> three """ expected = r"One t\\w\ three" result = html_to_minetest(html, page_url) assert result["body"].strip() == expected.strip() def test_unknown_attr(): html = r""" link """ expected = r"link" result = html_to_minetest(html, page_url) assert result["body"].strip() == expected.strip()