Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown: Ensure all markdown fixtures have unique names.

akshatdaltonf2c7e8e80fad
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index 21dcd9683ee..ee43c3bf5aa 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -7,14 +7,14 @@
"text_content": ""
},
{
- "name": "codeblock_hilite",
+ "name": "codeblock_hilite_python",
"input": "Hamlet said:\n~~~~.python \ndef speak(self):\n x = 1\n~~~~",
"expected_output": "<p>Hamlet said:</p>\n<div class=\"codehilite\" data-code-language=\"Python\"><pre><span></span><code><span class=\"k\">def</span> <span class=\"nf\">speak</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n <span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"mi\">1</span>\n</code></pre></div>",
"marked_expected_output": "<p>Hamlet said:</p>\n<div class=\"codehilite\" data-code-language=\"Python\"><pre><span></span><code>def speak(self):\n x = 1\n</code></pre></div>",
"text_content": "Hamlet said:\ndef speak(self):\n x = 1\n"
},
{
- "name": "codeblock_hilite",
+ "name": "codeblock_hilite_invented_language",
"input": "``` inventedlanguage\ndef speak(self):\n x = 1\n```",
"expected_output": "<div class=\"codehilite\" data-code-language=\"inventedlanguage\"><pre><span></span><code>def speak(self):\n x = 1\n</code></pre></div>",
"text_content": "def speak(self):\n x = 1\n"
@@ -44,7 +44,7 @@
"text_content": "Hamlet once said\ndef func():\n x = 1\n\n y = 2\n\n z = 3\n\nAnd all was good."
},
{
- "name": "test",
+ "name": "normal_text_test",
"input": "it's lunch time",
"expected_output": "<p>it's lunch time</p>"
},
@@ -79,7 +79,7 @@
"text_content": "Hamlet said:\ndef speak(self):\n x = 1\n# Comment to make this code block longer to test Trac #1162\n\nThen he mentioned y = 4 + x**2 and\ndef foobar(self):\n return self.baz()\n"
},
{
- "name": "fenced_quote",
+ "name": "fenced_normal_quote",
"input": "Hamlet said:\n~~~ quote\nTo be or **not** to be.\n\nThat is the question\n~~~",
"expected_output": "<p>Hamlet said:</p>\n<blockquote>\n<p>To be or <strong>not</strong> to be.</p>\n<p>That is the question</p>\n</blockquote>",
"text_content": "Hamlet said:\n> To be or not to be.\n> That is the question\n"
@@ -91,7 +91,7 @@
"text_content": "Hamlet said:\n> Polonius said:\n> > This above all: to thine ownself be true,\n> > And it must follow, as the night the day,\n> > Thou canst not then be false to any man.\n> What good advice!\n"
},
{
- "name": "complexly_nested_quote",
+ "name": "fenced_complexly_nested_quote",
"input": "I heard about this second hand...\n~~~ quote\n\nHe said:\n~~~ quote\nThe customer is complaining.\n\nThey looked at this code:\n``` \ndef hello(): print 'hello\n```\nThey would prefer:\n~~~\ndef hello()\n puts 'hello'\nend\n~~~\n\nPlease advise.\n~~~\n\nShe said:\n~~~ quote\nJust send them this:\n```\necho \"hello\n\"\n```\n~~~",
"expected_output": "<p>I heard about this second hand...</p>\n<blockquote>\n<p>He said:</p>\n<blockquote>\n<p>The customer is complaining.</p>\n<p>They looked at this code:</p>\n<div class=\"codehilite\"><pre><span></span><code>def hello(): print &#39;hello\n</code></pre></div>\n<p>They would prefer:</p>\n</blockquote>\n<p>def hello()<br>\n puts 'hello'<br>\nend</p>\n</blockquote>\n<p>Please advise.</p>\n<div class=\"codehilite\"><pre><span></span><code>She said:\n~~~ quote\nJust send them this:\n```\necho &quot;hello\n&quot;\n```\n</code></pre></div>",
"text_content": "I heard about this second hand...\n> He said:\n> > The customer is complaining.\n> > They looked at this code:\n> > def hello(): print 'hello\n> > They would prefer:\n> def hello()\n> puts 'hello'\n> end\n\nPlease advise.\nShe said:\n~~~ quote\nJust send them this:\n```\necho \"hello\n\"\n```\n"
@@ -117,12 +117,12 @@
"expected_output": "<blockquote>\n<p>text</p>\n</blockquote>"
},
{
- "name": "multiple_blockquote",
- "input": "> Hello world!\n\n> Hello universe!",
- "expected_output": "<blockquote>\n<p>Hello world!</p>\n</blockquote>\n<blockquote>\n<p>Hello universe!</p>\n</blockquote>"
+ "name": "multiple_blockquote_with_angular_bracket",
+ "input": "> Hello World!\n\n> Hello Universe!",
+ "expected_output": "<blockquote>\n<p>Hello World!</p>\n</blockquote>\n<blockquote>\n<p>Hello Universe!</p>\n</blockquote>"
},
{
- "name": "multiple_blockquote",
+ "name": "multiple_blockquote_with_backticks_and_angular_bracket",
"input": "```quote\nText in\nmultiple lines.\n```\n\n> Text in a single line.",
"expected_output": "<blockquote>\n<p>Text in<br>\nmultiple lines.</p>\n</blockquote>\n<blockquote>\n<p>Text in a single line.</p>\n</blockquote>"
},
@@ -145,13 +145,13 @@
"text_content": "Before:\n\nOne.\nTwo.\n\n> Lists should work after a quote\n\nAfter:\n\nOne.\nTwo.\n"
},
{
- "name": "dangerous_block",
+ "name": "dangerous_block_having_x",
"input": "xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:\n\n```\"xxxx xxxx\\xxxxx\\xxxxxx\"```\n\nxxx xxxx xxxxx:```xx.xxxxxxx(x'^xxxx$', xx.xxxxxxxxx)```\n\nxxxxxxx'x xxxx xxxxxxxxxx ```'xxxx'```, xxxxx xxxxxxxxx xxxxx ^ xxx $ xxxxxx xxxxx xxxxxxxxxxxx xxx xxxx xx x xxxx xx xxxx xx xxx xxxxx xxxxxx?",
"expected_output": "<p>xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:</p>\n<p><code>\"xxxx xxxx\\xxxxx\\xxxxxx\"</code></p>\n<p>xxx xxxx xxxxx:<code>xx.xxxxxxx(x'^xxxx$', xx.xxxxxxxxx)</code></p>\n<p>xxxxxxx'x xxxx xxxxxxxxxx <code>'xxxx'</code>, xxxxx xxxxxxxxx xxxxx ^ xxx $ xxxxxx xxxxx xxxxxxxxxxxx xxx xxxx xx x xxxx xx xxxx xx xxx xxxxx xxxxxx?</p>",
"text_content": "xxxxxx xxxxx xxxxxxxx xxxx. x xxxx xxxxxxxxxx:\n\"xxxx xxxx\\xxxxx\\xxxxxx\"\nxxx xxxx xxxxx:xx.xxxxxxx(x'^xxxx$', xx.xxxxxxxxx)\nxxxxxxx'x xxxx xxxxxxxxxx 'xxxx', xxxxx xxxxxxxxx xxxxx ^ xxx $ xxxxxx xxxxx xxxxxxxxxxxx xxx xxxx xx x xxxx xx xxxx xx xxx xxxxx xxxxxx?"
},
{
- "name": "dangerous_block",
+ "name": "dangerous_block_having_backticks",
"input": "``` one ```\n\n``` two ```\n\n~~~~\nx = 1",
"expected_output": "<p><code> one </code></p>\n<p><code> two </code></p>\n<div class=\"codehilite\"><pre><span></span><code>x = 1\n</code></pre></div>",
"text_content": " one \n two \nx = 1\n"
@@ -303,13 +303,13 @@
"text_content": "I like software hardware"
},
{
- "name": "strikthrough_multiword",
+ "name": "strikthrough_multiword_with_no_space_in_between",
"input": "I ~~like software~~ love hardware",
"expected_output": "<p>I <del>like software</del> love hardware</p>",
"text_content": "I like software love hardware"
},
{
- "name": "strikthrough_multiword",
+ "name": "strikthrough_multiword_with_space_in_between",
"input": "I ~~ like software ~~ love hardware",
"expected_output": "<p>I <del> like software </del> love hardware</p>",
"text_content": "I like software love hardware"
@@ -687,7 +687,7 @@
"expected_output": "<p>:skin-tone-2: :skin-tone-3:</p>"
},
{
- "name": "fried_egg",
+ "name": "fried_egg_emoji_nonexistant",
"input": "new :fried_egg: emoji is banned for now.",
"expected_output": "<p>new :fried_egg: emoji is banned for now.</p>"
},
diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py
index 7f8dd6ef617..4a5224184ff 100644
--- a/zerver/tests/test_markdown.py
+++ b/zerver/tests/test_markdown.py
@@ -412,6 +412,20 @@ class MarkdownTest(ZulipTestCase):
is_ignored = test.get("ignore", False)
self.assertFalse(is_ignored, message)
+ def test_markdown_fixtures_unique_names(self) -> None:
+ # All markdown fixtures must have unique names.
+ found_names: Set[str] = set()
+ with open(
+ os.path.join(os.path.dirname(__file__), "fixtures/markdown_test_cases.json"), "rb"
+ ) as f:
+ data = orjson.loads(f.read())
+ for test in data["regular_tests"]:
+ test_name = test["name"]
+ message = f'Test name: "{test_name}" must be unique.'
+ is_unique = test_name not in found_names
+ self.assertTrue(is_unique, message)
+ found_names.add(test_name)
+
def test_markdown_fixtures(self) -> None:
format_tests, linkify_tests = self.load_markdown_tests()
valid_keys = {