tb 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +13 -11
- data/lib/tb.rb +14 -6
- data/lib/tb/catreader.rb +2 -2
- data/lib/tb/cmd_consecutive.rb +6 -2
- data/lib/tb/cmd_crop.rb +22 -3
- data/lib/tb/cmd_cross.rb +24 -0
- data/lib/tb/cmd_cut.rb +20 -10
- data/lib/tb/cmd_git.rb +20 -7
- data/lib/tb/cmd_group.rb +32 -0
- data/lib/tb/cmd_gsub.rb +21 -0
- data/lib/tb/cmd_join.rb +28 -0
- data/lib/tb/cmd_ls.rb +9 -0
- data/lib/tb/cmd_melt.rb +15 -0
- data/lib/tb/cmd_mheader.rb +15 -0
- data/lib/tb/cmd_nest.rb +27 -6
- data/lib/tb/cmd_newfield.rb +19 -2
- data/lib/tb/cmd_rename.rb +20 -0
- data/lib/tb/{cmd_grep.rb → cmd_search.rb} +37 -23
- data/lib/tb/cmd_shape.rb +69 -25
- data/lib/tb/cmd_sort.rb +20 -0
- data/lib/tb/cmd_tar.rb +38 -0
- data/lib/tb/cmd_to_json.rb +2 -2
- data/lib/tb/cmd_to_ltsv.rb +3 -3
- data/lib/tb/cmd_to_pnm.rb +3 -3
- data/lib/tb/cmd_to_tsv.rb +3 -3
- data/lib/tb/cmd_to_yaml.rb +3 -3
- data/lib/tb/cmd_unmelt.rb +15 -0
- data/lib/tb/cmd_unnest.rb +31 -7
- data/lib/tb/cmdmain.rb +2 -0
- data/lib/tb/cmdtop.rb +1 -1
- data/lib/tb/cmdutil.rb +9 -62
- data/lib/tb/csv.rb +21 -79
- data/lib/tb/enumerable.rb +42 -68
- data/lib/tb/enumerator.rb +15 -7
- data/lib/tb/{fieldset.rb → hashreader.rb} +37 -56
- data/lib/tb/hashwriter.rb +54 -0
- data/lib/tb/headerreader.rb +108 -0
- data/lib/tb/headerwriter.rb +116 -0
- data/lib/tb/json.rb +17 -15
- data/lib/tb/ltsv.rb +35 -96
- data/lib/tb/ndjson.rb +63 -0
- data/lib/tb/numericreader.rb +66 -0
- data/lib/tb/numericwriter.rb +61 -0
- data/lib/tb/pnm.rb +206 -200
- data/lib/tb/ropen.rb +54 -59
- data/lib/tb/tsv.rb +39 -71
- data/sample/excel2csv +24 -25
- data/sample/poi-xls2csv.rb +13 -14
- data/tb.gemspec +154 -0
- data/test/test_cmd_cat.rb +28 -6
- data/test/test_cmd_consecutive.rb +8 -3
- data/test/test_cmd_cut.rb +14 -4
- data/test/test_cmd_git_log.rb +50 -50
- data/test/test_cmd_grep.rb +6 -6
- data/test/test_cmd_gsub.rb +7 -2
- data/test/test_cmd_ls.rb +70 -62
- data/test/test_cmd_shape.rb +43 -6
- data/test/test_cmd_svn_log.rb +26 -27
- data/test/test_cmd_to_csv.rb +10 -5
- data/test/test_cmd_to_json.rb +16 -0
- data/test/test_cmd_to_ltsv.rb +2 -2
- data/test/test_cmd_to_pp.rb +7 -2
- data/test/test_csv.rb +74 -62
- data/test/test_ex_enumerable.rb +0 -1
- data/test/test_fileenumerator.rb +3 -3
- data/test/test_headercsv.rb +43 -0
- data/test/test_json.rb +2 -2
- data/test/test_ltsv.rb +22 -17
- data/test/test_ndjson.rb +62 -0
- data/test/test_numericcsv.rb +36 -0
- data/test/test_pnm.rb +69 -70
- data/test/test_reader.rb +27 -124
- data/test/test_tbenum.rb +18 -18
- data/test/test_tsv.rb +21 -32
- data/test/util_tbtest.rb +12 -0
- metadata +41 -19
- data/lib/tb/basic.rb +0 -1070
- data/lib/tb/reader.rb +0 -106
- data/lib/tb/record.rb +0 -158
- data/test/test_basic.rb +0 -403
- data/test/test_fieldset.rb +0 -42
- data/test/test_record.rb +0 -61
data/test/test_cmd_cat.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'tb/cmdtop'
|
3
3
|
require 'tmpdir'
|
4
|
+
require_relative 'util_tbtest'
|
4
5
|
|
5
6
|
class TestTbCmdCat < Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -69,14 +70,18 @@ class TestTbCmdCat < Test::Unit::TestCase
|
|
69
70
|
5,6
|
70
71
|
7,8,y
|
71
72
|
End
|
72
|
-
|
73
|
+
o = "o.csv"
|
74
|
+
stderr = capture_stderr {
|
75
|
+
Tb::Cmd.main_cat(['-o', o, i1, i2])
|
76
|
+
}
|
73
77
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
74
78
|
a,b,c
|
75
79
|
1,2
|
76
|
-
3,4
|
80
|
+
3,4
|
77
81
|
,5,6
|
78
|
-
,7,8
|
82
|
+
,7,8
|
79
83
|
End
|
84
|
+
assert_match(/Header too short/, stderr)
|
80
85
|
end
|
81
86
|
|
82
87
|
def test_extend_both
|
@@ -88,12 +93,16 @@ class TestTbCmdCat < Test::Unit::TestCase
|
|
88
93
|
b
|
89
94
|
2,y
|
90
95
|
End
|
91
|
-
|
96
|
+
o = "o.csv"
|
97
|
+
stderr = capture_stderr {
|
98
|
+
Tb::Cmd.main_cat(['-o', o, i1, i2])
|
99
|
+
}
|
92
100
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
93
101
|
a,b
|
94
|
-
1
|
95
|
-
,2
|
102
|
+
1
|
103
|
+
,2
|
96
104
|
End
|
105
|
+
assert_match(/Header too short/, stderr)
|
97
106
|
end
|
98
107
|
|
99
108
|
def test_field_order
|
@@ -177,6 +186,19 @@ class TestTbCmdCat < Test::Unit::TestCase
|
|
177
186
|
End
|
178
187
|
end
|
179
188
|
|
189
|
+
def test_ltsv_output
|
190
|
+
File.open(i1="i1.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
191
|
+
a,b,c
|
192
|
+
1,2,3
|
193
|
+
4,5,6
|
194
|
+
End
|
195
|
+
Tb::Cmd.main_cat(['-o', o="o.ltsv", i1])
|
196
|
+
assert_equal(<<-"End".gsub(/^ */, '').gsub(/ /, "\t"), File.read(o))
|
197
|
+
a:1 b:2 c:3
|
198
|
+
a:4 b:5 c:6
|
199
|
+
End
|
200
|
+
end
|
201
|
+
|
180
202
|
def test_invalid_output_format
|
181
203
|
File.open(i1="i1.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
182
204
|
a,b,c
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'tb/cmdtop'
|
3
3
|
require 'tmpdir'
|
4
|
+
require_relative 'util_tbtest'
|
4
5
|
|
5
6
|
class TestTbCmdConsecutive < Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -52,12 +53,16 @@ class TestTbCmdConsecutive < Test::Unit::TestCase
|
|
52
53
|
4,5,6
|
53
54
|
7,8,9
|
54
55
|
End
|
55
|
-
|
56
|
+
o = "o.csv"
|
57
|
+
stderr = capture_stderr {
|
58
|
+
Tb::Cmd.main_consecutive(['-o', o, i])
|
59
|
+
}
|
56
60
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
57
61
|
a_1,a_2,b_1,b_2
|
58
|
-
1,4,2,5
|
59
|
-
4,7,5,8
|
62
|
+
1,4,2,5
|
63
|
+
4,7,5,8
|
60
64
|
End
|
65
|
+
assert_match(/Header too short/, stderr)
|
61
66
|
end
|
62
67
|
|
63
68
|
def test_n3
|
data/test/test_cmd_cut.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'tb/cmdtop'
|
3
3
|
require 'tmpdir'
|
4
|
+
require_relative 'util_tbtest'
|
4
5
|
|
5
6
|
class TestTbCmdCut < Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -61,19 +62,28 @@ class TestTbCmdCut < Test::Unit::TestCase
|
|
61
62
|
a,b
|
62
63
|
0,1,2,3
|
63
64
|
End
|
64
|
-
|
65
|
+
o = "o.csv"
|
66
|
+
stderr = capture_stderr {
|
67
|
+
Tb::Cmd.main_cut(['-o', o, 'a,2,1', i])
|
68
|
+
}
|
65
69
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
66
70
|
a,2,1
|
67
|
-
0
|
71
|
+
0
|
68
72
|
End
|
73
|
+
assert_match(/Header too short/, stderr)
|
69
74
|
end
|
70
75
|
|
71
|
-
def
|
76
|
+
def test_zero
|
72
77
|
File.open(i="i.csv", "w") {|f| f << <<-"End".gsub(/^[ \t]+/, '') }
|
73
78
|
a,b
|
74
79
|
0,1,2,3
|
75
80
|
End
|
76
|
-
|
81
|
+
o = "o.csv"
|
82
|
+
stderr = capture_stderr {
|
83
|
+
Tb::Cmd.main_cut(['-o', o, '0', i])
|
84
|
+
}
|
85
|
+
assert_equal("0\n\n", File.read(o))
|
86
|
+
assert_match(/Header too short/, stderr)
|
77
87
|
end
|
78
88
|
|
79
89
|
def test_twofile
|
data/test/test_cmd_git_log.rb
CHANGED
@@ -31,10 +31,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
31
31
|
system("git add foo")
|
32
32
|
system("git commit -q -m msg foo")
|
33
33
|
Tb::Cmd.main_git(['-o', o="o.csv"])
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
assert_match(/,A,foo\n/,
|
34
|
+
aa = CSV.read(o)
|
35
|
+
assert_equal(2, aa.length)
|
36
|
+
header, row = aa
|
37
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_escaped_filename
|
@@ -44,13 +44,14 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
44
44
|
system("git", "add", filename)
|
45
45
|
system("git", "commit", "-q", "-m", "msg", filename)
|
46
46
|
Tb::Cmd.main_git(['-o', o="o.csv"])
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assert_match(/,A,/,
|
51
|
-
|
52
|
-
assert_equal(
|
53
|
-
|
47
|
+
aa = CSV.read(o)
|
48
|
+
assert_equal(2, aa.length)
|
49
|
+
header, row = aa
|
50
|
+
assert_match(/,A,/, row[header.index "files"])
|
51
|
+
faa = CSV.parse(row[header.index "files"])
|
52
|
+
assert_equal(2, faa.length)
|
53
|
+
fheader, frow = faa
|
54
|
+
assert_equal(filename, frow[fheader.index "filename"])
|
54
55
|
end
|
55
56
|
|
56
57
|
def test_debug_git_output_input
|
@@ -59,18 +60,18 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
59
60
|
system("git add foo")
|
60
61
|
system("git commit -q -m msg foo")
|
61
62
|
Tb::Cmd.main_git(['-o', o="o.csv", '--debug-git-output', g='gitlog'])
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
assert_match(/,A,foo\n/,
|
63
|
+
aa = CSV.read(o)
|
64
|
+
assert_equal(2, aa.length)
|
65
|
+
header, row = aa
|
66
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
66
67
|
gresult = File.read(g)
|
67
68
|
assert(!gresult.empty?)
|
68
69
|
FileUtils.rmtree('.git')
|
69
70
|
Tb::Cmd.main_git(['-o', o="o.csv", '--debug-git-input', g])
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
assert_match(/,A,foo\n/,
|
71
|
+
aa = CSV.read(o)
|
72
|
+
assert_equal(2, aa.length)
|
73
|
+
header, row = aa
|
74
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
74
75
|
end
|
75
76
|
|
76
77
|
def test_warn1
|
@@ -79,10 +80,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
79
80
|
system("git add foo")
|
80
81
|
system("git commit -q -m msg foo")
|
81
82
|
Tb::Cmd.main_git(['-o', o="o.csv", '--debug-git-output', g='gitlog'])
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
assert_match(/,A,foo\n/,
|
83
|
+
aa = CSV.read(o)
|
84
|
+
assert_equal(2, aa.length)
|
85
|
+
header, row = aa
|
86
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
86
87
|
gresult = File.binread(g)
|
87
88
|
FileUtils.rmtree('.git')
|
88
89
|
###
|
@@ -94,10 +95,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
94
95
|
Tb::Cmd.main_git(['-o', o2, '--debug-git-input', g])
|
95
96
|
}
|
96
97
|
}
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
assert_not_match(/,A,foo\n/,
|
98
|
+
aa = CSV.read(o2)
|
99
|
+
assert_equal(2, aa.length)
|
100
|
+
header, row = aa
|
101
|
+
assert_not_match(/,A,foo\n/, row[header.index "files"])
|
101
102
|
log = File.read('log')
|
102
103
|
assert(!log.empty?)
|
103
104
|
end
|
@@ -108,10 +109,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
108
109
|
system("git add foo")
|
109
110
|
system("git commit -q -m msg foo")
|
110
111
|
Tb::Cmd.main_git(['-o', o="o.csv", '--debug-git-output', g='gitlog'])
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
assert_match(/,A,foo\n/,
|
112
|
+
aa = CSV.read(o)
|
113
|
+
assert_equal(2, aa.length)
|
114
|
+
header, row = aa
|
115
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
115
116
|
gresult = File.binread(g)
|
116
117
|
FileUtils.rmtree('.git')
|
117
118
|
###
|
@@ -123,10 +124,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
123
124
|
Tb::Cmd.main_git(['-o', o2, '--debug-git-input', g])
|
124
125
|
}
|
125
126
|
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
assert_match(/,A,foo\n/,
|
127
|
+
aa = CSV.read(o2)
|
128
|
+
assert_equal(2, aa.length)
|
129
|
+
header, row = aa
|
130
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
130
131
|
log = File.read('log')
|
131
132
|
assert(!log.empty?)
|
132
133
|
end
|
@@ -137,10 +138,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
137
138
|
system("git add foo")
|
138
139
|
system("git commit -q -m msg foo")
|
139
140
|
Tb::Cmd.main_git(['-o', o="o.csv", '--debug-git-output', g='gitlog'])
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
assert_match(/,A,foo\n/,
|
141
|
+
aa = CSV.read(o)
|
142
|
+
assert_equal(2, aa.length)
|
143
|
+
header, row = aa
|
144
|
+
assert_match(/,A,foo\n/, row[header.index "files"])
|
144
145
|
gresult = File.binread(g)
|
145
146
|
FileUtils.rmtree('.git')
|
146
147
|
###
|
@@ -152,9 +153,8 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
152
153
|
Tb::Cmd.main_git(['-o', o2, '--debug-git-input', g])
|
153
154
|
}
|
154
155
|
}
|
155
|
-
|
156
|
-
|
157
|
-
assert_equal(0, tb.size)
|
156
|
+
aa = CSV.read(o2)
|
157
|
+
assert_equal(1, aa.length)
|
158
158
|
log = File.read('log')
|
159
159
|
assert(!log.empty?)
|
160
160
|
end
|
@@ -165,10 +165,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
165
165
|
system("git add foo")
|
166
166
|
system("git commit -q -m msg foo")
|
167
167
|
Tb::Cmd.main_git(['-o', o="o.csv"])
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
assert_match(/,,,A,foo\n/,
|
168
|
+
aa = CSV.read(o)
|
169
|
+
assert_equal(2, aa.length)
|
170
|
+
header, row = aa
|
171
|
+
assert_match(/,,,A,foo\n/, row[header.index "files"])
|
172
172
|
end
|
173
173
|
|
174
174
|
def test_subdir
|
@@ -181,10 +181,10 @@ class TestTbCmdGitLog < Test::Unit::TestCase
|
|
181
181
|
system("git add bar")
|
182
182
|
system("git commit -q -m msg bar")
|
183
183
|
Tb::Cmd.main_git(['-o', o="o.csv", "bar"])
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
assert_not_match(/foo\n/,
|
184
|
+
aa = CSV.read(o)
|
185
|
+
assert_equal(2, aa.length)
|
186
|
+
header, row = aa
|
187
|
+
assert_not_match(/foo\n/, row[header.index "files"])
|
188
188
|
end
|
189
189
|
|
190
190
|
end
|
data/test/test_cmd_grep.rb
CHANGED
@@ -2,7 +2,7 @@ require 'test/unit'
|
|
2
2
|
require 'tb/cmdtop'
|
3
3
|
require 'tmpdir'
|
4
4
|
|
5
|
-
class
|
5
|
+
class TestTbCmdSearch < Test::Unit::TestCase
|
6
6
|
def setup
|
7
7
|
Tb::Cmd.reset_option
|
8
8
|
@curdir = Dir.pwd
|
@@ -23,7 +23,7 @@ class TestTbCmdGrep < Test::Unit::TestCase
|
|
23
23
|
8,9,a,b
|
24
24
|
c,d,e,f
|
25
25
|
End
|
26
|
-
Tb::Cmd.
|
26
|
+
Tb::Cmd.main_search(['-o', o="o.csv", '[6f]', i])
|
27
27
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
28
28
|
a,b,c,d
|
29
29
|
4,5,6,7
|
@@ -32,7 +32,7 @@ class TestTbCmdGrep < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_no_regexp
|
35
|
-
exc = assert_raise(SystemExit) { Tb::Cmd.
|
35
|
+
exc = assert_raise(SystemExit) { Tb::Cmd.main_search([]) }
|
36
36
|
assert(!exc.success?)
|
37
37
|
end
|
38
38
|
|
@@ -44,7 +44,7 @@ class TestTbCmdGrep < Test::Unit::TestCase
|
|
44
44
|
8,9,a,b
|
45
45
|
c,d,e,f
|
46
46
|
End
|
47
|
-
Tb::Cmd.
|
47
|
+
Tb::Cmd.main_search(['-o', o="o.csv", '-e', '[6f]', i])
|
48
48
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
49
49
|
a,b,c,d
|
50
50
|
4,5,6,7
|
@@ -60,7 +60,7 @@ class TestTbCmdGrep < Test::Unit::TestCase
|
|
60
60
|
8,9,a,b
|
61
61
|
c,d,e,f
|
62
62
|
End
|
63
|
-
Tb::Cmd.
|
63
|
+
Tb::Cmd.main_search(['-o', o="o.csv", '--ruby', '_["b"] == "5"', i])
|
64
64
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
65
65
|
a,b,c,d
|
66
66
|
4,5,6,7
|
@@ -78,7 +78,7 @@ class TestTbCmdGrep < Test::Unit::TestCase
|
|
78
78
|
5,6
|
79
79
|
7,8
|
80
80
|
End
|
81
|
-
Tb::Cmd.
|
81
|
+
Tb::Cmd.main_search(['-o', o="o.csv", '[46]', i1, i2])
|
82
82
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
83
83
|
a,b
|
84
84
|
3,4
|
data/test/test_cmd_gsub.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'tb/cmdtop'
|
3
3
|
require 'tmpdir'
|
4
|
+
require_relative 'util_tbtest'
|
4
5
|
|
5
6
|
class TestTbCmdGsub < Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -72,11 +73,15 @@ class TestTbCmdGsub < Test::Unit::TestCase
|
|
72
73
|
a,b
|
73
74
|
foo,bar,baz
|
74
75
|
End
|
75
|
-
|
76
|
+
o = "o.csv"
|
77
|
+
stderr = capture_stderr {
|
78
|
+
Tb::Cmd.main_gsub(['-o', o, '-f', '1', 'baz', 'Y', i])
|
79
|
+
}
|
76
80
|
assert_equal(<<-"End".gsub(/^[ \t]+/, ''), File.read(o))
|
77
81
|
a,b
|
78
|
-
foo,bar
|
82
|
+
foo,bar
|
79
83
|
End
|
84
|
+
assert_match(/Header too short/, stderr)
|
80
85
|
end
|
81
86
|
|
82
87
|
def test_twofile
|
data/test/test_cmd_ls.rb
CHANGED
@@ -72,16 +72,17 @@ class TestTbCmdLs < Test::Unit::TestCase
|
|
72
72
|
File.open("a", "w") {}
|
73
73
|
File.chmod(0754, "a")
|
74
74
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-l', 'a'])
|
75
|
-
|
76
|
-
assert_equal(
|
77
|
-
|
78
|
-
|
79
|
-
assert_equal(
|
80
|
-
assert_equal("
|
81
|
-
|
82
|
-
assert_match(/\A\d
|
83
|
-
|
84
|
-
assert_equal(
|
75
|
+
aa = CSV.read(o)
|
76
|
+
assert_equal(2, aa.length)
|
77
|
+
header, row = aa
|
78
|
+
assert_equal(%w[filemode nlink user group size mtime filename symlink], header)
|
79
|
+
assert_equal(8, row.length)
|
80
|
+
assert_equal("-rwxr-xr--", row[header.index "filemode"])
|
81
|
+
assert_equal("1", row[header.index "nlink"])
|
82
|
+
assert_match(/\A\d+\z/, row[header.index "size"])
|
83
|
+
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/, row[header.index "mtime"])
|
84
|
+
assert_equal("a", row[header.index "filename"])
|
85
|
+
assert_equal(nil, row[header.index "symlink"])
|
85
86
|
end
|
86
87
|
|
87
88
|
def test_opt_l
|
@@ -89,56 +90,60 @@ class TestTbCmdLs < Test::Unit::TestCase
|
|
89
90
|
File.open("d/a", "w") {}
|
90
91
|
Dir.mkdir("d/d2")
|
91
92
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-l', 'd'])
|
92
|
-
|
93
|
-
assert_equal(
|
94
|
-
|
95
|
-
|
93
|
+
aa = CSV.read(o)
|
94
|
+
assert_equal(3, aa.length)
|
95
|
+
header, row1, row2 = aa
|
96
|
+
i = header.index("filename")
|
97
|
+
assert_equal("d/a", row1[i])
|
98
|
+
assert_equal("d/d2", row2[i])
|
96
99
|
end
|
97
100
|
|
98
101
|
def test_opt_ll_single
|
99
102
|
File.open("a", "w") {}
|
100
103
|
File.chmod(0754, "a")
|
101
104
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-ll', 'a'])
|
102
|
-
|
103
|
-
assert_equal(
|
104
|
-
|
105
|
-
|
106
|
-
assert_match(/\A0x[0-9a-f]+\z/,
|
107
|
-
assert_match(/\A\d+\z/,
|
108
|
-
assert_match(/\A0[0-7]+\z/,
|
109
|
-
assert_equal("-rwxr-xr--",
|
110
|
-
assert_equal("1",
|
111
|
-
assert_match(/\A\d+\z/,
|
112
|
-
assert_match(/\A\d+\z/,
|
113
|
-
assert_match(/\A0x[0-9a-f]+\z/,
|
114
|
-
assert_match(/\A\d+\z/,
|
115
|
-
assert_match(/\A\d+\z/,
|
116
|
-
assert_match(/\A\d+\z/,
|
117
|
-
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/,
|
118
|
-
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/,
|
119
|
-
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/,
|
120
|
-
assert_equal("a",
|
121
|
-
assert_equal(nil,
|
105
|
+
aa = CSV.read(o)
|
106
|
+
assert_equal(2, aa.length)
|
107
|
+
header, row = aa
|
108
|
+
assert_equal(%w[dev ino mode filemode nlink uid user gid group rdev size blksize blocks atime mtime ctime filename symlink], header)
|
109
|
+
assert_match(/\A0x[0-9a-f]+\z/, row[header.index "dev"])
|
110
|
+
assert_match(/\A\d+\z/, row[header.index "ino"])
|
111
|
+
assert_match(/\A0[0-7]+\z/, row[header.index "mode"])
|
112
|
+
assert_equal("-rwxr-xr--", row[header.index "filemode"])
|
113
|
+
assert_equal("1", row[header.index "nlink"])
|
114
|
+
assert_match(/\A\d+\z/, row[header.index "uid"])
|
115
|
+
assert_match(/\A\d+\z/, row[header.index "gid"])
|
116
|
+
assert_match(/\A0x[0-9a-f]+\z/, row[header.index "rdev"])
|
117
|
+
assert_match(/\A\d+\z/, row[header.index "size"])
|
118
|
+
assert_match(/\A\d+\z/, row[header.index "blksize"])
|
119
|
+
assert_match(/\A\d+\z/, row[header.index "blocks"])
|
120
|
+
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/, row[header.index "atime"])
|
121
|
+
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/, row[header.index "mtime"])
|
122
|
+
assert_match(/\A\d+-\d\d-\d\dT\d\d:\d\d:\d\d/, row[header.index "ctime"])
|
123
|
+
assert_equal("a", row[header.index "filename"])
|
124
|
+
assert_equal(nil, row[header.index "symlink"])
|
122
125
|
end
|
123
126
|
|
124
127
|
def test_opt_a
|
125
128
|
Dir.mkdir("d")
|
126
129
|
File.open("d/.foo", "w") {}
|
127
130
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-a', 'd'])
|
128
|
-
|
129
|
-
assert_equal(
|
130
|
-
|
131
|
-
assert_equal("
|
132
|
-
assert_equal("
|
131
|
+
aa = CSV.read(o)
|
132
|
+
assert_equal(4, aa.length)
|
133
|
+
header, row1, row2, row3 = aa
|
134
|
+
assert_equal("d", row1[header.index "filename"]) # d/.
|
135
|
+
assert_equal(".", row2[header.index "filename"]) # d/..
|
136
|
+
assert_equal("d/.foo", row3[header.index "filename"])
|
133
137
|
end
|
134
138
|
|
135
139
|
def test_opt_A
|
136
140
|
Dir.mkdir("d")
|
137
141
|
File.open("d/.foo", "w") {}
|
138
142
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-A', 'd'])
|
139
|
-
|
140
|
-
assert_equal(
|
141
|
-
|
143
|
+
aa = CSV.read(o)
|
144
|
+
assert_equal(2, aa.length)
|
145
|
+
header, row = aa
|
146
|
+
assert_equal("d/.foo", row[header.index "filename"])
|
142
147
|
end
|
143
148
|
|
144
149
|
def test_opt_R
|
@@ -148,12 +153,13 @@ class TestTbCmdLs < Test::Unit::TestCase
|
|
148
153
|
File.open("d/d2/b", "w") {}
|
149
154
|
File.open("d/d2/c", "w") {}
|
150
155
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-R', 'd'])
|
151
|
-
|
152
|
-
assert_equal(
|
153
|
-
|
154
|
-
assert_equal("d/
|
155
|
-
assert_equal("d/d2
|
156
|
-
assert_equal("d/d2/
|
156
|
+
aa = CSV.read(o)
|
157
|
+
assert_equal(5, aa.length)
|
158
|
+
header, row1, row2, row3, row4 = aa
|
159
|
+
assert_equal("d/a", row1[header.index "filename"])
|
160
|
+
assert_equal("d/d2", row2[header.index "filename"])
|
161
|
+
assert_equal("d/d2/b", row3[header.index "filename"])
|
162
|
+
assert_equal("d/d2/c", row4[header.index "filename"])
|
157
163
|
end
|
158
164
|
|
159
165
|
def test_opt_Ra
|
@@ -163,25 +169,27 @@ class TestTbCmdLs < Test::Unit::TestCase
|
|
163
169
|
File.open("d/d2/b", "w") {}
|
164
170
|
File.open("d/d2/c", "w") {}
|
165
171
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-Ra', 'd'])
|
166
|
-
|
167
|
-
assert_equal(
|
168
|
-
|
169
|
-
assert_equal("d
|
170
|
-
assert_equal("d
|
171
|
-
assert_equal("d/
|
172
|
-
assert_equal("d/d2
|
173
|
-
assert_equal("d/d2
|
174
|
-
assert_equal("d/d2
|
175
|
-
assert_equal("d/d2/
|
172
|
+
aa = CSV.read(o)
|
173
|
+
assert_equal(9, aa.length)
|
174
|
+
header, *rows = aa
|
175
|
+
assert_equal("d/.", rows[0][header.index "filename"])
|
176
|
+
assert_equal("d/..", rows[1][header.index "filename"])
|
177
|
+
assert_equal("d/a", rows[2][header.index "filename"])
|
178
|
+
assert_equal("d/d2", rows[3][header.index "filename"])
|
179
|
+
assert_equal("d/d2/.", rows[4][header.index "filename"])
|
180
|
+
assert_equal("d/d2/..", rows[5][header.index "filename"])
|
181
|
+
assert_equal("d/d2/b", rows[6][header.index "filename"])
|
182
|
+
assert_equal("d/d2/c", rows[7][header.index "filename"])
|
176
183
|
end
|
177
184
|
|
178
185
|
def test_symlink
|
179
186
|
File.symlink("a", "b")
|
180
187
|
Tb::Cmd.main_ls(['-o', o="o.csv", '-l', 'b'])
|
181
|
-
|
182
|
-
assert_equal(
|
183
|
-
|
184
|
-
assert_equal("
|
188
|
+
aa = CSV.read(o)
|
189
|
+
assert_equal(2, aa.length)
|
190
|
+
header, row = aa
|
191
|
+
assert_equal("b", row[header.index "filename"])
|
192
|
+
assert_equal("a", row[header.index "symlink"])
|
185
193
|
end
|
186
194
|
|
187
195
|
def test_not_found
|