1
+ require 'test/unit'
2
+ require_relative '../lib/html2textile'
3
+
4
+ class HTMLToTextileParserTest < Test ::Unit ::TestCase
5
+
6
+ def to_textile ( html )
7
+ @parser = HTMLToTextileParser . new
8
+ @parser . feed ( html )
9
+ @parser . to_textile
10
+ end
11
+
12
+ def test_should_parse_bold
13
+ assert_equal ' *bold* ' , to_textile ( '<b>bold</b>' )
14
+ end
15
+
16
+ def test_should_parse_italic
17
+ assert_equal ' _italic_ ' , to_textile ( '<i>italic</i>' )
18
+ end
19
+
20
+ def test_bold_with_spaces
21
+ assert_equal ' *b o l d* ' , to_textile ( '<b> b o l d </b>' )
22
+ end
23
+
24
+ def test_should_parse_bold_with_new_lines_inside
25
+ assert_equal ' *b o l d* ' , to_textile ( "<b> b o\n l d\n </b>" )
26
+ end
27
+
28
+ def test_should_parse_italic_with_spaces
29
+ assert_equal ' _i t a l i c_ ' , to_textile ( '<i> i t a l i c</i>' )
30
+ end
31
+
32
+ def test_should_parse_headings
33
+ assert_equal ( "h1. Heading 1\n \n " , to_textile ( '<h1>Heading 1</h1>' ) )
34
+ assert_equal ( "h2. Heading 2\n \n " , to_textile ( '<h2>Heading 2</h2>' ) )
35
+ assert_equal ( "h3. Heading 3\n \n " , to_textile ( '<h3>Heading 3</h3>' ) )
36
+ end
37
+
38
+ def test_should_parse_heading_with_color
39
+ assert_equal "h1. Hello world \n \n " ,
40
+ to_textile ( '<h1>Hello <span style="color: red">world</span></h1>' )
41
+ end
42
+
43
+ def test_should_parse_heading_with_spaces_and_new_lines
44
+ assert_equal "h1. Th is is a headi ng\n \n " ,
45
+ to_textile ( '<h1> Th
46
+ is is a headi ng </h1>' )
47
+ end
48
+
49
+ end
0 commit comments