~ubuntu-branches/ubuntu/wily/lua-discount/wily-proposed

« back to all changes in this revision

Viewing changes to test_discount.lua

  • Committer: Package Import Robot
  • Author(s): Julian Wollrath
  • Date: 2013-02-17 14:57:18 UTC
  • Revision ID: package-import@ubuntu.com-20130217145718-0c5bvnfrze679weo
Tags: 1.2.10.1-1
Initial release. (Closes: #700783)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require("lunit")
 
1
require("luaunit")
2
2
discount = require("discount")
3
3
 
4
 
module("test discount", lunit.testcase, package.seeall)
5
 
 
6
4
function test_basic_conversion()
7
 
  assert_equal("<p>Hello World.</p>\n", discount("Hello World."))
 
5
  assertEquals("<p>Hello World.</p>", discount("Hello World."))
8
6
end
9
7
 
10
8
function test_relaxed_emphasis()
11
 
  assert_equal("<p><em>Hello World</em>!</p>\n", discount("_Hello World_!"))
12
 
  assert_equal("<p>under_score this_stuff</p>\n", discount("under_score this_stuff"))
 
9
  assertEquals("<p><em>Hello World</em>!</p>", discount("_Hello World_!"))
 
10
  assertEquals("<p>under_score this_stuff</p>", discount("under_score this_stuff"))
13
11
 
14
12
  local input = "_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>"
15
 
  local expected_out = "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>\n"
16
 
  assert_equal(expected_out, discount(input))
 
13
  local expected_out = "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>"
 
14
  assertEquals(expected_out, discount(input))
17
15
end
18
16
 
19
17
function test_nolinks()
20
 
  assert_equal("<p>[example](http://example.com)</p>\n", discount("[example](http://example.com)", "nolinks"))
21
 
  assert_equal('<p>&lt;a href="http://example.com">example</a></p>\n',
 
18
  assertEquals("<p>[example](http://example.com)</p>", discount("[example](http://example.com)", "nolinks"))
 
19
  assertEquals('<p>&lt;a href=&ldquo;http://example.com&rdquo;>example</a></p>',
22
20
      discount('<a href="http://example.com">example</a>', "nolinks"))
23
21
end
24
22
 
25
23
function test_noimages()
26
 
  assert_equal("<p>![example](example.png)</p>\n", discount("![example](example.png)", "noimages"))
27
 
  assert_equal('<p>&lt;img src="example.png"/></p>\n', discount('<img src="example.png"/>', "noimages"))
 
24
  assertEquals("<p>![example](example.png)</p>", discount("![example](example.png)", "noimages"))
 
25
  assertEquals('<p>&lt;img src=&ldquo;example.png&rdquo;/></p>', discount('<img src="example.png"/>', "noimages"))
28
26
end
29
27
 
30
28
function test_nopants()
31
 
  assert_equal('<p>&ldquo;quote&rdquo;</p>\n', discount('"quote"'))
32
 
  assert_equal('<p>"quote"</p>\n', discount('"quote"', "nopants"))
 
29
  assertEquals('<p>&ldquo;quote&rdquo;</p>', discount('"quote"'))
 
30
  assertEquals('<p>"quote"</p>', discount('"quote"', "nopants"))
33
31
end
34
32
 
35
33
function test_nohtml()
36
 
  local expected = "<p>This should &lt;em>not&lt;/em> be allowed</p>\n"
37
 
  assert_equal(expected, discount("This should <em>not</em> be allowed", "nohtml"))
38
 
end
39
 
 
40
 
function test_cdata()
41
 
  assert_equal("&lt;p&gt;foo&lt;/p&gt;\n", discount("foo", "cdata"))
42
 
end
 
34
  local expected = "<p>This should &lt;em>not&lt;/em> be allowed</p>"
 
35
  assertEquals(expected, discount("This should <em>not</em> be allowed", "nohtml"))
 
36
end
 
37
 
 
38
--function test_cdata()
 
39
--  assertEquals("&lt;p&gt;foo&lt;/p&gt;", discount("foo", "cdata"))
 
40
--end
 
41
 
 
42
function test_toc()
 
43
  local expected_out = '<h1 id="Level.1\">Level 1</h1>\n\n<h2 id="Level.2\">Level 2</h2>'
 
44
  local input = "# Level 1\n\n## Level 2\n\n"
 
45
  assertEquals(expected_out, discount(input, "toc"))
 
46
end
 
47
 
 
48
lu = LuaUnit
 
49
os.exit(lu:run())