langhelp 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tmpdir'
3
+ require 'test/unit'
4
+ require 'langhelp/langhelp-sub'
5
+ require 'fileutils'
6
+
7
+ class TestParseInfo < Test::Unit::TestCase
8
+
9
+ def tmpdir
10
+ Dir.tmpdir
11
+ end
12
+
13
+ def null
14
+ "> /dev/null 2>&1"
15
+ #""
16
+ end
17
+
18
+ def _test_lang(lang)
19
+ begin
20
+ new_e = "#{lang}.e"
21
+ old_e = "#{lang}.old.e"
22
+ new_sorted_e = "#{lang}.sorted.e"
23
+ old_sorted_e = "#{lang}.old.sorted.e"
24
+ # TODO: --suffix, refactoring
25
+ system "mklanghelp --suffix=.old.e --home=#{tmpdir} #{lang} #{null}"
26
+ system "ruby -Ilib bin/mklanghelp --home=#{tmpdir} #{lang} #{null}"
27
+ system "cd #{tmpdir}; sort #{old_e} > #{old_sorted_e}; sort #{new_e} > #{new_sorted_e}"
28
+ yield(File.read(File.join(tmpdir,new_sorted_e))) if block_given?
29
+ assert_file(:expected=>old_sorted_e, :actual=>new_sorted_e, :basedir=>tmpdir)
30
+ ensure
31
+ FileUtils.chdir(tmpdir) {
32
+ FileUtils.rm_f [new_e, old_e, new_sorted_e, old_sorted_e, *Dir['*.yaml']]
33
+ }
34
+ end
35
+ end
36
+
37
+ def test_c()
38
+ _test_lang "c" do |s|
39
+ assert( s =~ /"3 zlib"/ )
40
+ end
41
+ end
42
+
43
+ def test_perl()
44
+ _test_lang "perl" do |s|
45
+ assert( s =~ /perlfunc/ )
46
+ assert( s =~ /perlfaq/ )
47
+ assert( s =~ /alarm/ )
48
+ assert( s =~ /CGI/ )
49
+ end
50
+ end
51
+
52
+ def test_octave()
53
+ _test_lang "octave" do |s|
54
+ assert( s =~ / -- : ODE_options \(void\)/ )
55
+ end
56
+ end
57
+
58
+ def test_ruby()
59
+ _test_lang "ruby" do |s|
60
+ assert( s =~ /BTIME.+proctable.+VERSION/m )
61
+ end
62
+ end
63
+
64
+ def test_python() _test_lang "python" end
65
+
66
+ def test_gauche() _test_lang "scheme" end
67
+
68
+ def test_ratpoisonrc() _test_lang "ratpoisonrc" end
69
+
70
+ def _test_init_file(lang)
71
+ begin
72
+ init_script = File.join(tmpdir, "0init.rb")
73
+ flag_file = File.join(tmpdir, "flag")
74
+ "open('#{flag_file}','w'){}".writef init_script
75
+
76
+ FileUtils.rm_f flag_file
77
+ system "ruby -Ilib bin/mklanghelp --init-script=#{init_script} --home=#{tmpdir} #{lang} #{null}"
78
+ assert_equal true, File.file?(flag_file)
79
+
80
+ FileUtils.rm_f flag_file
81
+ system "ruby -Ilib bin/mklanghelp --init-script=#{init_script} -f --home=#{tmpdir} #{lang} #{null}"
82
+ assert_equal false, File.file?(flag_file)
83
+
84
+
85
+ ensure
86
+ FileUtils.rm_f [init_script, flag_file]
87
+ end
88
+ end
89
+
90
+ def test_init_file() _test_init_file "ratpoisonrc" end
91
+
92
+ end
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'langhelp/parse-info'
4
+ require 'test/common'
5
+ require 'langhelp/langhelp-sub'
6
+
7
+ class TestInfo < Test::Unit::TestCase
8
+ include CheckLink
9
+
10
+ def setup
11
+ @tmpdir=Dir.tmpdir
12
+ @info=File.join @tmpdir, "ratpoison.info"
13
+ @src = <<XXX
14
+ File: ratpoison.info, Node: Manipulating Windows, Next: Unmanaged Windows, Prev: Windows, Up: Windows
15
+
16
+ Manipulating Windows
17
+ ====================
18
+
19
+ The following
20
+
21
+ - Command: select N
22
+ This jumps
23
+
24
+ hoge
25
+ ****
26
+
27
+ - Command: select WINDOW-NAME
28
+ Go to
29
+
30
+ desclist
31
+ description list.
32
+
33
+ XXX
34
+ open(@info,"w"){|f| f.write @src}
35
+ end
36
+
37
+ def teardown
38
+ FileUtils.rm_f @info
39
+ end
40
+
41
+ def test_info__not_exist
42
+ @x = Info.new :Info=>"does_not_exist_____.info"
43
+ assert_raises(RuntimeError) { @x.to_e "" }
44
+ end
45
+
46
+ def test_info
47
+ @x = Info.new :Info=>@info
48
+
49
+ check_link <<XXX
50
+ # Node: Manipulating Windows\t(lh-info nil\t"(ratpoison)Manipulating Windows")
51
+ # (lh-info " - Command: select N"\t"(ratpoison)Manipulating Windows")
52
+ # (lh-info "hoge"\t"(ratpoison)Manipulating Windows")
53
+ # (lh-info " - Command: select WINDOW-NAME"\t"(ratpoison)Manipulating Windows")
54
+ # (lh-info "desclist"\t"(ratpoison)Manipulating Windows")
55
+ XXX
56
+ end
57
+
58
+ def test_info__node
59
+ @x = Info.new :Info=>@info, :extract=>[:node]
60
+
61
+ check_link <<XXX
62
+ # Node: Manipulating Windows\t(lh-info nil\t"(ratpoison)Manipulating Windows")
63
+ XXX
64
+ end
65
+
66
+ def test_info__node_regexp
67
+ @x = Info.new :Info=>@info, :extract=>[:node, :regexp]
68
+
69
+ check_link <<XXX
70
+ # Node: Manipulating Windows\t(lh-info nil\t"(ratpoison)Manipulating Windows")
71
+ # (lh-info " - Command: select N"\t"(ratpoison)Manipulating Windows")
72
+ # (lh-info " - Command: select WINDOW-NAME"\t"(ratpoison)Manipulating Windows")
73
+ XXX
74
+ end
75
+
76
+ def test_info__regexp
77
+ @x = Info.new :Info=>@info, :extract=>[:regexp]
78
+
79
+ check_link <<XXX
80
+ # (lh-info " - Command: select N"\t"(ratpoison)Manipulating Windows")
81
+ # (lh-info " - Command: select WINDOW-NAME"\t"(ratpoison)Manipulating Windows")
82
+ XXX
83
+ end
84
+
85
+ end
86
+
87
+
88
+ class TestInfoSort < Test::Unit::TestCase
89
+ def test_sort_info_files__0
90
+ @x = Info.allocate
91
+
92
+ assert_equal [], @x.__funcall(:sort_info_files, [])
93
+
94
+ a = %w[/usr/share/info/a.info.gz]
95
+ sorted = a
96
+ assert_equal sorted, @x.__funcall(:sort_info_files, a)
97
+ end
98
+
99
+ def test_sort_info_files__1
100
+ @x = Info.allocate
101
+ a = %w[
102
+ /usr/share/info/a.info-10.gz
103
+ /usr/share/info/a.info-1.gz
104
+ /usr/share/info/a.info-2.gz
105
+ ]
106
+
107
+ sorted = %w[
108
+ /usr/share/info/a.info-1.gz
109
+ /usr/share/info/a.info-2.gz
110
+ /usr/share/info/a.info-10.gz
111
+ ]
112
+
113
+ assert_equal sorted, @x.__funcall(:sort_info_files, a)
114
+ end
115
+
116
+ def test_sort_info_files__2
117
+ @x = Info.allocate
118
+ a = %w[
119
+ /usr/share/info/a.info-10
120
+ /usr/share/info/a.info-1
121
+ /usr/share/info/a.info-2
122
+ ]
123
+
124
+ sorted = %w[
125
+ /usr/share/info/a.info-1
126
+ /usr/share/info/a.info-2
127
+ /usr/share/info/a.info-10
128
+ ]
129
+
130
+ assert_equal sorted, @x.__funcall(:sort_info_files, a)
131
+ end
132
+
133
+ end
134
+
135
+
136
+ class TestParseInfoResult < Test::Unit::TestCase
137
+
138
+ def setup
139
+
140
+ end
141
+
142
+ def teardown
143
+
144
+ end
145
+
146
+ #disabled
147
+ def test_0
148
+ end
149
+ def xtest_index
150
+ ary = YAML.load <<EOY
151
+ ---
152
+ - !ruby/struct:Info::Result
153
+ info: gauche-refe
154
+ node: Bitwise operations
155
+ line: " -- Function: copy-bit index n bit"
156
+ - !ruby/struct:Info::Result
157
+ info: gauche-refe
158
+ node: Arithmetics
159
+ line: " -- Function: `+' z ..."
160
+ - !ruby/struct:Info::Result
161
+ info: ratpoison
162
+ node: Manipulating Windows
163
+ line: " - Command: select WINDOW-NAME"
164
+ EOY
165
+ copy_bit = ary[0]
166
+ assert_equal('copy-bit', copy_bit.index)
167
+
168
+ plus = ary[1]
169
+ assert_equal('+', plus.index)
170
+
171
+ rp = ary[2]
172
+ assert_equal('select', rp.index)
173
+
174
+ end
175
+ end
data/test/test-ruby.rb ADDED
@@ -0,0 +1,242 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'langhelp/lh_ruby'
4
+ require 'fileutils'
5
+ require 'test/common'
6
+
7
+ class TestList < Test::Unit::TestCase
8
+ def setup
9
+ Dir.chdir "test"
10
+ end
11
+
12
+ def teardown
13
+ Dir.chdir ".."
14
+ end
15
+
16
+ def test_methods_from_anchor
17
+ x = List.methods_from_anchor("doc", "testdoc.rd")
18
+ assert_equal("doc", x.source)
19
+ assert_equal(%w[A.new A#a], x.methods)
20
+ assert_equal("testdoc.rd", x.arg)
21
+ end
22
+ end
23
+
24
+
25
+
26
+
27
+ class TestRubyIndex < Test::Unit::TestCase
28
+ def setup
29
+ Dir.chdir "test"
30
+ end
31
+
32
+ def teardown
33
+ Dir.chdir ".."
34
+ end
35
+
36
+ def test_contents_ab
37
+ @x = RubyIndex.new(:sources => ["a", "b"])
38
+
39
+
40
+ expected = [
41
+ %w[lh-a A],
42
+ %w[lh-a A#foo],
43
+ %w[lh-b B],
44
+ %w[lh-b B.bar],
45
+ %w[lh-b C],
46
+ %w[lh-b C#baz],
47
+ ]
48
+ assert_equal(expected, a = @x.contents)
49
+ end
50
+
51
+ def test_contents_cd
52
+ @x = RubyIndex.new(:sources => ["c", "d"])
53
+
54
+ expected = [
55
+ %w[lh-c A],
56
+ %w[lh-c A#foo],
57
+ %w[lh-d B],
58
+ %w[lh-d B.bar],
59
+ %w[lh-d C],
60
+ %w[lh-d C#baz],
61
+ ]
62
+ assert_equal(expected, @x.contents)
63
+ end
64
+
65
+ def test_contents_new
66
+ args = [
67
+ List.new("a", %w[A.new A#meth]),
68
+ List.new("doc", %w[D.new], "test.rd"),
69
+ List.new("doc", %w[E.new], "test2.rd"),
70
+ List.new("ri", %w[F.new]),
71
+ ]
72
+ @x = RubyIndex.new(:lists=>args)
73
+
74
+ expected = [
75
+ %w[lh-a A.new],
76
+ %w[lh-a A#meth],
77
+ %w[lh-doc D.new test.rd],
78
+ %w[lh-doc E.new test2.rd],
79
+ %w[lh-ri F.new],
80
+ ]
81
+ assert_equal(expected, @x.contents)
82
+ end
83
+ end
84
+
85
+
86
+ class TestMoonWolfRubyDocConverter < Test::Unit::TestCase
87
+ def test_create_anchor
88
+ input = <<EOS
89
+ #EmptyElementTag
90
+
91
+ <h2><a name="EmptyElementTag">EmptyElementTag</a></h2>
92
+ �����ǤΥ���
93
+ <h3>���饹�᥽�å�</h3>
94
+ <dl compact>
95
+ <dt>new(<var class="String">name</var>[,<var class="Hash">attr</var>])
96
+ <dd>���������֥������Ȥ��������롣 <var class="String">name</var>�ϥ�����̾�� <var c
97
+ </dl>
98
+ <h3>�᥽�å�</h3>
99
+ <dl compact>
100
+ <dt class="String">name
101
+ <dd>����̾���֤���
102
+ <dt class="Hash">attr
103
+ <dd>°�����֤���
104
+ <dt class="String">to_s
105
+ <dd>HTML���֤���
106
+ <dt class="String">self[<var class="String">key</var>]
107
+ <dd>key�˴�Ϣ�Ť���줿°���ͤ��֤��ޤ���
108
+ �������륭������Ͽ����Ƥ��ʤ����ˤϡ�nil���֤��ޤ���
109
+ <dt class="String">self[<var class="String">key</var>]= <var class="String">value</var>
110
+ <dd><var class="String">key</var>���Ф���<var class="String">value</var>���Ϣ�Ť���
111
+ <var class="String">value</var>��nil�λ���<var class="String">key</var>���Ф���
112
+ </dl>
113
+ EOS
114
+
115
+ output = <<'EOS'
116
+ #{{EmptyElementTag}}
117
+
118
+ <h2><a name="EmptyElementTag">EmptyElementTag</a></h2>
119
+ �����ǤΥ���
120
+ <h3>���饹�᥽�å�</h3>
121
+ <dl compact>
122
+ <dt>{{EmptyElementTag.new}}(<var class="String">name</var>[,<var class="Hash">attr</var>])
123
+ <dd>���������֥������Ȥ��������롣 <var class="String">name</var>�ϥ�����̾�� <var c
124
+ </dl>
125
+ <h3>�᥽�å�</h3>
126
+ <dl compact>
127
+ <dt class="String">{{EmptyElementTag#name}}
128
+ <dd>����̾���֤���
129
+ <dt class="Hash">{{EmptyElementTag#attr}}
130
+ <dd>°�����֤���
131
+ <dt class="String">{{EmptyElementTag#to_s}}
132
+ <dd>HTML���֤���
133
+ <dt class="String">{{EmptyElementTag#[]}} self[<var class="String">key</var>]
134
+ <dd>key�˴�Ϣ�Ť���줿°���ͤ��֤��ޤ���
135
+ �������륭������Ͽ����Ƥ��ʤ����ˤϡ�nil���֤��ޤ���
136
+ <dt class="String">{{EmptyElementTag#[]=}} self[<var class="String">key</var>]= <var class="String">value</var>
137
+ <dd><var class="String">key</var>���Ф���<var class="String">value</var>���Ϣ�Ť���
138
+ <var class="String">value</var>��nil�λ���<var class="String">key</var>���Ф���
139
+ </dl>
140
+ EOS
141
+
142
+ assert_equal(output, MoonWolfRubyDocConverter.new(input).create_anchor)
143
+
144
+ end
145
+ end
146
+
147
+
148
+ class TestRDConverter < Test::Unit::TestCase
149
+
150
+ def scenario
151
+ assert_equal(@output, RDConverter.new(@input).create_anchor)
152
+ end
153
+
154
+ def test_method_list__class_method
155
+ @input = <<EOS
156
+ --- ProcTable.fields
157
+ Returns a list of fields available on the current OS. May also take a
158
+ block.
159
+ EOS
160
+ @output = <<EOS
161
+ --- <<<ProcTable.fields>>>
162
+ Returns a list of fields available on the current OS. May also take a
163
+ block.
164
+ EOS
165
+ scenario
166
+
167
+ @input = '--- ProcTable.ps(pid=nil)'
168
+ @output = '--- <<<ProcTable.ps>>>(pid=nil)'
169
+ scenario
170
+
171
+ @input = '--- ProcTable.ps{ |s| ... }'
172
+ @output = '--- <<<ProcTable.ps>>>{ |s| ... }'
173
+ scenario
174
+
175
+ @input = '--- ProcTable::ps{ |s| ... }'
176
+ @output = '--- <<<ProcTable::ps>>>{ |s| ... }'
177
+ scenario
178
+
179
+ end
180
+
181
+ def test_method_list__instance_method
182
+ @input = '--- ProcTable#ps{ |s| ... }'
183
+ @output = '--- <<<ProcTable#ps>>>{ |s| ... }'
184
+ scenario
185
+ end
186
+ end
187
+
188
+ class TestRD < Test::Unit::TestCase
189
+ include CheckLink
190
+
191
+ def setup
192
+ @tmpdir=Dir.tmpdir
193
+ @rd=File.join @tmpdir, "index.rd"
194
+ @src = <<XXX
195
+ =begin
196
+ = Headline1
197
+ a
198
+
199
+ ==Headline2
200
+ b
201
+ :Desclist1
202
+ c
203
+ : Desclist2
204
+
205
+ --- MethodList
206
+ d
207
+ --- Foo#bar(arg="")
208
+ e
209
+ =end
210
+ XXX
211
+ open(@rd,"w"){|f| f.write @src}
212
+ end
213
+
214
+ def teardown
215
+ FileUtils.rm_f @rd
216
+ end
217
+
218
+ def test_rd
219
+ @x = RD.new :RD=>@rd
220
+
221
+ check_link <<XXX
222
+ # (lh-view "= Headline1"\t"#{@rd}")
223
+ # (lh-view "==Headline2"\t"#{@rd}")
224
+ # (lh-view ":Desclist1"\t"#{@rd}")
225
+ # (lh-view ": Desclist2"\t"#{@rd}")
226
+ # (lh-view "--- MethodList"\t"#{@rd}")
227
+ # (lh-view "--- Foo#bar(arg=\\"\\")"\t"#{@rd}")
228
+ XXX
229
+ end
230
+
231
+ def test_rd__exclude
232
+ @x = RD.new :RD=>@rd, :exclude=>/Desclist/
233
+
234
+ check_link <<XXX
235
+ # (lh-view "= Headline1"\t"#{@rd}")
236
+ # (lh-view "==Headline2"\t"#{@rd}")
237
+ # (lh-view "--- MethodList"\t"#{@rd}")
238
+ # (lh-view "--- Foo#bar(arg=\\"\\")"\t"#{@rd}")
239
+ XXX
240
+ end
241
+
242
+ end