File: toc.rb

package info (click to toggle)
ruby-bluefeather 0.41-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 736 kB
  • sloc: ruby: 4,195; makefile: 9
file content (147 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require 'pathname'
require(Pathname.new(__FILE__).parent + 'lib/common.rb')


describe 'TOC:' do
	before(:each) do
		@bf = BlueFeather::Parser.new
		if @doc_src then
			@html = @bf.parse_document(@doc_src)
		else
			@html, @rs = @bf.parse_text_with_render_state(@src)
			@html = "<div>#{@html}</div>"
		end
		@doc = Nokogiri(@html)
	end

	describe 'Standard:' do
		before(:all) do
			@header_part = <<MARKDOWN
# h1 #
## h2a ##
## h2b ##
### h3a ###
### h3b ###
### h3c ###
## h2c ##
MARKDOWN
		end

	
	
		shared_context 'content overview' do
		    it 'overview' do
				@doc.should have_element('ul')
				@doc.should have_elements(1, 'h1')
				@doc.should have_elements(3, 'h2')
				@doc.should have_elements(3, 'h3')
			end
		end
	
	
		describe 'basic:' do
			 include_context 'content overview'
			before(:all) do
				@src = "{toc}\n\n" +  @header_part
			end
			
			
			specify 'list structure' do
				toc = @doc.at('ul')
				toc['class'] = 'toc'
				
				@doc.should have_elements(3, 'ul.toc > li')
				@doc.should have_elements(1, 'ul.toc > li > ul')
				@doc.should have_elements(3, 'ul.toc > li > ul > li')
			end
			
			specify 'list content' do
				toc = @doc.at('ul')
				toc['class'] = 'toc'
				
				items1 = @doc.search('ul.toc > li')
				items1[0].inner_text.should == 'h2a'
				items1[2].inner_text.should == 'h2c'
	
				items2 = @doc.search('ul.toc > li > ul > li')
				items2[0].inner_text.should == 'h3a'
				items2[1].inner_text.should == 'h3b'
				items2[2].inner_text.should == 'h3c'
			end
	
		end
		
		
		describe 'range:' do
			 include_context 'content overview'
			before(:all) do
				@src = "{toc:h1..h2}\n\n" +  @header_part
			end
			
			specify 'list structure' do
				toc = @doc.at('ul')
				toc['class'] = 'toc'
				
				@doc.should have_elements(1, 'ul.toc > li')
				@doc.should have_elements(1, 'ul.toc > li > ul')
				@doc.should have_elements(3, 'ul.toc > li > ul > li')
			end
			
			specify 'list content' do
				toc = @doc.at('ul')
				toc['class'] = 'toc'
				
				items2 = @doc.search('ul.toc > li > ul > li')
				items2[0].inner_text.should == 'h2a'
				items2[1].inner_text.should == 'h2b'
				items2[2].inner_text.should == 'h2c'
			end
	
		end
		
		
		describe 'numbering:' do
			before(:all) do
				@doc_src = "Numbering: yes\n\n{toc}\n" + @header_part
			end
			
			specify 'list content' do
				toc = @doc.at('ul')
				toc['class'] = 'toc'
				
				items1 = @doc.search('ul.toc > li')
				items1[0].inner_text.should == '1. h2a'
				items1[2].inner_text.should == '3. h2c'
				
				items2 = @doc.search('ul.toc > li > ul > li')
				items2[0].inner_text.should == '2.1. h3a'
				items2[1].inner_text.should == '2.2. h3b'
				items2[2].inner_text.should == '2.3. h3c'

			end
		end

		

	end
	
	describe 'Illegal:' do
		describe 'Standard:' do
			before(:all) do
				@src = <<MARKDOWN
{toc}
	
### h3
MARKDOWN
			end
			
			specify '1 warning' do
				@rs.warnings.size.should == 1
			end
		end
	end
	
	


end