tb 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +62 -50
- data/bin/tb +22 -18
- data/lib/tb.rb +35 -19
- data/lib/tb/basic.rb +85 -86
- data/lib/tb/catreader.rb +33 -116
- data/lib/tb/cmd_cat.rb +31 -27
- data/lib/tb/cmd_consecutive.rb +45 -35
- data/lib/tb/cmd_crop.rb +86 -52
- data/lib/tb/cmd_cross.rb +113 -71
- data/lib/tb/cmd_cut.rb +49 -44
- data/lib/tb/cmd_git_log.rb +193 -0
- data/lib/tb/cmd_grep.rb +43 -32
- data/lib/tb/cmd_group.rb +63 -39
- data/lib/tb/cmd_gsub.rb +53 -43
- data/lib/tb/cmd_help.rb +51 -24
- data/lib/tb/cmd_join.rb +32 -35
- data/lib/tb/cmd_ls.rb +233 -205
- data/lib/tb/cmd_mheader.rb +47 -37
- data/lib/tb/cmd_nest.rb +94 -0
- data/lib/tb/cmd_newfield.rb +29 -33
- data/lib/tb/cmd_rename.rb +40 -32
- data/lib/tb/cmd_shape.rb +31 -24
- data/lib/tb/cmd_sort.rb +46 -25
- data/lib/tb/cmd_svn_log.rb +47 -28
- data/lib/tb/cmd_tar_tvf.rb +447 -0
- data/lib/tb/cmd_to_csv.rb +60 -0
- data/lib/tb/cmd_to_json.rb +60 -0
- data/lib/tb/cmd_to_pnm.rb +48 -0
- data/lib/tb/cmd_to_pp.rb +71 -0
- data/lib/tb/cmd_to_tsv.rb +48 -0
- data/lib/tb/cmd_to_yaml.rb +52 -0
- data/lib/tb/cmd_unnest.rb +118 -0
- data/lib/tb/cmdmain.rb +24 -20
- data/lib/tb/cmdtop.rb +33 -25
- data/lib/tb/cmdutil.rb +26 -66
- data/lib/tb/csv.rb +46 -34
- data/lib/tb/enum.rb +294 -0
- data/lib/tb/enumerable.rb +198 -7
- data/lib/tb/enumerator.rb +73 -0
- data/lib/tb/fieldset.rb +27 -19
- data/lib/tb/fileenumerator.rb +365 -0
- data/lib/tb/json.rb +50 -0
- data/lib/tb/pager.rb +6 -6
- data/lib/tb/pairs.rb +227 -0
- data/lib/tb/pnm.rb +23 -22
- data/lib/tb/reader.rb +52 -49
- data/lib/tb/record.rb +48 -19
- data/lib/tb/revcmp.rb +38 -0
- data/lib/tb/ropen.rb +74 -57
- data/lib/tb/search.rb +25 -21
- data/lib/tb/tsv.rb +31 -34
- data/sample/excel2csv +24 -20
- data/sample/poi-xls2csv.rb +24 -20
- data/sample/poi-xls2csv.sh +22 -18
- data/sample/tbplot +185 -127
- data/test-all-cov.rb +3 -3
- data/test-all.rb +1 -1
- data/test/test_basic.rb +26 -10
- data/test/test_catreader.rb +7 -6
- data/test/test_cmd_cat.rb +32 -0
- data/test/test_cmd_consecutive.rb +10 -0
- data/test/test_cmd_crop.rb +4 -4
- data/test/test_cmd_cross.rb +16 -4
- data/test/test_cmd_git_log.rb +46 -0
- data/test/test_cmd_help.rb +17 -12
- data/test/test_cmd_join.rb +21 -1
- data/test/test_cmd_ls.rb +3 -4
- data/test/test_cmd_mheader.rb +17 -11
- data/test/test_cmd_nest.rb +49 -0
- data/test/test_cmd_sort.rb +15 -0
- data/test/test_cmd_tar_tvf.rb +281 -0
- data/test/{test_cmd_csv.rb → test_cmd_to_csv.rb} +35 -21
- data/test/{test_cmd_json.rb → test_cmd_to_json.rb} +31 -3
- data/test/{test_cmd_pnm.rb → test_cmd_to_pnm.rb} +2 -2
- data/test/{test_cmd_pp.rb → test_cmd_to_pp.rb} +4 -4
- data/test/{test_cmd_tsv.rb → test_cmd_to_tsv.rb} +4 -4
- data/test/{test_cmd_yaml.rb → test_cmd_to_yaml.rb} +3 -3
- data/test/test_cmd_unnest.rb +89 -0
- data/test/test_cmdtty.rb +19 -13
- data/test/test_enumerable.rb +83 -1
- data/test/test_fileenumerator.rb +265 -0
- data/test/test_json.rb +15 -0
- data/test/test_pager.rb +3 -4
- data/test/test_pairs.rb +122 -0
- data/test/test_pnm.rb +24 -24
- data/test/test_reader.rb +35 -13
- data/test/test_revcmp.rb +10 -0
- data/test/test_tbenum.rb +173 -0
- metadata +51 -23
- data/lib/tb/cmd_csv.rb +0 -42
- data/lib/tb/cmd_json.rb +0 -60
- data/lib/tb/cmd_pnm.rb +0 -43
- data/lib/tb/cmd_pp.rb +0 -70
- data/lib/tb/cmd_tsv.rb +0 -43
- data/lib/tb/cmd_yaml.rb +0 -47
data/test-all-cov.rb
CHANGED
@@ -17,10 +17,10 @@ at_exit {
|
|
17
17
|
%r{lib/tb[/.]} !~ f
|
18
18
|
}
|
19
19
|
if !fs.empty?
|
20
|
-
if
|
20
|
+
if $stdout.tty?
|
21
21
|
out = IO.popen(['less', '-S', '-j20', '+/ 0:'], 'w')
|
22
22
|
else
|
23
|
-
out =
|
23
|
+
out = $stdout
|
24
24
|
end
|
25
25
|
pat = nil
|
26
26
|
fs[0].chars.to_a.reverse_each {|ch|
|
@@ -55,7 +55,7 @@ at_exit {
|
|
55
55
|
end
|
56
56
|
}
|
57
57
|
}
|
58
|
-
if out !=
|
58
|
+
if out != $stdout
|
59
59
|
out.close
|
60
60
|
end
|
61
61
|
end
|
data/test-all.rb
CHANGED
data/test/test_basic.rb
CHANGED
@@ -208,10 +208,10 @@ class TestTbBasic < Test::Unit::TestCase
|
|
208
208
|
t1 = Tb.new %w[a b], %w[1 2], %w[3 4], %w[0 4]
|
209
209
|
t2 = Tb.new %w[b c], %w[2 3], %w[4 5], %w[5 8]
|
210
210
|
t3 = t1.natjoin2(t2)
|
211
|
-
assert_equal([{"
|
212
|
-
{"
|
213
|
-
{"
|
214
|
-
t3.to_a.map {|r| r.
|
211
|
+
assert_equal([{"a"=>"1", "b"=>"2", "c"=>"3"},
|
212
|
+
{"a"=>"3", "b"=>"4", "c"=>"5"},
|
213
|
+
{"a"=>"0", "b"=>"4", "c"=>"5"}],
|
214
|
+
t3.to_a.map {|r| r.to_h })
|
215
215
|
end
|
216
216
|
|
217
217
|
def test_natjoin2_nocommon
|
@@ -229,12 +229,12 @@ class TestTbBasic < Test::Unit::TestCase
|
|
229
229
|
t1 = Tb.new %w[a b], %w[1 2], %w[3 4], %w[0 4], %w[0 1]
|
230
230
|
t2 = Tb.new %w[b c], %w[2 3], %w[4 5], %w[5 8]
|
231
231
|
t3 = t1.natjoin2_outer(t2)
|
232
|
-
assert_equal([{"
|
233
|
-
{"
|
234
|
-
{"
|
235
|
-
{"
|
236
|
-
{"
|
237
|
-
t3.to_a.map {|r| r.
|
232
|
+
assert_equal([{"a"=>"0", "b"=>"1"},
|
233
|
+
{"a"=>"1", "b"=>"2", "c"=>"3"},
|
234
|
+
{"a"=>"3", "b"=>"4", "c"=>"5"},
|
235
|
+
{"a"=>"0", "b"=>"4", "c"=>"5"},
|
236
|
+
{"b"=>"5", "c"=>"8"}],
|
237
|
+
t3.to_a.map {|r| r.to_h })
|
238
238
|
end
|
239
239
|
|
240
240
|
def test_fmap!
|
@@ -384,4 +384,20 @@ class TestTbBasic < Test::Unit::TestCase
|
|
384
384
|
assert_equal([['banana', 'yellow'], ['orange', 'orange']], rs)
|
385
385
|
end
|
386
386
|
|
387
|
+
def test_with_header
|
388
|
+
t = Tb.new %w[a b], [1, 2], [3, 4]
|
389
|
+
result = []
|
390
|
+
t.with_header {|x|
|
391
|
+
result << x
|
392
|
+
}.each {|x|
|
393
|
+
result << x
|
394
|
+
}
|
395
|
+
assert_equal(3, result.length)
|
396
|
+
assert_equal(%w[a b], result[0])
|
397
|
+
assert_kind_of(Tb::Record, result[1])
|
398
|
+
assert_kind_of(Tb::Record, result[2])
|
399
|
+
assert_equal([["a", 1], ["b", 2]], result[1].to_a)
|
400
|
+
assert_equal([["a", 3], ["b", 4]], result[2].to_a)
|
401
|
+
end
|
402
|
+
|
387
403
|
end
|
data/test/test_catreader.rb
CHANGED
@@ -14,12 +14,13 @@ class TestTbCatReader < Test::Unit::TestCase
|
|
14
14
|
3,4
|
15
15
|
End
|
16
16
|
Tb::CatReader.open([i1, i2]) {|r|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
result = []
|
18
|
+
r.with_header {|header|
|
19
|
+
result << header
|
20
|
+
}.each {|pairs|
|
21
|
+
result << pairs.to_a
|
22
|
+
}
|
23
|
+
assert_equal([%w[a b], [['a','1'], ['b','2']], [['b','3'],['a','4']]], result)
|
23
24
|
}
|
24
25
|
}
|
25
26
|
end
|
data/test/test_cmd_cat.rb
CHANGED
@@ -115,4 +115,36 @@ class TestTbCmdCat < Test::Unit::TestCase
|
|
115
115
|
End
|
116
116
|
end
|
117
117
|
|
118
|
+
def test_with_filename
|
119
|
+
File.open(i1="i1.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
120
|
+
a,b,c
|
121
|
+
1,2,3
|
122
|
+
End
|
123
|
+
File.open(i2="i2.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
124
|
+
a,b,c
|
125
|
+
4,5,6
|
126
|
+
End
|
127
|
+
Tb::Cmd.main_cat(['-o', o="o.csv", '--with-filename', i1, i2])
|
128
|
+
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
129
|
+
filename,a,b,c
|
130
|
+
i1.csv,1,2,3
|
131
|
+
i2.csv,4,5,6
|
132
|
+
End
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_empty
|
136
|
+
File.open(i1="i1.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
137
|
+
a,b,c
|
138
|
+
1,2,3
|
139
|
+
End
|
140
|
+
File.open(i2="i2.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
141
|
+
a,b,c
|
142
|
+
End
|
143
|
+
Tb::Cmd.main_cat(['-o', o="o.csv", '--with-filename', i1, i2])
|
144
|
+
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
145
|
+
filename,a,b,c
|
146
|
+
i1.csv,1,2,3
|
147
|
+
End
|
148
|
+
end
|
149
|
+
|
118
150
|
end
|
@@ -87,4 +87,14 @@ class TestTbCmdConsecutive < Test::Unit::TestCase
|
|
87
87
|
End
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_header_only
|
91
|
+
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
92
|
+
a,b,c
|
93
|
+
End
|
94
|
+
Tb::Cmd.main_consecutive(['-o', o="o.csv", i])
|
95
|
+
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
96
|
+
a_1,a_2,b_1,b_2,c_1,c_2
|
97
|
+
End
|
98
|
+
end
|
99
|
+
|
90
100
|
end
|
data/test/test_cmd_crop.rb
CHANGED
@@ -19,16 +19,16 @@ class TestTbCmdCrop < Test::Unit::TestCase
|
|
19
19
|
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
20
20
|
,,
|
21
21
|
,a,b,,
|
22
|
-
,0,1
|
23
|
-
|
22
|
+
,0,1,,2,
|
23
|
+
,,4,,,
|
24
24
|
,,,
|
25
25
|
|
26
26
|
End
|
27
27
|
Tb::Cmd.main_crop(['-o', o="o.csv", i])
|
28
28
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
29
29
|
a,b
|
30
|
-
0,1
|
31
|
-
4
|
30
|
+
0,1,,2
|
31
|
+
,4
|
32
32
|
End
|
33
33
|
end
|
34
34
|
|
data/test/test_cmd_cross.rb
CHANGED
@@ -23,7 +23,7 @@ class TestTbCmdCross < Test::Unit::TestCase
|
|
23
23
|
bbbb,2000,4
|
24
24
|
cccc,2002,5
|
25
25
|
End
|
26
|
-
Tb::Cmd.main_cross(['-o', o="o.csv", '
|
26
|
+
Tb::Cmd.main_cross(['-o', o="o.csv", 'year', 'name', i])
|
27
27
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
28
28
|
name,aaaa,bbbb,cccc
|
29
29
|
year,count,count,count
|
@@ -43,6 +43,18 @@ class TestTbCmdCross < Test::Unit::TestCase
|
|
43
43
|
assert(!exc.success?)
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_field_not_found
|
47
|
+
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
48
|
+
name,year,observ
|
49
|
+
aaaa,2000,1
|
50
|
+
bbbb,2001,3
|
51
|
+
End
|
52
|
+
exc = assert_raise(SystemExit) { Tb::Cmd.main_cross(['-o', "o.csv", 'foo', 'year', i]) }
|
53
|
+
assert(!exc.success?)
|
54
|
+
exc = assert_raise(SystemExit) { Tb::Cmd.main_cross(['-o', "o.csv", 'name', 'bar', i]) }
|
55
|
+
assert(!exc.success?)
|
56
|
+
end
|
57
|
+
|
46
58
|
def test_compact
|
47
59
|
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
48
60
|
name,year,observ
|
@@ -51,7 +63,7 @@ class TestTbCmdCross < Test::Unit::TestCase
|
|
51
63
|
bbbb,2000,4
|
52
64
|
cccc,2002,5
|
53
65
|
End
|
54
|
-
Tb::Cmd.main_cross(['-o', o="o.csv", '
|
66
|
+
Tb::Cmd.main_cross(['-o', o="o.csv", 'year', 'name', '-c', i])
|
55
67
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
56
68
|
year,aaaa,bbbb,cccc
|
57
69
|
2000,1,1,
|
@@ -69,7 +81,7 @@ class TestTbCmdCross < Test::Unit::TestCase
|
|
69
81
|
cccc,2002,5
|
70
82
|
aaaa,2000,2
|
71
83
|
End
|
72
|
-
Tb::Cmd.main_cross(['-o', o="o.csv", '
|
84
|
+
Tb::Cmd.main_cross(['-o', o="o.csv", 'year', 'name', '-a', 'sum(observ)', i])
|
73
85
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
74
86
|
name,aaaa,bbbb,cccc
|
75
87
|
year,sum(observ),sum(observ),sum(observ)
|
@@ -90,7 +102,7 @@ class TestTbCmdCross < Test::Unit::TestCase
|
|
90
102
|
5,6
|
91
103
|
7,8
|
92
104
|
End
|
93
|
-
Tb::Cmd.main_cross(['-o', o="o.csv", '
|
105
|
+
Tb::Cmd.main_cross(['-o', o="o.csv", 'b', 'a', i1, i2])
|
94
106
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
95
107
|
a,1,3,6,8
|
96
108
|
b,count,count,count,count
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'tb/cmdtop'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
class TestTbCmdGitLog < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Tb::Cmd.reset_option
|
8
|
+
@curdir = Dir.pwd
|
9
|
+
@tmpdir = Dir.mktmpdir
|
10
|
+
Dir.chdir @tmpdir
|
11
|
+
end
|
12
|
+
def teardown
|
13
|
+
Tb::Cmd.reset_option
|
14
|
+
Dir.chdir @curdir
|
15
|
+
FileUtils.rmtree @tmpdir
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_basic
|
19
|
+
system("git init -q")
|
20
|
+
File.open("foo", "w") {|f| f.puts "bar" }
|
21
|
+
system("git add foo")
|
22
|
+
system("git commit -q -m msg foo")
|
23
|
+
Tb::Cmd.main_git_log(['-o', o="o.csv"])
|
24
|
+
result = File.read(o)
|
25
|
+
tb = Tb.parse_csv(result)
|
26
|
+
assert_equal(1, tb.size)
|
27
|
+
assert_match(/,A,foo\n/, tb.get_record(0)["files"])
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_escaped_filename
|
31
|
+
filename = (1..32).to_a.pack("C*") + "\"\\"
|
32
|
+
system("git init -q")
|
33
|
+
File.open(filename, "w") {|f| f.puts "bar" }
|
34
|
+
system("git", "add", filename)
|
35
|
+
system("git", "commit", "-q", "-m", "msg", filename)
|
36
|
+
Tb::Cmd.main_git_log(['-o', o="o.csv"])
|
37
|
+
result = File.read(o)
|
38
|
+
tb = Tb.parse_csv(result)
|
39
|
+
assert_equal(1, tb.size)
|
40
|
+
assert_match(/,A,/, tb.get_record(0)["files"])
|
41
|
+
ftb = Tb.parse_csv(tb.get_record(0)["files"])
|
42
|
+
assert_equal(1, ftb.size)
|
43
|
+
assert_equal(filename, ftb.get_record(0)["filename"])
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/test/test_cmd_help.rb
CHANGED
@@ -16,24 +16,22 @@ class TestTbCmdHelp < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def with_stdout(io)
|
19
|
-
save =
|
20
|
-
|
19
|
+
save = $stdout
|
20
|
+
$stdout = io
|
21
21
|
begin
|
22
22
|
yield
|
23
23
|
ensure
|
24
|
-
|
25
|
-
save.close
|
24
|
+
$stdout = save
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
28
|
def with_stderr(io)
|
30
|
-
save =
|
31
|
-
|
29
|
+
save = $stderr
|
30
|
+
$stderr = io
|
32
31
|
begin
|
33
32
|
yield
|
34
33
|
ensure
|
35
|
-
|
36
|
-
save.close
|
34
|
+
$stderr = save
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
@@ -81,7 +79,7 @@ class TestTbCmdHelp < Test::Unit::TestCase
|
|
81
79
|
msg = th.value
|
82
80
|
r.close
|
83
81
|
assert_match(/Usage:/, msg)
|
84
|
-
assert_match(/ tb csv /, msg)
|
82
|
+
assert_match(/ tb to-csv /, msg)
|
85
83
|
assert_match(/ tb cut /, msg)
|
86
84
|
}
|
87
85
|
end
|
@@ -90,7 +88,7 @@ class TestTbCmdHelp < Test::Unit::TestCase
|
|
90
88
|
assert_equal(true, Tb::Cmd.main(['-h', '-o', o="msg"]))
|
91
89
|
msg = File.read(o)
|
92
90
|
assert_match(/Usage:/, msg)
|
93
|
-
assert_match(/ tb csv /, msg)
|
91
|
+
assert_match(/ tb to-csv /, msg)
|
94
92
|
assert_match(/ tb cut /, msg)
|
95
93
|
end
|
96
94
|
|
@@ -98,7 +96,7 @@ class TestTbCmdHelp < Test::Unit::TestCase
|
|
98
96
|
assert_equal(true, Tb::Cmd.main(['--help', '-o', o="msg"]))
|
99
97
|
msg = File.read(o)
|
100
98
|
assert_match(/Usage:/, msg)
|
101
|
-
assert_match(/ tb csv /, msg)
|
99
|
+
assert_match(/ tb to-csv /, msg)
|
102
100
|
assert_match(/ tb cut /, msg)
|
103
101
|
end
|
104
102
|
|
@@ -106,7 +104,7 @@ class TestTbCmdHelp < Test::Unit::TestCase
|
|
106
104
|
assert_equal(true, Tb::Cmd.main(['help', '-o', o="msg"]))
|
107
105
|
msg = File.read(o)
|
108
106
|
assert_match(/Usage:/, msg)
|
109
|
-
assert_match(/ tb csv /, msg)
|
107
|
+
assert_match(/ tb to-csv /, msg)
|
110
108
|
assert_match(/ tb cut /, msg)
|
111
109
|
end
|
112
110
|
|
@@ -187,4 +185,11 @@ class TestTbCmdHelp < Test::Unit::TestCase
|
|
187
185
|
assert_match(/unexpected subcommand/, exc.message)
|
188
186
|
end
|
189
187
|
|
188
|
+
def test_help_s
|
189
|
+
assert_exit_success(['help', '-o', o="msg", '-s'])
|
190
|
+
msg = File.read(o)
|
191
|
+
assert_match(/Show help message of tb command/, msg)
|
192
|
+
assert_no_match(/Usage:/, msg)
|
193
|
+
end
|
194
|
+
|
190
195
|
end
|
data/test/test_cmd_join.rb
CHANGED
@@ -64,6 +64,26 @@ class TestTbCmdJoin < Test::Unit::TestCase
|
|
64
64
|
End
|
65
65
|
end
|
66
66
|
|
67
|
+
def test_outer2
|
68
|
+
File.open(i1="i1.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
69
|
+
b,c
|
70
|
+
4,5
|
71
|
+
6,7
|
72
|
+
End
|
73
|
+
File.open(i2="i2.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
74
|
+
a,b
|
75
|
+
1,2
|
76
|
+
3,4
|
77
|
+
End
|
78
|
+
Tb::Cmd.main_join(['-o', o="o.csv", '--outer', i1, i2])
|
79
|
+
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
80
|
+
b,c,a
|
81
|
+
2,,1
|
82
|
+
4,5,3
|
83
|
+
6,7,
|
84
|
+
End
|
85
|
+
end
|
86
|
+
|
67
87
|
def test_outer_missing
|
68
88
|
File.open(i1="i1.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
69
89
|
a,b
|
@@ -189,8 +209,8 @@ class TestTbCmdJoin < Test::Unit::TestCase
|
|
189
209
|
Tb::Cmd.main_join(['-o', o="o.csv", '--right', i1, i2, i3])
|
190
210
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
191
211
|
a,b,c,d
|
192
|
-
3,,D,F
|
193
212
|
2,,,E
|
213
|
+
3,,D,F
|
194
214
|
End
|
195
215
|
end
|
196
216
|
|
data/test/test_cmd_ls.rb
CHANGED
@@ -16,13 +16,12 @@ class TestTbCmdLs < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def with_stderr(io)
|
19
|
-
save =
|
20
|
-
|
19
|
+
save = $stderr
|
20
|
+
$stderr = io
|
21
21
|
begin
|
22
22
|
yield
|
23
23
|
ensure
|
24
|
-
|
25
|
-
save.close
|
24
|
+
$stderr = save
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
data/test/test_cmd_mheader.rb
CHANGED
@@ -15,6 +15,16 @@ class TestTbCmdMheader < Test::Unit::TestCase
|
|
15
15
|
FileUtils.rmtree @tmpdir
|
16
16
|
end
|
17
17
|
|
18
|
+
def with_stderr(io)
|
19
|
+
save = $stderr
|
20
|
+
$stderr = io
|
21
|
+
begin
|
22
|
+
yield
|
23
|
+
ensure
|
24
|
+
$stderr = save
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
18
28
|
def test_basic
|
19
29
|
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
20
30
|
,2000,2000,2001,2001
|
@@ -48,18 +58,14 @@ class TestTbCmdMheader < Test::Unit::TestCase
|
|
48
58
|
a,a
|
49
59
|
1,1
|
50
60
|
End
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
save.close
|
61
|
+
o = nil
|
62
|
+
File.open(log="log", "w") {|logf|
|
63
|
+
with_stderr(logf) {
|
64
|
+
Tb::Cmd.main_mheader(['-o', o="o.csv", i])
|
65
|
+
}
|
66
|
+
}
|
58
67
|
assert_equal('', File.read(o))
|
59
|
-
assert_match(/
|
60
|
-
ensure
|
61
|
-
save.close if save && !save.closed?
|
62
|
-
logf.close if logf && !logf.closed?
|
68
|
+
assert_match(/unique header fields not recognized/, File.read(log))
|
63
69
|
end
|
64
70
|
|
65
71
|
def test_twofile
|