mirror of
https://github.com/TangentFoxy/markdown.lua.git
synced 2025-07-27 17:42:16 +00:00
Do not use setfenv in tests
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
if not markdown then
|
local markdown = require "markdown"
|
||||||
require "markdown"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Splits the text into an array of separate lines.
|
-- Splits the text into an array of separate lines.
|
||||||
local function split(text, sep)
|
local function split(text, sep)
|
||||||
@@ -26,23 +24,19 @@ end
|
|||||||
-- Set up a table to store all the tests. Customize __newindex to record the
|
-- Set up a table to store all the tests. Customize __newindex to record the
|
||||||
-- order in which the tests are created so that we can process them in the right
|
-- order in which the tests are created so that we can process them in the right
|
||||||
-- order.
|
-- order.
|
||||||
local TESTS = {}
|
local tests_mt = {
|
||||||
local TESTS_MT = {
|
__newindex = function(t, k, v)
|
||||||
__index = _G,
|
if type(k) == "string" then
|
||||||
__newindex = function(t,k,v)
|
table.insert(t, k)
|
||||||
if k:sub(1,1) == "_" then rawset(t,k,v) return end
|
end
|
||||||
|
|
||||||
if t._indices == nil then t._indices = {} end
|
rawset(t, k, v)
|
||||||
table.insert(t._indices, k)
|
|
||||||
rawset(t,k,v)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
local tests = setmetatable({}, tests_mt)
|
||||||
setmetatable(TESTS, TESTS_MT)
|
|
||||||
setfenv(1, TESTS)
|
|
||||||
|
|
||||||
-- Test header markers
|
-- Test header markers
|
||||||
headers = [[
|
tests.headers = [[
|
||||||
This is an h1
|
This is an h1
|
||||||
============
|
============
|
||||||
|
|
||||||
@@ -89,7 +83,7 @@ This is an h2
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test blockquotes
|
-- Test blockquotes
|
||||||
blockquotes = [[
|
tests.blockquotes = [[
|
||||||
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
|
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
|
||||||
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
|
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
|
||||||
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
|
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
|
||||||
@@ -163,7 +157,7 @@ id sem consectetuer libero luctus adipiscing.
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test lists
|
-- Test lists
|
||||||
lists = [[
|
tests.lists = [[
|
||||||
* Red
|
* Red
|
||||||
* Green
|
* Green
|
||||||
* Blue
|
* Blue
|
||||||
@@ -339,7 +333,7 @@ sit amet, consectetuer adipiscing elit.</p></li>
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test code blocks
|
-- Test code blocks
|
||||||
code_blocks = [[
|
tests.code_blocks = [[
|
||||||
This is a normal paragraph:
|
This is a normal paragraph:
|
||||||
|
|
||||||
This is a code block.
|
This is a code block.
|
||||||
@@ -380,7 +374,7 @@ And _underlines_.
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test rules
|
-- Test rules
|
||||||
rules = [[
|
tests.rules = [[
|
||||||
* * *
|
* * *
|
||||||
|
|
||||||
***
|
***
|
||||||
@@ -403,7 +397,7 @@ rules = [[
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test links
|
-- Test links
|
||||||
links = [[
|
tests.links = [[
|
||||||
This is [an example](http://example.com/ "Title") inline link.
|
This is [an example](http://example.com/ "Title") inline link.
|
||||||
~
|
~
|
||||||
<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
|
<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
|
||||||
@@ -491,7 +485,7 @@ or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test emphasis
|
-- Test emphasis
|
||||||
emphasis = [[
|
tests.emphasis = [[
|
||||||
Test *single asterisks* test.
|
Test *single asterisks* test.
|
||||||
~
|
~
|
||||||
<p>Test <em>single asterisks</em> test.</p>
|
<p>Test <em>single asterisks</em> test.</p>
|
||||||
@@ -522,7 +516,7 @@ Test with *two* different *words*.
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test code
|
-- Test code
|
||||||
code = [[
|
tests.code = [[
|
||||||
Use the `printf()` function.
|
Use the `printf()` function.
|
||||||
~
|
~
|
||||||
<p>Use the <code>printf()</code> function.</p>
|
<p>Use the <code>printf()</code> function.</p>
|
||||||
@@ -554,7 +548,7 @@ wrapped with an
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test images
|
-- Test images
|
||||||
images = [[
|
tests.images = [[
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
@@ -571,7 +565,7 @@ images = [[
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test autolinking
|
-- Test autolinking
|
||||||
autolinks = [[
|
tests.autolinks = [[
|
||||||
An auto link <http://www.google.com/>.
|
An auto link <http://www.google.com/>.
|
||||||
~
|
~
|
||||||
<p>An auto link <a href="http://www.google.com/">http://www.google.com/</a>.</p>
|
<p>An auto link <a href="http://www.google.com/">http://www.google.com/</a>.</p>
|
||||||
@@ -588,14 +582,14 @@ Mail links <niklas@frykholm.se> and <mailto:niklas@frykholm.se>.
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test escape codes
|
-- Test escape codes
|
||||||
escapes = [[
|
tests.escapes = [[
|
||||||
\*literal asterisks\*
|
\*literal asterisks\*
|
||||||
~
|
~
|
||||||
<p>*literal asterisks*</p>
|
<p>*literal asterisks*</p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test hard linebreaks
|
-- Test hard linebreaks
|
||||||
linebreaks = [[
|
tests.linebreaks = [[
|
||||||
Poetry
|
Poetry
|
||||||
in
|
in
|
||||||
motion
|
motion
|
||||||
@@ -606,7 +600,7 @@ motion</p>
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test amps and angles conversion
|
-- Test amps and angles conversion
|
||||||
amps = [[
|
tests.amps = [[
|
||||||
©
|
©
|
||||||
~
|
~
|
||||||
<p>©</p>
|
<p>©</p>
|
||||||
@@ -621,7 +615,7 @@ AT&T
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
-- Test raw blocks
|
-- Test raw blocks
|
||||||
raw = [[
|
tests.raw = [[
|
||||||
<div>
|
<div>
|
||||||
This should not be disturbed by Markdown.
|
This should not be disturbed by Markdown.
|
||||||
</div>
|
</div>
|
||||||
@@ -633,7 +627,7 @@ raw = [[
|
|||||||
|
|
||||||
-- Markdown test suit
|
-- Markdown test suit
|
||||||
|
|
||||||
markdown_amps_and_angles = [[
|
tests.markdown_amps_and_angles = [[
|
||||||
AT&T has an ampersand in their name.
|
AT&T has an ampersand in their name.
|
||||||
|
|
||||||
AT&T is another way to write it.
|
AT&T is another way to write it.
|
||||||
@@ -674,7 +668,7 @@ Here's an inline [link](</script?foo=1&bar=2>).
|
|||||||
<p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
|
<p>Here's an inline <a href="/script?foo=1&bar=2">link</a>.</p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_auto_links = [[
|
tests.markdown_auto_links = [[
|
||||||
Link: <http://example.com/>.
|
Link: <http://example.com/>.
|
||||||
|
|
||||||
With an ampersand: <http://example.com/?foo=1&bar=2>
|
With an ampersand: <http://example.com/?foo=1&bar=2>
|
||||||
@@ -709,7 +703,7 @@ Auto-links should not occur here: `<http://example.com/>`
|
|||||||
</code></pre>
|
</code></pre>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_backslash_escapes = [[
|
tests.markdown_backslash_escapes = [[
|
||||||
These should all get escaped:
|
These should all get escaped:
|
||||||
|
|
||||||
Backslash: \\
|
Backslash: \\
|
||||||
@@ -919,7 +913,7 @@ Minus: \-
|
|||||||
<p>Minus: <code>\-</code></p>
|
<p>Minus: <code>\-</code></p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_blockquotes_with_codeblocks = [[
|
tests.markdown_blockquotes_with_codeblocks = [[
|
||||||
> Example:
|
> Example:
|
||||||
>
|
>
|
||||||
> sub status {
|
> sub status {
|
||||||
@@ -949,7 +943,7 @@ markdown_blockquotes_with_codeblocks = [[
|
|||||||
</blockquote>
|
</blockquote>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_hard_wrapped_paragraphs_with_list_like_lines = [[
|
tests.markdown_hard_wrapped_paragraphs_with_list_like_lines = [[
|
||||||
In Markdown 1.0.0 and earlier. Version
|
In Markdown 1.0.0 and earlier. Version
|
||||||
8. This line turns into a list item.
|
8. This line turns into a list item.
|
||||||
Because a hard-wrapped line in the
|
Because a hard-wrapped line in the
|
||||||
@@ -969,7 +963,7 @@ list item.</p>
|
|||||||
* criminey.</p>
|
* criminey.</p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_horizontal_rules = [[
|
tests.markdown_horizontal_rules = [[
|
||||||
Dashes:
|
Dashes:
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -1113,7 +1107,7 @@ _ _ _
|
|||||||
|
|
||||||
-- currently not supported by regular markdown, so we ignore it too
|
-- currently not supported by regular markdown, so we ignore it too
|
||||||
--[[
|
--[[
|
||||||
markdown_inline_html_advanced =
|
tests.markdown_inline_html_advanced =
|
||||||
Simple block on one line:
|
Simple block on one line:
|
||||||
|
|
||||||
<div>foo</div>
|
<div>foo</div>
|
||||||
@@ -1145,7 +1139,7 @@ foo
|
|||||||
</div>
|
</div>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_inline_html_simple = [[
|
tests.markdown_inline_html_simple = [[
|
||||||
Here's a simple block:
|
Here's a simple block:
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -1289,7 +1283,7 @@ Blah
|
|||||||
<hr class="foo" id="bar" >
|
<hr class="foo" id="bar" >
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_inline_html_comments = [[
|
tests.markdown_inline_html_comments = [[
|
||||||
Paragraph one.
|
Paragraph one.
|
||||||
|
|
||||||
<!-- This is a simple comment -->
|
<!-- This is a simple comment -->
|
||||||
@@ -1319,7 +1313,7 @@ The end.
|
|||||||
<p>The end.</p>
|
<p>The end.</p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_links_inline_style = [[
|
tests.markdown_links_inline_style = [[
|
||||||
Just a [URL](/url/).
|
Just a [URL](/url/).
|
||||||
|
|
||||||
[URL and title](/url/ "title").
|
[URL and title](/url/ "title").
|
||||||
@@ -1341,7 +1335,7 @@ Just a [URL](/url/).
|
|||||||
<p><a href="">Empty</a>.</p>
|
<p><a href="">Empty</a>.</p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_links_reference_style = [=[
|
tests.markdown_links_reference_style = [=[
|
||||||
Foo [bar] [1].
|
Foo [bar] [1].
|
||||||
|
|
||||||
Foo [bar][1].
|
Foo [bar][1].
|
||||||
@@ -1394,7 +1388,7 @@ Indented [four][] times.
|
|||||||
</code></pre>
|
</code></pre>
|
||||||
]=]
|
]=]
|
||||||
|
|
||||||
markdown_literal_quotes_in_text = [=[
|
tests.markdown_literal_quotes_in_text = [=[
|
||||||
Foo [bar][].
|
Foo [bar][].
|
||||||
|
|
||||||
Foo [bar](/url/ "Title with "quotes" inside").
|
Foo [bar](/url/ "Title with "quotes" inside").
|
||||||
@@ -1407,7 +1401,7 @@ Foo [bar](/url/ "Title with "quotes" inside").
|
|||||||
<p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
|
<p>Foo <a href="/url/" title="Title with "quotes" inside">bar</a>.</p>
|
||||||
]=]
|
]=]
|
||||||
|
|
||||||
markdown_basics = [[
|
tests.markdown_basics = [[
|
||||||
Markdown: Basics
|
Markdown: Basics
|
||||||
================
|
================
|
||||||
|
|
||||||
@@ -2031,7 +2025,7 @@ you've got to put paragraph tags in your blockquotes:</p>
|
|||||||
</code></pre>
|
</code></pre>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_syntax = [[
|
tests.markdown_syntax = [[
|
||||||
Markdown: Syntax
|
Markdown: Syntax
|
||||||
================
|
================
|
||||||
|
|
||||||
@@ -3864,7 +3858,7 @@ _ underscore
|
|||||||
</code></pre>
|
</code></pre>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_nested_blockquotes = [[
|
tests.markdown_nested_blockquotes = [[
|
||||||
> foo
|
> foo
|
||||||
>
|
>
|
||||||
> > bar
|
> > bar
|
||||||
@@ -3882,7 +3876,7 @@ markdown_nested_blockquotes = [[
|
|||||||
</blockquote>
|
</blockquote>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_ordered_and_unordered_lists = [[
|
tests.markdown_ordered_and_unordered_lists = [[
|
||||||
## Unordered
|
## Unordered
|
||||||
|
|
||||||
Asterisks tight:
|
Asterisks tight:
|
||||||
@@ -4145,7 +4139,7 @@ back.</p></li>
|
|||||||
</ol>
|
</ol>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_strong_and_em_together = [[
|
tests.markdown_strong_and_em_together = [[
|
||||||
***This is strong and em.***
|
***This is strong and em.***
|
||||||
|
|
||||||
So is ***this*** word.
|
So is ***this*** word.
|
||||||
@@ -4163,7 +4157,7 @@ So is ___this___ word.
|
|||||||
<p>So is <strong><em>this</em></strong> word.</p>
|
<p>So is <strong><em>this</em></strong> word.</p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_tabs = [[
|
tests.markdown_tabs = [[
|
||||||
+ this is a list item
|
+ this is a list item
|
||||||
indented with tabs
|
indented with tabs
|
||||||
|
|
||||||
@@ -4213,7 +4207,7 @@ indented with spaces</p></li>
|
|||||||
</code></pre>
|
</code></pre>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
markdown_tidyness = [[
|
tests.markdown_tidyness = [[
|
||||||
> A list within a blockquote:
|
> A list within a blockquote:
|
||||||
>
|
>
|
||||||
> * asterisk 1
|
> * asterisk 1
|
||||||
@@ -4230,7 +4224,7 @@ markdown_tidyness = [[
|
|||||||
</blockquote>
|
</blockquote>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
bug_from_paul_chiusano_gmail_com = [[
|
tests.bug_from_paul_chiusano_gmail_com = [[
|
||||||
[context-free grammar][CFG]
|
[context-free grammar][CFG]
|
||||||
[notated][BNF]
|
[notated][BNF]
|
||||||
[unrestricted grammar][]
|
[unrestricted grammar][]
|
||||||
@@ -4248,7 +4242,7 @@ bug_from_paul_chiusano_gmail_com = [[
|
|||||||
<p><em><code>foo()</code></em></p>
|
<p><em><code>foo()</code></em></p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
links = [[
|
tests.links = [[
|
||||||
[the_dog](the_dog.html)
|
[the_dog](the_dog.html)
|
||||||
~
|
~
|
||||||
<p><a href="the_dog.html">the_dog</a></p>
|
<p><a href="the_dog.html">the_dog</a></p>
|
||||||
@@ -4278,7 +4272,7 @@ _Kalle_
|
|||||||
<p><em>Kalle</em></p>
|
<p><em>Kalle</em></p>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
bugs = [==[
|
tests.bugs = [==[
|
||||||
[the dog](the%20dog.html)
|
[the dog](the%20dog.html)
|
||||||
~
|
~
|
||||||
<p><a href="the%20dog.html">the dog</a></p>
|
<p><a href="the%20dog.html">the dog</a></p>
|
||||||
@@ -4400,7 +4394,7 @@ This is [an example] [id] reference-style link.
|
|||||||
|
|
||||||
-- Unhandled test: _M*A*S*H_
|
-- Unhandled test: _M*A*S*H_
|
||||||
|
|
||||||
setfenv(1, _G)
|
local quiet_mode
|
||||||
|
|
||||||
-- Test running function
|
-- Test running function
|
||||||
local function run_tests()
|
local function run_tests()
|
||||||
@@ -4460,9 +4454,9 @@ local function run_tests()
|
|||||||
return failed
|
return failed
|
||||||
end
|
end
|
||||||
|
|
||||||
total_failed = 0
|
local total_failed = 0
|
||||||
for _,k in ipairs(TESTS._indices) do
|
for _,k in ipairs(tests) do
|
||||||
total_failed = total_failed + run_test(k,TESTS[k])
|
total_failed = total_failed + run_test(k,tests[k])
|
||||||
end
|
end
|
||||||
if total_failed > 0 then
|
if total_failed > 0 then
|
||||||
os.exit(-1)
|
os.exit(-1)
|
||||||
|
Reference in New Issue
Block a user