workbook 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +21 -0
- data/.gitignore +4 -1
- data/.ruby-version +1 -1
- data/.travis.yml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/README.md +9 -7
- data/Rakefile +6 -6
- data/lib/workbook/book.rb +73 -62
- data/lib/workbook/cell.rb +58 -13
- data/lib/workbook/column.rb +31 -28
- data/lib/workbook/format.rb +23 -24
- data/lib/workbook/generatetypes.rb +4 -4
- data/lib/workbook/modules/cache.rb +6 -7
- data/lib/workbook/modules/cell.rb +77 -100
- data/lib/workbook/modules/diff_sort.rb +92 -83
- data/lib/workbook/modules/raw_objects_storage.rb +6 -8
- data/lib/workbook/modules/type_parser.rb +30 -22
- data/lib/workbook/nil_value.rb +4 -9
- data/lib/workbook/readers/csv_reader.rb +7 -10
- data/lib/workbook/readers/ods_reader.rb +48 -50
- data/lib/workbook/readers/txt_reader.rb +6 -8
- data/lib/workbook/readers/xls_reader.rb +21 -33
- data/lib/workbook/readers/xls_shared.rb +106 -117
- data/lib/workbook/readers/xlsx_reader.rb +45 -46
- data/lib/workbook/row.rb +99 -84
- data/lib/workbook/sheet.rb +47 -38
- data/lib/workbook/table.rb +96 -72
- data/lib/workbook/template.rb +12 -15
- data/lib/workbook/types/false.rb +0 -1
- data/lib/workbook/types/nil.rb +0 -1
- data/lib/workbook/types/nil_class.rb +1 -1
- data/lib/workbook/types/numeric.rb +1 -1
- data/lib/workbook/types/string.rb +1 -1
- data/lib/workbook/types/time.rb +1 -1
- data/lib/workbook/types/true.rb +0 -1
- data/lib/workbook/types/true_class.rb +1 -1
- data/lib/workbook/version.rb +2 -3
- data/lib/workbook/writers/csv_table_writer.rb +10 -13
- data/lib/workbook/writers/html_writer.rb +34 -38
- data/lib/workbook/writers/json_table_writer.rb +8 -11
- data/lib/workbook/writers/xls_writer.rb +30 -36
- data/lib/workbook/writers/xlsx_writer.rb +45 -29
- data/lib/workbook.rb +16 -15
- data/test/helper.rb +6 -5
- data/test/test_book.rb +41 -38
- data/test/test_column.rb +26 -24
- data/test/test_format.rb +51 -55
- data/test/test_functional.rb +7 -8
- data/test/test_modules_cache.rb +18 -17
- data/test/test_modules_cell.rb +47 -46
- data/test/test_modules_table_diff_sort.rb +55 -64
- data/test/test_modules_type_parser.rb +61 -31
- data/test/test_readers_csv_reader.rb +48 -42
- data/test/test_readers_ods_reader.rb +28 -31
- data/test/test_readers_txt_reader.rb +21 -23
- data/test/test_readers_xls_reader.rb +20 -23
- data/test/test_readers_xls_shared.rb +2 -3
- data/test/test_readers_xlsx_reader.rb +44 -37
- data/test/test_row.rb +105 -109
- data/test/test_sheet.rb +41 -35
- data/test/test_table.rb +82 -60
- data/test/test_template.rb +16 -15
- data/test/test_types_date.rb +4 -6
- data/test/test_writers_csv_writer.rb +24 -0
- data/test/test_writers_html_writer.rb +42 -41
- data/test/test_writers_json_writer.rb +9 -9
- data/test/test_writers_xls_writer.rb +50 -35
- data/test/test_writers_xlsx_writer.rb +62 -34
- data/workbook.gemspec +26 -27
- metadata +92 -27
data/test/test_modules_cell.rb
CHANGED
@@ -1,83 +1,85 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), 'helper')
|
3
|
+
require File.join(File.dirname(__FILE__), "helper")
|
5
4
|
|
6
5
|
class TestModulesCell < Minitest::Test
|
7
|
-
|
8
|
-
|
9
6
|
def test_init
|
10
7
|
w = Workbook::Cell.new nil
|
11
8
|
assert_nil(w.value)
|
12
9
|
w = Workbook::Cell.new "asdf"
|
13
|
-
assert_equal("asdf",w.value)
|
10
|
+
assert_equal("asdf", w.value)
|
14
11
|
|
15
12
|
assert_raises(ArgumentError) { w = Workbook::Cell.new Workbook::Row }
|
16
13
|
|
17
14
|
t = Time.now
|
18
15
|
w = Workbook::Cell.new t
|
19
|
-
assert_equal(t,w.value)
|
20
|
-
|
16
|
+
assert_equal(t, w.value)
|
21
17
|
end
|
22
18
|
|
23
19
|
def test_value
|
24
20
|
w = Workbook::Cell.new nil
|
25
21
|
assert_nil(w.value)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
w.value
|
34
|
-
|
35
|
-
assert_equal(
|
22
|
+
|
23
|
+
{"asdf" => :string, Date.new => :date, 1 => :integer, 1.0 => :float, BigDecimal("1.0") => :decimal}.each do |value, value_type|
|
24
|
+
w.value = value
|
25
|
+
assert_equal(value, w.value)
|
26
|
+
assert_equal(value_type, w.cell_type)
|
27
|
+
end
|
28
|
+
# w.value = "asdf"
|
29
|
+
# assert_equal("asdf", w.value)
|
30
|
+
# w.value = Date.new
|
31
|
+
# assert_equal(Date.new, w.value)
|
32
|
+
# w.value = 1
|
33
|
+
# assert_equal(1, w.value)
|
34
|
+
# assert(["Integer", "Integer"].include?(w.value.class.to_s))
|
35
|
+
# w.value = 1.0
|
36
|
+
# assert_equal(1.0, w.value)
|
37
|
+
# assert_equal(Float, w.value.class)
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_importance_of_class
|
39
41
|
a = Workbook::Cell.new
|
40
|
-
assert_equal(
|
41
|
-
assert_equal(
|
42
|
+
assert_equal(5, a.importance_of_class("a"))
|
43
|
+
assert_equal(6, a.importance_of_class(:a))
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_comp
|
45
47
|
a = Workbook::Cell.new 1
|
46
48
|
b = Workbook::Cell.new 2
|
47
|
-
assert_equal(-1, a<=>b)
|
49
|
+
assert_equal(-1, a <=> b)
|
48
50
|
a = Workbook::Cell.new "c"
|
49
51
|
b = Workbook::Cell.new "bsdf"
|
50
|
-
assert_equal(1, a<=>b)
|
52
|
+
assert_equal(1, a <=> b)
|
51
53
|
a = Workbook::Cell.new "c"
|
52
54
|
b = Workbook::Cell.new "c"
|
53
|
-
assert_equal(0, a<=>b)
|
55
|
+
assert_equal(0, a <=> b)
|
54
56
|
a = Workbook::Cell.new true
|
55
57
|
b = Workbook::Cell.new false
|
56
|
-
assert_equal(-1, a<=>b)
|
58
|
+
assert_equal(-1, a <=> b)
|
57
59
|
a = Workbook::Cell.new "true"
|
58
60
|
b = Workbook::Cell.new "false"
|
59
|
-
assert_equal(1, a<=>b)
|
61
|
+
assert_equal(1, a <=> b)
|
60
62
|
a = Workbook::Cell.new 1
|
61
63
|
b = Workbook::Cell.new "a"
|
62
|
-
assert_equal(-1, a<=>b)
|
64
|
+
assert_equal(-1, a <=> b)
|
63
65
|
a = Workbook::Cell.new nil
|
64
66
|
b = Workbook::Cell.new "a"
|
65
|
-
assert_equal(1, a<=>b)
|
67
|
+
assert_equal(1, a <=> b)
|
66
68
|
a = Workbook::Cell.new nil
|
67
69
|
b = Workbook::Cell.new nil
|
68
|
-
assert_equal(0, a<=>b)
|
70
|
+
assert_equal(0, a <=> b)
|
69
71
|
end
|
70
72
|
|
71
73
|
def test_cloning_as_expected?
|
72
74
|
a = Workbook::Cell.new 1
|
73
|
-
a.format = Workbook::Format.new({:
|
75
|
+
a.format = Workbook::Format.new({value: 1})
|
74
76
|
b = a.clone
|
75
77
|
b.value = 2
|
76
|
-
b.format[:value]=2
|
77
|
-
assert_equal(1,a.value)
|
78
|
-
assert_equal(2,b.value)
|
79
|
-
assert_equal(2,a.format[:value])
|
80
|
-
assert_equal(2,b.format[:value])
|
78
|
+
b.format[:value] = 2
|
79
|
+
assert_equal(1, a.value)
|
80
|
+
assert_equal(2, b.value)
|
81
|
+
assert_equal(2, a.format[:value])
|
82
|
+
assert_equal(2, b.format[:value])
|
81
83
|
end
|
82
84
|
|
83
85
|
def test_to_sym
|
@@ -91,15 +93,14 @@ class TestModulesCell < Minitest::Test
|
|
91
93
|
"éåšžÌ?" => :easzi?,
|
92
94
|
1 => :num1,
|
93
95
|
1.0 => :num1_0,
|
94
|
-
|
95
|
-
|
96
|
+
"test " => :test,
|
97
|
+
"test " => :test
|
96
98
|
|
97
99
|
}
|
98
|
-
examples.each do |k,v|
|
100
|
+
examples.each do |k, v|
|
101
|
+
assert_equal(v, Workbook::Cell::value_to_sym(k))
|
99
102
|
assert_equal(v, Workbook::Cell.new(k).to_sym)
|
100
103
|
end
|
101
|
-
|
102
|
-
|
103
104
|
end
|
104
105
|
|
105
106
|
def test_nil
|
@@ -119,32 +120,32 @@ class TestModulesCell < Minitest::Test
|
|
119
120
|
assert_nil(c.rowspan)
|
120
121
|
c.colspan = 3
|
121
122
|
c.rowspan = "4"
|
122
|
-
assert_equal(3,c.colspan)
|
123
|
+
assert_equal(3, c.colspan)
|
123
124
|
c.rowspan = 0
|
124
125
|
assert_nil(c.rowspan)
|
125
|
-
assert_equal(3,c.colspan)
|
126
|
+
assert_equal(3, c.colspan)
|
126
127
|
c.colspan = 0
|
127
128
|
c.rowspan = 3
|
128
|
-
assert_equal(3,c.rowspan)
|
129
|
+
assert_equal(3, c.rowspan)
|
129
130
|
assert_nil(c.colspan)
|
130
131
|
end
|
131
132
|
|
132
133
|
def test_cell_type
|
133
|
-
{1 => :integer, 3.2 => :float, true => :boolean, "asdf" => :string}.each do |k,v|
|
134
|
+
{1 => :integer, 3.2 => :float, true => :boolean, "asdf" => :string}.each do |k, v|
|
134
135
|
c = Workbook::Cell.new(k)
|
135
|
-
assert_equal(v,c.cell_type)
|
136
|
+
assert_equal(v, c.cell_type)
|
136
137
|
end
|
137
138
|
end
|
138
139
|
|
139
140
|
def test_index
|
140
|
-
t = Workbook::Table.new [[:a
|
141
|
+
t = Workbook::Table.new [[:a, :b, :c], [1, 2, 3], [4, 5, 6]]
|
141
142
|
assert_equal(2, t[2][2].index)
|
142
143
|
end
|
143
144
|
|
144
145
|
def test_key
|
145
|
-
t = Workbook::Table.new [[:a
|
146
|
+
t = Workbook::Table.new [[:a, :b, :c], [1, 2, 3], [4, 5, 6]]
|
146
147
|
assert_equal(:c, t[2][2].key)
|
147
|
-
t = Workbook::Table.new [[:d,nil,nil],[:a
|
148
|
+
t = Workbook::Table.new [[:d, nil, nil], [:a, :b, :c], [1, 2, 3], [4, 5, 6]]
|
148
149
|
assert_nil(t[2][2].key)
|
149
150
|
assert_equal(:d, t[2][0].key)
|
150
151
|
t.header = t[1]
|
@@ -1,85 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), 'helper')
|
3
|
+
require File.join(File.dirname(__FILE__), "helper")
|
5
4
|
module Modules
|
6
5
|
class TestTableDiffSort < Minitest::Test
|
7
6
|
def test_sort
|
8
7
|
time = Time.now
|
9
|
-
b = Workbook::Book.new [[1,2,3],[2,2,3],[true,false,true],["asdf","sdf","as"],[time,2,3],[2,2,2],[22,2,3],[1,2,233]]
|
8
|
+
b = Workbook::Book.new [[1, 2, 3], [2, 2, 3], [true, false, true], ["asdf", "sdf", "as"], [time, 2, 3], [2, 2, 2], [22, 2, 3], [1, 2, 233]]
|
10
9
|
t = b.sheet.table
|
11
10
|
assert_equal(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
ba = Workbook::Book.new [[
|
11
|
+
[[Workbook::Cell.new(1), Workbook::Cell.new(2), Workbook::Cell.new(3)],
|
12
|
+
[Workbook::Cell.new(1), Workbook::Cell.new(2), Workbook::Cell.new(233)],
|
13
|
+
[Workbook::Cell.new(2), Workbook::Cell.new(2), Workbook::Cell.new(2)],
|
14
|
+
[Workbook::Cell.new(2), Workbook::Cell.new(2), Workbook::Cell.new(3)],
|
15
|
+
[Workbook::Cell.new(22), Workbook::Cell.new(2), Workbook::Cell.new(3)],
|
16
|
+
[Workbook::Cell.new("asdf"), Workbook::Cell.new("sdf"), Workbook::Cell.new("as")],
|
17
|
+
[Workbook::Cell.new(time), Workbook::Cell.new(2), Workbook::Cell.new(3)],
|
18
|
+
[Workbook::Cell.new(true), Workbook::Cell.new(false), Workbook::Cell.new(true)]],
|
19
|
+
t.sort.rows.map(&:cells)
|
20
|
+
)
|
21
|
+
|
22
|
+
ba = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [4, 2, 3, 4], [3, 2, 3, 4]]
|
24
23
|
sba = ba.sheet.table.sort
|
25
|
-
refute_equal(Workbook::Table.new([[
|
26
|
-
assert_equal(Workbook::Table.new([[
|
27
|
-
|
24
|
+
refute_equal(Workbook::Table.new([["a", "b", "c", "d"], [1, 2, 3, 4], [4, 2, 3, 4], [3, 2, 3, 4]]), sba)
|
25
|
+
assert_equal(Workbook::Table.new([["a", "b", "c", "d"], [1, 2, 3, 4], [3, 2, 3, 4], [4, 2, 3, 4]]), sba)
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_align
|
31
|
-
ba = Workbook::Book.new [[
|
32
|
-
bb = Workbook::Book.new [[
|
33
|
-
tself = ba.sheet.table
|
34
|
-
tother = bb.sheet.table
|
35
|
-
|
36
|
-
ba = Workbook::Book.new [['a','b','c','d'],[1,2,3,4],[4,2,3,4],[3,2,3,4]]
|
37
|
-
bb = Workbook::Book.new [['a','b','c','d'],[1,2,3,4],[3,2,3,4],[5,2,3,4]]
|
29
|
+
ba = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [4, 2, 3, 4], [3, 2, 3, 4]]
|
30
|
+
bb = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4]]
|
38
31
|
tself = ba.sheet.table
|
39
32
|
tother = bb.sheet.table
|
40
33
|
align_result = tself.align tother
|
41
|
-
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n\n5,2,3,4\n",align_result[:other].to_csv)
|
42
|
-
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n4,2,3,4\n\n",align_result[:self].to_csv)
|
34
|
+
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n\n5,2,3,4\n", align_result[:other].to_csv)
|
35
|
+
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n4,2,3,4\n\n", align_result[:self].to_csv)
|
43
36
|
|
44
|
-
ba = Workbook::Book.new [[
|
45
|
-
bb = Workbook::Book.new [[
|
37
|
+
ba = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4]]
|
38
|
+
bb = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [2, 2, 3, 4], [5, 2, 3, 4]]
|
46
39
|
tself = ba.sheet.table
|
47
40
|
tother = bb.sheet.table
|
48
41
|
align_result = tself.align tother
|
49
|
-
assert_equal("a,b,c,d\n1,2,3,4\n\n3,2,3,4\n5,2,3,4\n",align_result[:self].to_csv)
|
50
|
-
assert_equal("a,b,c,d\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n",align_result[:other].to_csv)
|
42
|
+
assert_equal("a,b,c,d\n1,2,3,4\n\n3,2,3,4\n5,2,3,4\n", align_result[:self].to_csv)
|
43
|
+
assert_equal("a,b,c,d\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n", align_result[:other].to_csv)
|
51
44
|
align_result = tother.align tself
|
52
|
-
assert_equal("a,b,c,d\n1,2,3,4\n\n3,2,3,4\n5,2,3,4\n",align_result[:other].to_csv)
|
53
|
-
assert_equal("a,b,c,d\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n",align_result[:self].to_csv)
|
45
|
+
assert_equal("a,b,c,d\n1,2,3,4\n\n3,2,3,4\n5,2,3,4\n", align_result[:other].to_csv)
|
46
|
+
assert_equal("a,b,c,d\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n", align_result[:self].to_csv)
|
54
47
|
|
55
|
-
tself =
|
56
|
-
tother = Workbook::Book.new([[
|
48
|
+
tself = Workbook::Book.new([["a", "b", "c", "d"], [1, 2, 3, 4], [1, 3, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
49
|
+
tother = Workbook::Book.new([["a", "b", "c", "d"], [1, 2, 3, 4], [2, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
57
50
|
align_result = tself.align tother
|
58
|
-
assert_equal("a,b,c,d\n1,2,3,4\n1,3,3,4\n\n3,2,3,4\n5,2,3,4\n",align_result[:self].to_csv)
|
59
|
-
assert_equal("a,b,c,d\n1,2,3,4\n\n2,2,3,4\n\n5,2,3,4\n",align_result[:other].to_csv)
|
60
|
-
tself = Workbook::Book.new(
|
61
|
-
tother = Workbook::Book.new([[
|
51
|
+
assert_equal("a,b,c,d\n1,2,3,4\n1,3,3,4\n\n3,2,3,4\n5,2,3,4\n", align_result[:self].to_csv)
|
52
|
+
assert_equal("a,b,c,d\n1,2,3,4\n\n2,2,3,4\n\n5,2,3,4\n", align_result[:other].to_csv)
|
53
|
+
tself = Workbook::Book.new([["a", "b", "c", "d"], [1, 2, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
54
|
+
tother = Workbook::Book.new([["a", "b", "c", "d"], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [2, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
62
55
|
align_result = tself.align tother
|
63
|
-
assert_equal("a,b,c,d\n1,2,3,4\n\n\n\n3,2,3,4\n5,2,3,4\n",align_result[:self].to_csv)
|
64
|
-
assert_equal("a,b,c,d\n1,2,3,4\n1,2,3,4\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n",align_result[:other].to_csv)
|
65
|
-
tself = Workbook::Book.new([[
|
66
|
-
tother = Workbook::Book.new([[
|
56
|
+
assert_equal("a,b,c,d\n1,2,3,4\n\n\n\n3,2,3,4\n5,2,3,4\n", align_result[:self].to_csv)
|
57
|
+
assert_equal("a,b,c,d\n1,2,3,4\n1,2,3,4\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n", align_result[:other].to_csv)
|
58
|
+
tself = Workbook::Book.new([["a", "b", "c", "d"], [9, 2, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
59
|
+
tother = Workbook::Book.new([["a", "b", "c", "d"], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [2, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
67
60
|
align_result = tself.align tother
|
68
|
-
assert_equal("a,b,c,d\n\n\n\n\n3,2,3,4\n5,2,3,4\n9,2,3,4\n",align_result[:self].to_csv)
|
69
|
-
assert_equal("a,b,c,d\n1,2,3,4\n1,2,3,4\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n\n",align_result[:other].to_csv)
|
70
|
-
tself = Workbook::Book.new([[
|
71
|
-
tother = Workbook::Book.new([[
|
61
|
+
assert_equal("a,b,c,d\n\n\n\n\n3,2,3,4\n5,2,3,4\n9,2,3,4\n", align_result[:self].to_csv)
|
62
|
+
assert_equal("a,b,c,d\n1,2,3,4\n1,2,3,4\n1,2,3,4\n2,2,3,4\n\n5,2,3,4\n\n", align_result[:other].to_csv)
|
63
|
+
tself = Workbook::Book.new([["a", "b", "c", "d"], [49, 2, 3, 4], [10, 2, 3, 4], [45, 2, 3, 4]]).sheet.table
|
64
|
+
tother = Workbook::Book.new([["a", "b", "c", "d"], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [2, 2, 3, 4], [5, 2, 3, 4]]).sheet.table
|
72
65
|
align_result = tself.align tother
|
73
|
-
assert_equal("a,b,c,d\n\n\n\n\n\n10,2,3,4\n45,2,3,4\n49,2,3,4\n",align_result[:self].to_csv)
|
74
|
-
assert_equal("a,b,c,d\n1,2,3,4\n1,2,3,4\n1,2,3,4\n2,2,3,4\n5,2,3,4\n\n\n\n",align_result[:other].to_csv)
|
75
|
-
|
66
|
+
assert_equal("a,b,c,d\n\n\n\n\n\n10,2,3,4\n45,2,3,4\n49,2,3,4\n", align_result[:self].to_csv)
|
67
|
+
assert_equal("a,b,c,d\n1,2,3,4\n1,2,3,4\n1,2,3,4\n2,2,3,4\n5,2,3,4\n\n\n\n", align_result[:other].to_csv)
|
76
68
|
end
|
77
69
|
|
78
70
|
def test_with_nil_header
|
79
|
-
a = Workbook::Book.new([[
|
80
|
-
b = Workbook::Book.new([[
|
71
|
+
a = Workbook::Book.new([["a", "b", nil], [1, 2, 3]])
|
72
|
+
b = Workbook::Book.new([["a", "b", "c"], [1, 2, 3]])
|
81
73
|
c = a.sheet.table.diff b.sheet.table
|
82
|
-
assert_equal("a,b,(was: c)\n1,2,(was: 3)\n",c.to_csv)
|
74
|
+
assert_equal("a,b,(was: c)\n1,2,(was: 3)\n", c.to_csv)
|
83
75
|
end
|
84
76
|
|
85
77
|
# def test_diff_file
|
@@ -94,8 +86,8 @@ module Modules
|
|
94
86
|
# end
|
95
87
|
|
96
88
|
def test_diff
|
97
|
-
ba = Workbook::Book.new [[
|
98
|
-
bb = Workbook::Book.new [[
|
89
|
+
ba = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [4, 2, 3, 4], [3, 2, 3, 4], [3, 3, 3, 4]]
|
90
|
+
bb = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4], [3, 2, 3, 4]]
|
99
91
|
# Start:
|
100
92
|
# ba = [['a','b','c','d'],[1,2,3,4],[4,2,3,4],[3,2,3,4],[3,3,3,4]]
|
101
93
|
# bb = [['a','b','c','d'],[1,2,3,4],[3,2,3,4],[5,2,3,4],[3,2,3,4]]
|
@@ -110,21 +102,20 @@ module Modules
|
|
110
102
|
tself = ba.sheet.table
|
111
103
|
tother = bb.sheet.table
|
112
104
|
diff_result = tself.diff tother
|
113
|
-
assert_equal(
|
114
|
-
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n3,3 (was: 2),3,4\n4,2,3,4\n(was: 5),(was: 2),(was: 3),(was: 4)\n",diff_result.to_csv)
|
105
|
+
assert_equal("a", diff_result.sheet.table.header[0].value)
|
106
|
+
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n3,3 (was: 2),3,4\n4,2,3,4\n(was: 5),(was: 2),(was: 3),(was: 4)\n", diff_result.to_csv)
|
115
107
|
diff_result.sheet.book.write_to_xls
|
116
108
|
end
|
117
109
|
|
118
110
|
def test_workbook_diff
|
119
|
-
ba = Workbook::Book.new [[
|
120
|
-
bb = Workbook::Book.new [[
|
121
|
-
ba << [[
|
122
|
-
bb << [[
|
111
|
+
ba = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [4, 2, 3, 4], [3, 2, 3, 4], [3, 3, 3, 4]]
|
112
|
+
bb = Workbook::Book.new [["a", "b", "c", "d"], [1, 2, 3, 4], [3, 2, 3, 4], [5, 2, 3, 4], [3, 2, 3, 4]]
|
113
|
+
ba << [["e", "f", "g", "h"], [1, 2, 3, 4], [4, 2, 3, 4], [3, 2, 3, 4], [3, 3, 3, 4]]
|
114
|
+
bb << [["e", "f", "g", "h"], [1, 2, 2, 2], [4, 2, 3, 4], [3, 2, 3, 4], [3, 3, 3, 6]]
|
123
115
|
diff_result = ba.diff bb
|
124
116
|
|
125
|
-
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n3,3 (was: 2),3,4\n4,2,3,4\n(was: 5),(was: 2),(was: 3),(was: 4)\n",diff_result[0][0].to_csv)
|
126
|
-
assert_equal("e,f,g,h\n1,2,3 (was: 2),4 (was: 2)\n3,2,3,4\n3,3,3,4 (was: 6)\n4,2,3,4\n",diff_result[1][0].to_csv)
|
127
|
-
|
117
|
+
assert_equal("a,b,c,d\n1,2,3,4\n3,2,3,4\n3,3 (was: 2),3,4\n4,2,3,4\n(was: 5),(was: 2),(was: 3),(was: 4)\n", diff_result[0][0].to_csv)
|
118
|
+
assert_equal("e,f,g,h\n1,2,3 (was: 2),4 (was: 2)\n3,2,3,4\n3,3,3,4 (was: 6)\n4,2,3,4\n", diff_result[1][0].to_csv)
|
128
119
|
end
|
129
120
|
end
|
130
121
|
end
|
@@ -1,68 +1,98 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), 'helper')
|
3
|
+
require File.join(File.dirname(__FILE__), "helper")
|
5
4
|
module Modules
|
6
5
|
class TestTypeParser < Minitest::Test
|
7
6
|
def examples
|
8
7
|
{
|
9
|
-
"2312"=>2312,
|
10
|
-
"12-12-2012"=>Date.new(2012,12,12),
|
11
|
-
"12-12-2012 12:24"=>DateTime.new(2012,12,12,12,24),
|
12
|
-
"2012-12-12 12:24"=>DateTime.new(2012,12,12,12,24),
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
8
|
+
"2312" => 2312,
|
9
|
+
"12-12-2012" => Date.new(2012, 12, 12),
|
10
|
+
"12-12-2012 12:24" => DateTime.new(2012, 12, 12, 12, 24),
|
11
|
+
"2012-12-12 12:24" => DateTime.new(2012, 12, 12, 12, 24),
|
12
|
+
"2012-12-12T12:24" => DateTime.new(2012, 12, 12, 12, 24),
|
13
|
+
"2011-05-19T15_37_49 - 52349.xml" => "2011-05-19T15_37_49 - 52349.xml",
|
14
|
+
"20-2-2012 20:52" => DateTime.new(2012, 2, 20, 20, 52),
|
15
|
+
"1-11-2011" => Date.new(2011, 11, 1),
|
16
|
+
"12/12/2012" => Date.new(2012, 12, 12),
|
17
17
|
# "12/23/1980"=>Date.new(1980,12,23), #TODO: should probably depend on locale, see: http://bugs.ruby-lang.org/issues/634#note-10
|
18
|
-
"jA"=>"jA",
|
19
|
-
"n"=>"n",
|
20
|
-
""=>nil,
|
21
|
-
" "=> nil,
|
22
|
-
"12 bomen"=>"12 bomen",
|
23
|
-
"12 bomenasdfasdfsadf"=>"12 bomenasdfasdfsadf",
|
24
|
-
"mailto:sadf@asdf.as"=>"sadf@asdf.as",
|
25
|
-
"012-3456789"=>"012-3456789",
|
26
|
-
"TRUE"=>true
|
18
|
+
"jA" => "jA",
|
19
|
+
"n" => "n",
|
20
|
+
"" => nil,
|
21
|
+
" " => nil,
|
22
|
+
"12 bomen" => "12 bomen",
|
23
|
+
"12 bomenasdfasdfsadf" => "12 bomenasdfasdfsadf",
|
24
|
+
"mailto:sadf@asdf.as" => "sadf@asdf.as",
|
25
|
+
"012-3456789" => "012-3456789",
|
26
|
+
"TRUE" => true
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_parse
|
31
|
-
examples.each do |k,v|
|
32
|
-
if v
|
33
|
-
assert_nil(Workbook::Cell.new(k).parse({:
|
31
|
+
examples.each do |k, v|
|
32
|
+
if v.nil?
|
33
|
+
assert_nil(Workbook::Cell.new(k).parse({detect_date: true}))
|
34
34
|
else
|
35
|
-
assert_equal(v, Workbook::Cell.new(k).parse({:
|
35
|
+
assert_equal(v, Workbook::Cell.new(k).parse({detect_date: true}))
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_custom_parse
|
41
|
-
customparsers = [proc{|v| "#{v}2" }]
|
42
|
-
examples.each do |k,v|
|
41
|
+
customparsers = [proc { |v| "#{v}2" }]
|
42
|
+
examples.each do |k, v|
|
43
43
|
c = Workbook::Cell.new(k)
|
44
44
|
c.string_parsers = customparsers
|
45
|
-
refute_equal(v,c.parse)
|
45
|
+
refute_equal(v, c.parse)
|
46
46
|
end
|
47
47
|
c = Workbook::Cell.new("233")
|
48
48
|
c.string_parsers = customparsers
|
49
|
-
assert_equal("2332",c.parse)
|
49
|
+
assert_equal("2332", c.parse)
|
50
50
|
c.value = "v"
|
51
|
-
assert_equal("v2",c.parse)
|
51
|
+
assert_equal("v2", c.parse)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_american_date_format
|
55
|
+
c = Workbook::Cell.new("01-11-2012")
|
56
|
+
c.string_parsers << :string_american_date_converter
|
57
|
+
assert_equal(Date.new(2012, 1, 11), c.parse)
|
58
|
+
c = Workbook::Cell.new("12-31-2012")
|
59
|
+
c.string_parsers << :string_american_date_converter
|
60
|
+
assert_equal(Date.new(2012, 12, 31), c.parse)
|
61
|
+
c = Workbook::Cell.new("12/31/2012")
|
62
|
+
c.string_parsers << :string_american_date_converter
|
63
|
+
assert_equal(Date.new(2012, 12, 31), c.parse)
|
64
|
+
c = Workbook::Cell.new("12/1/2012")
|
65
|
+
c.string_parsers << :string_american_date_converter
|
66
|
+
assert_equal(Date.new(2012, 12, 1), c.parse)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_non_american_date_format
|
70
|
+
c = Workbook::Cell.new("01-11-2012")
|
71
|
+
c.string_parsers << :string_non_american_date_converter
|
72
|
+
assert_equal(Date.new(2012, 11, 1), c.parse)
|
73
|
+
c = Workbook::Cell.new("31/12/2012")
|
74
|
+
c.string_parsers << :string_non_american_date_converter
|
75
|
+
assert_equal(Date.new(2012, 12, 31), c.parse)
|
76
|
+
c = Workbook::Cell.new("31.12.2012")
|
77
|
+
c.string_parsers << :string_non_american_date_converter
|
78
|
+
assert_equal(Date.new(2012, 12, 31), c.parse)
|
79
|
+
c = Workbook::Cell.new("12-1-2012")
|
80
|
+
c.string_parsers << :string_non_american_date_converter
|
81
|
+
assert_equal(Date.new(2012, 1, 12), c.parse)
|
52
82
|
end
|
53
83
|
|
54
84
|
def test_parse!
|
55
|
-
r= Workbook::Row.new
|
85
|
+
r = Workbook::Row.new
|
56
86
|
r[0] = Workbook::Cell.new "xls_cell"
|
57
87
|
r[0].parse!
|
58
|
-
assert_equal("xls_cell",r[0].value)
|
88
|
+
assert_equal("xls_cell", r[0].value)
|
59
89
|
r[1] = Workbook::Cell.new ""
|
60
90
|
r[1].parse!
|
61
91
|
assert_nil(r[1].value)
|
62
92
|
end
|
63
93
|
|
64
94
|
def test_once_failing_files
|
65
|
-
w = Workbook::Book.open(File.join(File.dirname(__FILE__),
|
95
|
+
w = Workbook::Book.open(File.join(File.dirname(__FILE__), "artifacts/failing_import1.xls")) # TRUE wasn't parsed properly
|
66
96
|
assert_equal(Workbook::Book, w.class)
|
67
97
|
end
|
68
98
|
end
|