rttool 1.0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ require 'rt/rt2html-lib'
2
+ require 'test/unit'
3
+
4
+ include RT
5
+ class RT2HTMLVisitorTest < Test::Unit::TestCase
6
+ def setup
7
+ @x = RT2HTMLVisitor::new
8
+ @x.visit(RTParser::parse(<<-END))
9
+ caption = Test Table
10
+
11
+ , Human, == , Dog , ==
12
+ || , M , F ,M,F
13
+
14
+ x , 1.0 , 2.0, 1.1, 1.2
15
+ y , 0.4 , 0.5, 0.3, 0.1
16
+ END
17
+ end
18
+
19
+ def uncomment(str)
20
+ rep = "\001"
21
+ #if str =~ /\A<!--\s+.+?\s+-->\n(.+)<!--\s+.+?\s+-->\n\n\Z/p# POSIX
22
+ if str.gsub(/\n/, rep) =~ /\A<!--\s+.+?\s+-->#{rep}(.+)<!--\s+.+?\s+-->#{rep}#{rep}\Z/
23
+ #$1
24
+ $1.gsub(/#{rep}/, "\n")
25
+ else
26
+ assert_fail("not RTBlock format")
27
+ end
28
+ end
29
+
30
+ def test_setup
31
+ lines =
32
+ %Q[<table border="1">\n] +
33
+ %Q[<caption>Test Table</caption>\n]
34
+ assert_equal(lines, uncomment(@x.setup))
35
+ end
36
+
37
+ def test_teardown
38
+ assert_equal(%Q[</table>\n], uncomment(@x.teardown))
39
+ end
40
+
41
+ def test_visit_Header
42
+ lines =
43
+ %Q[<thead>\n] +
44
+ %Q[<tr><th rowspan="2"></th><th colspan="2">Human</th><th colspan="2">Dog</th></tr>\n] +
45
+ %Q[<tr><th>M</th><th>F</th><th>M</th><th>F</th></tr>\n] +
46
+ %Q[</thead>\n]
47
+ assert_equal(lines, uncomment(@x.visit_Header))
48
+ end
49
+
50
+ def test_visit_Body
51
+ lines =
52
+ %Q[<tbody>\n] +
53
+ %Q[<tr><td align="left">x</td><td align="right">1.0</td><td align="right">2.0</td><td align="right">1.1</td><td align="right">1.2</td></tr>\n] +
54
+ %Q[<tr><td align="left">y</td><td align="right">0.4</td><td align="right">0.5</td><td align="right">0.3</td><td align="right">0.1</td></tr>\n] +
55
+ %Q[</tbody>\n]
56
+ assert_equal(lines, uncomment(@x.visit_Body))
57
+ end
58
+
59
+ def test0
60
+ assert_equal(RT::RTCell, RT::RTCell::new("a").class)
61
+ end
62
+
63
+ end
64
+
65
+
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/ruby
2
+ require 'rt/rtparser'
3
+ require 'test/unit'
4
+ require 'nkf'
5
+
6
+ include RT
7
+
8
+ class RTCellTest < Test::Unit::TestCase
9
+ def test_equal
10
+ assert_equal(RTCell::new(""), RTCell::new("", :left))
11
+ assert_equal(RTCell::new(""), RTCell::new("", :right))
12
+ assert_equal(RTCell::new(""), RTCell::new("", :center))
13
+ end
14
+ def test_align
15
+ assert_equal(:left, RTCell::new("value").align)
16
+ assert_equal(:left, RTCell::new("value", :left).align)
17
+ assert_equal(:left, RTCell::new("1", :left).align)
18
+ assert_equal(:center, RTCell::new("value", :center).align)
19
+ assert_equal(:center, RTCell::new("1.90", :center).align)
20
+ assert_equal(:right, RTCell::new("1.1kg").align)
21
+ assert_equal(:right, RTCell::new("value", :right).align)
22
+ assert_raises(RuntimeError){ RTCell::new("value", :error)}
23
+ end
24
+ end
25
+
26
+
27
+ module CellShortcut
28
+ def c(x)
29
+ RTCell::new(x,:center)
30
+ end
31
+
32
+ def l(x)
33
+ RTCell::new(x, :left)
34
+ end
35
+
36
+ def r(x)
37
+ RTCell::new(x, :right)
38
+ end
39
+ private :c, :l, :r
40
+ end
41
+
42
+ class RTParserTest < Test::Unit::TestCase
43
+ def setup
44
+ @x = RTParser::new
45
+ end
46
+
47
+ def test_blocks
48
+ blocks = lambda{|str| @x.make_blocks(str).blocks}
49
+
50
+ # no block
51
+ assert_equal([[], [], []], blocks.call(""))
52
+ # 1 block: body
53
+ assert_equal([[], [], ["body"]], blocks.call("body"))
54
+ # 2 blocks: config body
55
+ assert_equal([["config"], [], ["body"]] ,blocks.call("config\n\nbody"))
56
+ # 3 blocks: config header body
57
+ assert_equal([["config1", "config2"], ["header"], ["body"]], blocks.call("config1\nconfig2\n\nheader\n\nbody"))
58
+ assert_raises(RuntimeError){ blocks.call("config\n\nheader\n\nbody\n\nextra")}
59
+ end
60
+
61
+ def test_parse_config
62
+ dc = RTParser::DefaultConfig
63
+ pc = lambda{|config_line| @x.parse_config(config_line).config}
64
+ assert_equal(dc, pc.call([]))
65
+ assert_equal(dc.update("p1"=>"v1", "p2"=>"v2", "p3"=>"v3"),
66
+ pc.call(["p1 = v1", "#comment", " p2= v2", "p3=v3"]))
67
+ assert_equal(dc.update("p1"=>"\t"), pc.call(["p1 = \t"]))
68
+ assert_raises(RuntimeError){ pc.call(["p1 = v1", "error"])}
69
+ end
70
+
71
+ include CellShortcut
72
+
73
+ def test_parse_header
74
+ ph = lambda{|header_line| @x.parse_header(header_line).header}
75
+ assert_equal([ [c(""), c("wide"), "==", c("std")],
76
+ [c("x"), c("1"), c("x2"), c("tall")],
77
+ [c(""), c("y1"), c("y2"), "||"]],
78
+ ph.call([ " , wide, == , std",
79
+ "#comment",
80
+ " x , 1 , x2, tall",
81
+ " , y1 , y2, || "]))
82
+
83
+ assert_equal([[c(""), c("x"), c("y"), c("z")]],
84
+ ph.call(["\t,x\t ,y \t,z"]))
85
+ assert_equal([[c(""), c("X"), c("Y"), c("Z")]],
86
+ ph.call(["\tX\t\tY\tZ"]))
87
+ assert_equal([[c(""), c("1999"), c(""), c("2000"), c("")]],
88
+ ph.call([",\t1999,\t,\t2000,"]))
89
+
90
+ assert_raises(RuntimeError){
91
+ ph.call([ " , wide, == , std",
92
+ "#comment",
93
+ " , x1 , differenterror ",
94
+ ", y1 , y2, == "])}
95
+ end
96
+
97
+ def test_parse_body
98
+ pb = lambda{|body_line| @x.parse_body(body_line).body}
99
+ assert_equal([ [c(""), l("wide"), "==", r("-101")],
100
+ [c(""), r("2.2kg"), r("2L"), l("tall")],
101
+ [c(""), l("y1"), l("y2"), "||"],
102
+ [l("a"),l("b"), c(""), c("")]],
103
+ pb.call([ "#comment-----------",
104
+ " , wide, == , -101",
105
+ " , 2.2kg, 2L, tall",
106
+ ", y1 , y2, ||",
107
+ "a, b,,"]))
108
+ end
109
+
110
+ def test_calc_span
111
+ tbl = [ [c(""), l("wide"), "==", "=="],
112
+ [c(""), r("2.2kg"), r("2L"), l("tall")],
113
+ [c(""), l("y1"), l("y2"), "||"]]
114
+
115
+ @x.calc_span(tbl)
116
+ assert_equal(1, tbl[0][0].rowspan)
117
+ assert_equal(1, tbl[0][0].colspan)
118
+ assert_equal(3, tbl[0][1].colspan)
119
+ assert_equal(2, tbl[1][3].rowspan)
120
+ end
121
+
122
+
123
+
124
+ end
125
+
126
+ class RTParseTest < Test::Unit::TestCase
127
+ include CellShortcut
128
+ module CRLF
129
+ include NKF
130
+ def to_unix(str)
131
+ nkf("-Lu", str)
132
+ end
133
+
134
+ def to_dos(str)
135
+ nkf("-Lw", str)
136
+ end
137
+
138
+ def to_mac(str)
139
+ nkf("-Lm", str)
140
+ end
141
+ end
142
+
143
+ def setup
144
+ @rt = <<-END
145
+ delimiter = ;
146
+ rowspan = @
147
+
148
+ ; x ; @
149
+
150
+ z ; 1 ; 2
151
+ zz ; 3 ; 4
152
+ END
153
+ end
154
+
155
+ def check
156
+ assert_equal(';', @x.config['delimiter'])
157
+ assert_equal('@', @x.config['rowspan'])
158
+ assert_equal([[c(""), c("x"), "@"]], @x.header)
159
+ assert_equal([ [l("z"), r("1"), r("2")],
160
+ [l("zz"),r("3"), r("4")],
161
+ ], @x.body)
162
+ end
163
+
164
+ include CRLF
165
+
166
+ def test_unix
167
+ @x = RTParser::parse(to_unix(@rt))
168
+ check
169
+ end
170
+
171
+ def test_dos
172
+ @x = RTParser::parse(to_dos(@rt))
173
+ check
174
+ end
175
+
176
+ def test_mac
177
+ @x = RTParser::parse(to_mac(@rt))
178
+ check
179
+ end
180
+
181
+ end
182
+
183
+
184
+ class RTParseWithEscapeTest
185
+ def test__parse__with_escape1
186
+ x = RTParser::parse <<-'END'
187
+ delimiter = ;
188
+ escape = %
189
+
190
+ %z ; %;1 ; 2
191
+ END
192
+
193
+ assert_equal(';', x.config['delimiter'])
194
+ assert_equal([ [l("%z"), l(";1"), r("2")],], x.body)
195
+ end
196
+
197
+ def test__parse__with_escape2
198
+ x = RTParser::parse <<-'END'
199
+ delimiter = ;
200
+ escape = \
201
+
202
+ \z ; \;1 ; 2
203
+ END
204
+
205
+ assert_equal(';', x.config['delimiter'])
206
+ assert_equal([ [l("\\z"), l(";1"), r("2")],], x.body)
207
+ end
208
+
209
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ require 'rttool-sub'
4
+
5
+ module Chdir
6
+ def pushd
7
+ @pwd = Dir.pwd
8
+ Dir.chdir File.dirname(File.expand_path(__FILE__))
9
+ end
10
+
11
+ def popd
12
+ Dir.chdir @pwd
13
+ end
14
+ def setup
15
+ pushd
16
+ end
17
+ end
18
+
19
+ class TestRTtool < Test::Unit::TestCase
20
+ =begin eev
21
+ = How to make test files
22
+  (eecd2)
23
+ cd ../examples/; rt2 -r rt/rt2html-lib test1.rt > test1.html
24
+ cd ../examples/; rt2 -r rt/rt2html-lib test2.rt > test2.html
25
+ cd ../examples/; rt2 -r rt/rt2html-lib escape.rt > escape.html
26
+ cd ../examples/; rd2 --with-part=RT:rt rttest.rd > rttest.html
27
+ =end
28
+ include Chdir
29
+ def teardown
30
+ rt2html
31
+ popd
32
+ end
33
+
34
+ def rt2html
35
+ @html = "#{@name}.html"
36
+ @rt = "#{@name}.rt"
37
+ AssertFile.basedir = "../examples"
38
+ AssertFile.transaction(@html) do |html|
39
+ system_safe "cd ../examples; ruby -I../lib ../bin/rt/rt2 -r rt/rt2html-lib #{@rt} > #{html}"
40
+ end
41
+ end
42
+
43
+ #
44
+ def test__test1
45
+ # (find-filez "test1.rt test1.html" "../examples/")
46
+ @name = "test1"
47
+ end
48
+ #
49
+
50
+ def test__test2
51
+ # (find-filez "test2.rt test2.html" "../examples/")
52
+ @name = "test2"
53
+ end
54
+
55
+ def test__escape
56
+ # (find-filez "escape.rt escape.html" "../examples/")
57
+ @name = "escape"
58
+ end
59
+
60
+ end
61
+
62
+
63
+ class TestRDRT2 < Test::Unit::TestCase
64
+
65
+ include Chdir
66
+
67
+ def teardown
68
+ rdrt2
69
+ popd
70
+ end
71
+
72
+ def rdrt2
73
+ ENV['RUBYLIB'] = "../lib"
74
+ @html = "#{@name}.html"
75
+ @rd = "#{@name}.rd"
76
+ AssertFile.basedir = "../examples"
77
+ AssertFile.transaction(@html) do |html|
78
+ system_safe "cd ../examples; ruby ../bin/rt/rdrt2 #{@rd} > #{html}"
79
+ end
80
+ end
81
+
82
+ def test_rttest
83
+ # (find-filez "rttest.rd rttest.html" "../examples/")
84
+ @name = "rttest"
85
+ end
86
+
87
+
88
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: rttool
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.2.0
7
+ date: 2007-02-21 00:00:00 +09:00
8
+ summary: Simple table generator
9
+ require_paths:
10
+ - lib
11
+ email: zn@mbf.nifty.com
12
+ homepage: http://raa.ruby-lang.org/project/rttool/
13
+ rubyforge_project: rwiki
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - rubikitch
31
+ - Kazuhiro NISHIYAMA
32
+ files:
33
+ - ChangeLog
34
+ - GPL
35
+ - bin/rt/rdrt2
36
+ - bin/rt/rt2
37
+ - examples/easiest.html
38
+ - examples/easiest.rt
39
+ - examples/escape.html
40
+ - examples/escape.rt
41
+ - examples/rttest.html
42
+ - examples/rttest.rd
43
+ - examples/test1.html
44
+ - examples/test1.rt
45
+ - examples/test2.html
46
+ - examples/test2.rt
47
+ - lib/rd/rt-filter.rb
48
+ - lib/rt/rt2html-lib.rb
49
+ - lib/rt/rt2txt-lib.rb
50
+ - lib/rt/rtparser.rb
51
+ - lib/rt/rtvisitor.rb
52
+ - lib/rt/w3m.rb
53
+ - rttool.en.html
54
+ - rttool.en.rd
55
+ - rttool.ja.html
56
+ - rttool.ja.rd
57
+ - test/rttool-sub.rb
58
+ - test/test-rt2html-lib.rb
59
+ - test/test-rtparser.rb
60
+ - test/test.rb
61
+ test_files: []
62
+
63
+ rdoc_options: []
64
+
65
+ extra_rdoc_files: []
66
+
67
+ executables:
68
+ - rt/rdrt2
69
+ - rt/rt2
70
+ extensions: []
71
+
72
+ requirements: []
73
+
74
+ dependencies: []
75
+