mediacloth 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/test/data/html9 ADDED
@@ -0,0 +1,6 @@
1
+ <p>Some examples of wiki escaping.</p><p>A paragraph with some wiki characters: ''italic'' '''bold''' [[Link]]</p><p>An escaped list:
2
+
3
+ * one
4
+ * two
5
+ * three
6
+ </p><p>Text escaped in a heading:</p><h2>Heading with '''</h2>
data/test/data/input1 CHANGED
@@ -19,6 +19,11 @@ We can have headlines:
19
19
  ====== Headline6 ======
20
20
  ======= Headline7 =======
21
21
 
22
+ Headlines may have formatting:
23
+
24
+ = See [[Internal Link]] for more info =
25
+ == This is an '''important''' heading ==
26
+
22
27
  This is a preformatted ''' ''' << '' '' text
23
28
  yes
24
29
 
data/test/data/input10 ADDED
@@ -0,0 +1,124 @@
1
+ Some examples of tables.
2
+
3
+ {|
4
+ |}
5
+
6
+ {|
7
+ |-
8
+ |}
9
+
10
+ {|
11
+ | a
12
+ | b
13
+ |}
14
+
15
+ {|
16
+ | a
17
+ | b
18
+ |-
19
+ | 1
20
+ | 2
21
+ |}
22
+
23
+ {|
24
+ | a || b
25
+ |-
26
+ | 1 || 2
27
+ |}
28
+
29
+ {|
30
+ ! a
31
+ ! b
32
+ |-
33
+ | 1
34
+ | 2
35
+ |}
36
+
37
+ {|
38
+ ! a || b
39
+ |-
40
+ | 1 || 2
41
+ |}
42
+
43
+ {|
44
+ | a
45
+ |-
46
+ | 1
47
+ | 2
48
+ |}
49
+
50
+ {|
51
+ | a
52
+ | b
53
+ |-
54
+ | 1
55
+ |}
56
+
57
+ {|
58
+ | a
59
+ | b
60
+ |-
61
+ |
62
+ | 2
63
+ |}
64
+
65
+ {|
66
+ | [http://example.com Example]
67
+ | '''bold'''
68
+ |-
69
+ | [[example|Example]]
70
+ | [[image:example.jpg|1|2|3]]
71
+ |}
72
+
73
+ {|
74
+ | [http://example.com Example
75
+ | '''bold
76
+ |-
77
+ | [[example|Example
78
+ | '''bold ''italic
79
+ |}
80
+
81
+ {|
82
+ | a
83
+ | b
84
+ |-
85
+ | A list in a cell:
86
+ * one
87
+ * two
88
+ |}
89
+
90
+ {|
91
+ | a
92
+ | b
93
+ |-
94
+ | A table in a cell:
95
+ {|
96
+ | 1
97
+ | 2
98
+ |-
99
+ | one
100
+ | two
101
+ |}
102
+ |}
103
+
104
+
105
+ {| border="1"
106
+ ! a
107
+ ! b
108
+ |- align="left"
109
+ | 1
110
+ | 2
111
+ |}
112
+
113
+
114
+ Text before
115
+ {|
116
+ | a
117
+ | b
118
+ |}
119
+
120
+ Text before with ''italic
121
+ {|
122
+ | a
123
+ | b
124
+ |}
data/test/data/input4 CHANGED
@@ -1 +1,50 @@
1
- '''''Foo'''''
1
+ Test mixing of bold and italic formatting:
2
+
3
+ ''italic'''bold'''italic''
4
+
5
+ '''bold''italic''bold'''
6
+
7
+ '''''boldalic'''''
8
+
9
+ ''italic'''bold'''italic'''''bold''italic''bold'''
10
+
11
+
12
+ Test bold and italic wrapped around inline links:
13
+
14
+ ''http://example.com''
15
+
16
+ '''http://example.com'''
17
+
18
+ ''http://example.com'''
19
+
20
+ '''http://example.com' is good'''
21
+
22
+ ''http://example.com' is good''
23
+
24
+
25
+ Test unclosed bold and italic formatting:
26
+
27
+ ''Some italic and now ''bold
28
+ ==Heading==
29
+ Text
30
+
31
+
32
+ ''Some italic and now '''bold
33
+ ==Heading==
34
+ Text
35
+
36
+
37
+ ''Some italic and now '''bold
38
+
39
+ ==Heading==
40
+ Text
41
+
42
+
43
+ ''Some italic and now '''bold
44
+ * one
45
+ * two
46
+
47
+
48
+ ''Some italic and now '''bold
49
+
50
+ Text
data/test/data/input5 CHANGED
@@ -12,3 +12,11 @@
12
12
  ####a
13
13
  #a
14
14
  ##aa
15
+
16
+ *A
17
+ *B
18
+ *
19
+
20
+ #A
21
+ #B
22
+ #
data/test/data/input7 CHANGED
@@ -1,2 +1,35 @@
1
- [http://www.example.com external link]
2
- http://www.example.com [foo]
1
+ http://sun.com
2
+
3
+ [http://sun.com]
4
+
5
+ [mailto:joe@sun.com]
6
+
7
+ [http://sun.com stars]
8
+
9
+ [http://sun.com stars and moon]
10
+
11
+ [http://sun.com stars and ''moon'' and '''trees''' and birds]
12
+
13
+ [[sun]]
14
+
15
+ [[sun|All about Sun]]
16
+
17
+ [[image:sun|All about Sun]]
18
+
19
+ [[sun|nofollow|All about Sun]]
20
+
21
+ [[image:sun|nofollow|All about Sun]]
22
+
23
+ [[image:sun|All about [[Sun]]]]
24
+
25
+ [[image:sun|All about [[sun|More about]]]]
26
+
27
+ [[image:sun|one||two||three|]]
28
+
29
+ []
30
+
31
+ [ ]
32
+
33
+ [[]]
34
+
35
+ [[ ]]
data/test/data/input9 ADDED
@@ -0,0 +1,14 @@
1
+ Some examples of wiki escaping.
2
+
3
+ A paragraph with some wiki characters: <nowiki>''italic'' '''bold''' [[Link]]</nowiki>
4
+
5
+ An escaped list:
6
+ <nowiki>
7
+ * one
8
+ * two
9
+ * three
10
+ </nowiki>
11
+
12
+ Text escaped in a heading:
13
+
14
+ ==Heading with <nowiki>'''</nowiki>==
data/test/data/lex1 CHANGED
@@ -6,12 +6,16 @@ PARA_STARTTEXTAnother paragraph starts after a blank line.PARA_END
6
6
  PARA_STARTTEXT
7
7
  Another one.PARA_END
8
8
 
9
- PARA_STARTTEXTThis is text with INTLINKSTART[[TEXTInternal LinkINTLINKEND]]TEXT and LINKSTART[TEXThttp://www.example.com external linkLINKEND]TEXT.PARA_END
9
+ PARA_STARTTEXTThis is text with INTLINKSTART[[TEXTInternal LinkINTLINKEND]]TEXT and LINKSTART[TEXThttp://www.example.comLINKSEPTEXTexternal linkLINKEND]TEXT.PARA_END
10
10
 
11
11
  PARA_STARTTEXTWe can have headlines:PARA_END
12
12
 
13
13
  SECTION_START=TEXT Headline1 SECTION_END=SECTION_START==TEXT Headline2 SECTION_END==SECTION_START===TEXT Headline3 SECTION_END===SECTION_START====TEXT Headline4 SECTION_END====SECTION_START=====TEXT Headline5 SECTION_END=====SECTION_START======TEXT Headline6 SECTION_END======SECTION_START=======TEXT Headline7 SECTION_END=======PARA_STARTPARA_END
14
14
 
15
+ PARA_STARTTEXTHeadlines may have formatting:PARA_END
16
+
17
+ SECTION_START=TEXT See INTLINKSTART[[TEXTInternal LinkINTLINKEND]]TEXT for more info SECTION_END=SECTION_START==TEXT This is an BOLDSTART'''TEXTimportantBOLDEND'''TEXT heading SECTION_END==PARA_STARTPARA_END
18
+
15
19
  PREThis is a preformatted ''' ''' << '' '' text
16
20
  PREyes
17
21
  HLINE----PARA_STARTTEXT
data/test/data/lex10 ADDED
@@ -0,0 +1,87 @@
1
+ PARA_STARTTEXTSome examples of tables.PARA_END
2
+
3
+ TABLE_START{|TABLE_END|}PARA_STARTPARA_END
4
+
5
+ TABLE_START{|ROW_START|-ROW_END|}TABLE_ENDPARA_STARTPARA_END
6
+
7
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
8
+ CELL_END|CELL_STARTTEXT b
9
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
10
+
11
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
12
+ CELL_END|CELL_STARTTEXT b
13
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT 1
14
+ CELL_END|CELL_STARTTEXT 2
15
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
16
+
17
+ TABLE_START{|ROW_START|CELL_STARTTEXT a CELL_END||CELL_STARTTEXT b
18
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT 1 CELL_END||CELL_STARTTEXT 2
19
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
20
+
21
+ TABLE_START{|ROW_START!HEAD_STARTTEXT a
22
+ HEAD_END!HEAD_STARTTEXT b
23
+ HEAD_END|-ROW_ENDROW_STARTCELL_START|TEXT 1
24
+ CELL_END|CELL_STARTTEXT 2
25
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
26
+
27
+ TABLE_START{|ROW_START!HEAD_STARTTEXT a HEAD_END||HEAD_STARTTEXT b
28
+ HEAD_END|-ROW_ENDROW_STARTCELL_START|TEXT 1 CELL_END||CELL_STARTTEXT 2
29
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
30
+
31
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
32
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT 1
33
+ CELL_END|CELL_STARTTEXT 2
34
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
35
+
36
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
37
+ CELL_END|CELL_STARTTEXT b
38
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT 1
39
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
40
+
41
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
42
+ CELL_END|CELL_STARTTEXT b
43
+ CELL_END|-ROW_ENDROW_STARTCELL_START|CELL_END|CELL_STARTTEXT 2
44
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
45
+
46
+ TABLE_START{|ROW_START|CELL_STARTTEXT LINKSTART[TEXThttp://example.comLINKSEPTEXTExampleLINKEND]CELL_END|CELL_STARTTEXT BOLDSTART'''TEXTboldBOLDEND'''CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT INTLINKSTART[[TEXTexampleINTLINKSEP|TEXTExampleINTLINKEND]]CELL_END|CELL_STARTTEXT INTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTexample.jpgINTLINKSEP|TEXT1INTLINKSEP|TEXT2INTLINKSEP|TEXT3INTLINKEND]]CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
47
+
48
+ TABLE_START{|ROW_START|CELL_STARTTEXT LINKSTART[TEXThttp://example.comLINKSEPTEXTExample
49
+ LINKEND|CELL_ENDCELL_STARTTEXT BOLDSTART'''TEXTbold
50
+ BOLDEND|-CELL_ENDROW_ENDROW_STARTCELL_START|TEXT INTLINKSTART[[TEXTexampleINTLINKSEP|TEXTExample
51
+ INTLINKEND|CELL_ENDCELL_STARTTEXT BOLDSTART'''TEXTbold ITALICSTART''TEXTitalic
52
+ ITALICEND|}BOLDENDCELL_ENDROW_ENDTABLE_ENDPARA_STARTPARA_END
53
+
54
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
55
+ CELL_END|CELL_STARTTEXT b
56
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT A list in a cell:
57
+ UL_STARTLI_STARTTEXTone
58
+ LI_ENDLI_STARTTEXTtwo
59
+ LI_ENDUL_ENDCELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
60
+
61
+ TABLE_START{|ROW_START|CELL_STARTTEXT a
62
+ CELL_END|CELL_STARTTEXT b
63
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT A table in a cell:
64
+ TABLE_START{|ROW_START|CELL_STARTTEXT 1
65
+ CELL_END|CELL_STARTTEXT 2
66
+ CELL_END|-ROW_ENDROW_STARTCELL_START|TEXT one
67
+ CELL_END|CELL_STARTTEXT two
68
+ CELL_END|}ROW_ENDTABLE_ENDCELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
69
+
70
+ TABLE_START{|TEXT border="1"
71
+ ROW_START!HEAD_STARTTEXT a
72
+ HEAD_END!HEAD_STARTTEXT b
73
+ HEAD_END|-ROW_ENDROW_STARTTEXT align="left"
74
+ CELL_START|TEXT 1
75
+ CELL_END|CELL_STARTTEXT 2
76
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
77
+
78
+ PARA_STARTTEXT
79
+ Text before
80
+ PARA_END{|TABLE_STARTROW_START|CELL_STARTTEXT a
81
+ CELL_END|CELL_STARTTEXT b
82
+ CELL_END|}ROW_ENDTABLE_ENDPARA_STARTPARA_END
83
+
84
+ PARA_STARTTEXTText before with ITALICSTART''TEXTitalic
85
+ ITALICEND{|PARA_ENDTABLE_STARTROW_START|CELL_STARTTEXT a
86
+ CELL_END|CELL_STARTTEXT b
87
+ CELL_END|}ROW_ENDTABLE_ENDfalsefalse
data/test/data/lex4 CHANGED
@@ -1 +1,47 @@
1
- PARA_STARTBOLDSTART'''ITALICSTART''TEXTFooITALICEND''BOLDEND'''PARA_ENDfalsefalse
1
+ PARA_STARTTEXTTest mixing of bold and italic formatting:PARA_END
2
+
3
+ PARA_STARTITALICSTART''TEXTitalicBOLDSTART'''TEXTboldBOLDEND'''TEXTitalicITALICEND''PARA_END
4
+
5
+ PARA_STARTBOLDSTART'''TEXTboldITALICSTART''TEXTitalicITALICEND''TEXTboldBOLDEND'''PARA_END
6
+
7
+ PARA_STARTITALICSTART''BOLDSTART'''TEXTboldalicBOLDEND'''ITALICEND''PARA_END
8
+
9
+ PARA_STARTITALICSTART''TEXTitalicBOLDSTART'''TEXTboldBOLDEND'''TEXTitalicITALICEND''BOLDSTART'''TEXTboldITALICSTART''TEXTitalicITALICEND''TEXTboldBOLDEND'''PARA_END
10
+
11
+ PARA_STARTTEXT
12
+ Test bold and italic wrapped around inline links:PARA_END
13
+
14
+ PARA_STARTITALICSTART''LINKSTARTTEXThttp://example.comLINKEND]ITALICEND''PARA_END
15
+
16
+ PARA_STARTBOLDSTART'''LINKSTARTTEXThttp://example.comLINKEND]BOLDEND'''PARA_END
17
+
18
+ PARA_STARTITALICSTART''LINKSTARTTEXThttp://example.com'LINKEND]ITALICEND''PARA_END
19
+
20
+ PARA_STARTBOLDSTART'''LINKSTARTTEXThttp://example.com'LINKEND]TEXT is goodBOLDEND'''PARA_END
21
+
22
+ PARA_STARTITALICSTART''LINKSTARTTEXThttp://example.com'LINKEND]TEXT is goodITALICEND''PARA_END
23
+
24
+ PARA_STARTTEXT
25
+ Test unclosed bold and italic formatting:PARA_END
26
+
27
+ PARA_STARTITALICSTART''TEXTSome italic and now ITALICEND''TEXTbold
28
+ PARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT
29
+ TextPARA_END
30
+
31
+ PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTbold
32
+ BOLDENDITALICENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT
33
+ TextPARA_END
34
+
35
+ PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTboldBOLDEND
36
+
37
+ ITALICENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT
38
+ TextPARA_END
39
+
40
+ PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTbold
41
+ BOLDENDITALICENDPARA_ENDUL_STARTLI_STARTTEXTone
42
+ LI_ENDLI_STARTTEXTtwo
43
+ LI_ENDUL_ENDPARA_STARTPARA_END
44
+
45
+ PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTboldBOLDEND
46
+
47
+ ITALICENDPARA_ENDPARA_STARTTEXTTextPARA_ENDfalsefalse
data/test/data/lex5 CHANGED
@@ -9,4 +9,10 @@ LI_ENDUL_ENDLI_ENDUL_ENDOL_STARTLI_STARTTEXTa
9
9
  OL_STARTLI_STARTTEXTa
10
10
  OL_STARTLI_STARTTEXTa
11
11
  OL_STARTLI_STARTTEXTa
12
- LI_ENDOL_ENDLI_ENDOL_ENDLI_ENDOL_ENDLI_ENDOL_ENDfalsefalse
12
+ LI_ENDOL_ENDLI_ENDOL_ENDLI_ENDOL_ENDLI_ENDLI_STARTTEXTa
13
+ OL_STARTLI_STARTTEXTaa
14
+ LI_ENDOL_ENDLI_ENDOL_ENDUL_STARTLI_STARTTEXTA
15
+ LI_ENDLI_STARTTEXTB
16
+ LI_ENDLI_STARTLI_ENDUL_ENDOL_STARTLI_STARTTEXTA
17
+ LI_ENDLI_STARTTEXTB
18
+ LI_ENDLI_STARTLI_ENDOL_ENDfalsefalse
data/test/data/lex7 CHANGED
@@ -1,2 +1,35 @@
1
- PARA_STARTLINKSTART[TEXThttp://www.example.com external linkLINKEND]LINKSTARTTEXThttp://www.example.comLINKEND]TEXT [foo]
2
- PARA_ENDfalsefalse
1
+ PARA_STARTLINKSTARTTEXThttp://sun.comLINKEND]PARA_END
2
+
3
+ PARA_STARTLINKSTART[TEXThttp://sun.comLINKEND]PARA_END
4
+
5
+ PARA_STARTLINKSTART[TEXTmailto:joe@sun.comLINKEND]PARA_END
6
+
7
+ PARA_STARTLINKSTART[TEXThttp://sun.comLINKSEPTEXTstarsLINKEND]PARA_END
8
+
9
+ PARA_STARTLINKSTART[TEXThttp://sun.comLINKSEPTEXTstars and moonLINKEND]PARA_END
10
+
11
+ PARA_STARTLINKSTART[TEXThttp://sun.comLINKSEPTEXTstars and ITALICSTART''TEXTmoonITALICEND''LINKSEPTEXTand BOLDSTART'''TEXTtreesBOLDEND'''LINKSEPTEXTand birdsLINKEND]PARA_END
12
+
13
+ PARA_STARTINTLINKSTART[[TEXTsunINTLINKEND]]PARA_END
14
+
15
+ PARA_STARTINTLINKSTART[[TEXTsunINTLINKSEP|TEXTAll about SunINTLINKEND]]PARA_END
16
+
17
+ PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTAll about SunINTLINKEND]]PARA_END
18
+
19
+ PARA_STARTINTLINKSTART[[TEXTsunINTLINKSEP|TEXTnofollow|All about SunINTLINKEND]]PARA_END
20
+
21
+ PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTnofollowINTLINKSEP|TEXTAll about SunINTLINKEND]]PARA_END
22
+
23
+ PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTAll about INTLINKSTART[[TEXTSunINTLINKEND]]INTLINKEND]]PARA_END
24
+
25
+ PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTAll about INTLINKSTART[[TEXTsunINTLINKSEP|TEXTMore aboutINTLINKEND]]INTLINKEND]]PARA_END
26
+
27
+ PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXToneINTLINKSEP|INTLINKSEP|TEXTtwoINTLINKSEP|INTLINKSEP|TEXTthreeINTLINKSEP|INTLINKEND]]PARA_END
28
+
29
+ PARA_STARTTEXT[]PARA_END
30
+
31
+ PARA_STARTTEXT[ ]PARA_END
32
+
33
+ PARA_STARTTEXT[[]]PARA_END
34
+
35
+ PARA_STARTTEXT[[ ]]PARA_ENDfalsefalse
data/test/data/lex9 ADDED
@@ -0,0 +1,14 @@
1
+ PARA_STARTTEXTSome examples of wiki escaping.PARA_END
2
+
3
+ PARA_STARTTEXTA paragraph with some wiki characters: ''italic'' '''bold''' [[Link]]PARA_END
4
+
5
+ PARA_STARTTEXTAn escaped list:
6
+
7
+ * one
8
+ * two
9
+ * three
10
+ PARA_END
11
+
12
+ PARA_STARTTEXTText escaped in a heading:PARA_END
13
+
14
+ SECTION_START==TEXTHeading with '''SECTION_END==falsefalse
@@ -4,8 +4,8 @@ require 'mediacloth/mediawikiparams'
4
4
  require 'mediacloth/mediawikihtmlgenerator'
5
5
 
6
6
  def produce(index)
7
- file = File.new("../data/html#{index}", "w")
8
- inputFile = File.new("../data/input#{index}", "r")
7
+ file = File.new("../test/data/html#{index}", "w")
8
+ inputFile = File.new("../test/data/input#{index}", "r")
9
9
  input = inputFile.read
10
10
 
11
11
  parser = MediaWikiParser.new
@@ -0,0 +1,24 @@
1
+ require 'mediacloth/mediawikilexer'
2
+ require 'mediacloth/mediawikiparser'
3
+ require 'mediacloth/mediawikiparams'
4
+ require 'mediacloth/mediawikihtmlgenerator'
5
+
6
+ def produce(index)
7
+ file = File.new("../data/html#{index}", "w")
8
+ inputFile = File.new("../data/input#{index}", "r")
9
+ input = inputFile.read
10
+
11
+ parser = MediaWikiParser.new
12
+ parser.lexer = MediaWikiLexer.new
13
+ ast = parser.parse(input)
14
+ MediaWikiParams.instance.time = Time.mktime(2000, 1, 1, 1, 1, 1, 1)
15
+ generator = MediaWikiHTMLGenerator.new
16
+ generator.parse(ast)
17
+
18
+ # puts generator.html
19
+ file.write(generator.html)
20
+ file.close
21
+ end
22
+
23
+ # (3..5).each { |i| produce(i) }
24
+ produce(5)
@@ -1,8 +1,8 @@
1
1
  require 'mediacloth/mediawikilexer'
2
2
 
3
3
  def produce(index)
4
- file = File.new("../data/lex#{index}", "w")
5
- inputFile = File.new("../data/input#{index}", "r")
4
+ file = File.new("../test/data/lex#{index}", "w")
5
+ inputFile = File.new("../test/data/input#{index}", "r")
6
6
  input = inputFile.read
7
7
 
8
8
  lexer = MediaWikiLexer.new
@@ -12,4 +12,4 @@ def produce(index)
12
12
  end
13
13
 
14
14
  #1..5.each { |i| produce(1) }
15
- produce(8)
15
+ produce(5)
@@ -0,0 +1,15 @@
1
+ require 'mediacloth/mediawikilexer'
2
+
3
+ def produce(index)
4
+ file = File.new("../data/lex#{index}", "w")
5
+ inputFile = File.new("../data/input#{index}", "r")
6
+ input = inputFile.read
7
+
8
+ lexer = MediaWikiLexer.new
9
+ tokens = lexer.tokenize(input)
10
+ file.write(tokens.to_s)
11
+ file.close
12
+ end
13
+
14
+ #1..5.each { |i| produce(1) }
15
+ produce(8)
data/test/debugwalker.rb CHANGED
@@ -37,7 +37,7 @@ protected
37
37
  end
38
38
 
39
39
  def parse_list(ast)
40
- info(ast, ast.type)
40
+ info(ast, ast.class)
41
41
  super(ast)
42
42
  end
43
43
 
@@ -5,19 +5,20 @@ require 'mediacloth/mediawikihtmlgenerator'
5
5
  require 'test/unit'
6
6
  require 'testhelper'
7
7
 
8
- class Parser_Test < Test::Unit::TestCase
8
+ class HTMLGenerator_Test < Test::Unit::TestCase
9
9
 
10
10
  include TestHelper
11
11
 
12
12
  def test_input
13
- test_files("html") { |input,result|
13
+ test_files("html") { |input,result,name|
14
+ puts name
14
15
  parser = MediaWikiParser.new
15
16
  parser.lexer = MediaWikiLexer.new
16
17
  ast = parser.parse(input)
17
- MediaWikiParams.instance.time = Time.mktime(2000, 1, 1, 1, 1, 1, 1)
18
+ MediaWikiParams.instance.time = Time.utc(2000, 1, 1, 1, 1, 1, 1)
18
19
  generator = MediaWikiHTMLGenerator.new
19
20
  generator.parse(ast)
20
- assert_equal generator.html, result
21
+ assert_equal generator.html, result, name
21
22
  # puts generator.html
22
23
  }
23
24
  end
data/test/lexer.rb CHANGED
@@ -6,18 +6,35 @@ class Lexer_Test < Test::Unit::TestCase
6
6
 
7
7
  include TestHelper
8
8
 
9
- def test_input
9
+ def test_standard_formatted_input
10
10
  test_files("lex") { |input,result,resultname|
11
11
  lexer = MediaWikiLexer.new
12
12
  tokens = lexer.tokenize(input)
13
- assert_equal(tokens.to_s, result)
13
+ assert_equal(result, tokens.to_s, "Mismatch in #{resultname}")
14
+ }
15
+ end
16
+
17
+ def test_internet_formatted_input
18
+ test_files("lex") { |input,result,resultname|
19
+ lexer = MediaWikiLexer.new
20
+ tokens = lexer.tokenize(input.gsub("\n", "\r\n"))
21
+ assert_equal(result.gsub("\n", "\r\n"), tokens.to_s, "Mismatch in #{resultname}")
14
22
  }
15
23
  end
16
24
 
17
25
  def test_paragraphs
18
- assert_equal(lex("Before\n\n\n=Headline="),
26
+ assert_equal(lex("text\n\ntext"),
27
+ [[:PARA_START, ""], [:TEXT, "text"], [:PARA_END, "\n\n"],
28
+ [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]])
29
+ assert_equal(lex("text\r\n\r\ntext"),
30
+ [[:PARA_START, ""], [:TEXT, "text"], [:PARA_END, "\r\n\r\n"],
31
+ [:PARA_START, ""], [:TEXT, "text"], [:PARA_END, ""], [false,false]])
32
+ assert_equal(lex("Before\n\n=Headline="),
19
33
  [[:PARA_START, ""], [:TEXT, "Before"], [:PARA_END, "\n\n"],
20
34
  [:SECTION_START, "="], [:TEXT, "Headline"], [:SECTION_END, "="], [false,false]])
35
+ assert_equal(lex("Before\r\n\r\n=Headline="),
36
+ [[:PARA_START, ""], [:TEXT, "Before"], [:PARA_END, "\r\n\r\n"],
37
+ [:SECTION_START, "="], [:TEXT, "Headline"], [:SECTION_END, "="], [false,false]])
21
38
  end
22
39
 
23
40
  def test_empty
@@ -27,6 +44,7 @@ class Lexer_Test < Test::Unit::TestCase
27
44
  def test_preformatted
28
45
  #assure preformatted text works as expected at the start of the text
29
46
  assert_equal(lex(" Foo\n"), [[:PRE, "Foo\n"], [false, false]])
47
+ assert_equal(lex(" Foo\r\n"), [[:PRE, "Foo\r\n"], [false, false]])
30
48
  assert_equal(lex(" Foo"), [[:PRE, "Foo"], [false, false]])
31
49
  end
32
50
 
@@ -34,16 +52,30 @@ class Lexer_Test < Test::Unit::TestCase
34
52
  #assure that at the start of the text hline still works
35
53
  assert_equal(lex("----"), [[:HLINE, "----"], [false, false]])
36
54
  assert_equal(lex("\n----"), [[:HLINE, "----"], [false, false]])
55
+ assert_equal(lex("\r\n----"), [[:HLINE, "----"], [false, false]])
37
56
  end
57
+
58
+ def test_inline_links
59
+ #assure that links in-line work
60
+ assert_equal(lex("http://example.com"), [[:PARA_START, ""], [:LINKSTART, ""], [:TEXT, "http://example.com"], [:LINKEND, "]"], [:PARA_END, ""], [false, false]])
61
+ assert_equal(lex("http://example.com\n"), [[:PARA_START, ""], [:LINKSTART, ""], [:TEXT, "http://example.com"], [:LINKEND, "]"], [:PARA_END, ""], [false, false]])
62
+ #assert_equal(lex("http://example.com''italic''"), [[:PARA_START, ""], [:LINKSTART, ""], [:TEXT, "http://example.com"], [:LINKEND, "]"], [:PARA_END, ""], [false, false]])
63
+ end
38
64
 
39
65
  def test_ending_text_token
40
66
  #check for a problem when the last token is TEXT and it's not included
41
67
  assert_equal(lex("\n----\nfoo\n"),
42
68
  [[:HLINE, "----"], [:PARA_START, ""],
43
69
  [:TEXT, "\nfoo\n"], [:PARA_END, ""], [false, false]])
70
+ assert_equal(lex("\r\n----\r\nfoo\r\n"),
71
+ [[:HLINE, "----"], [:PARA_START, ""],
72
+ [:TEXT, "\r\nfoo\r\n"], [:PARA_END, ""], [false, false]])
44
73
  assert_equal(lex("\n----\nfoo\n Hehe"),
45
74
  [[:HLINE, "----"], [:PARA_START, ""], [:TEXT, "\nfoo\n"],
46
75
  [:PARA_END, ""], [:PRE, "Hehe"], [false, false]])
76
+ assert_equal(lex("\r\n----\r\nfoo\r\n Hehe"),
77
+ [[:HLINE, "----"], [:PARA_START, ""], [:TEXT, "\r\nfoo\r\n"],
78
+ [:PARA_END, ""], [:PRE, "Hehe"], [false, false]])
47
79
  end
48
80
 
49
81
  def test_bullets
@@ -57,6 +89,11 @@ class Lexer_Test < Test::Unit::TestCase
57
89
  [:UL_END, ""], [:LI_END, ""], [:UL_END, ""], [false, false]])
58
90
  end
59
91
 
92
+ def test_bullets_at_eof
93
+ assert_equal(lex("* Foo\n*"),
94
+ [[:UL_START, nil], [:LI_START, ""], [:TEXT, "Foo\n"], [:LI_END, ""], [:LI_START, ""], [:LI_END, ""], [:UL_END, ""], [false, false]])
95
+ end
96
+
60
97
  private
61
98
  def lex(string)
62
99
  lexer = MediaWikiLexer.new