xmlss 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +10 -16
- data/Rakefile +3 -3
- data/lib/xmlss/version.rb +1 -1
- data/test/cell_test.rb +68 -65
- data/test/column_test.rb +33 -32
- data/test/data_test.rb +70 -63
- data/test/helper.rb +15 -16
- data/test/irb.rb +10 -0
- data/test/item_set_test.rb +18 -17
- data/test/row_test.rb +52 -49
- data/test/style/alignment_test.rb +54 -61
- data/test/style/base_test.rb +90 -80
- data/test/style/border_test.rb +52 -58
- data/test/style/font_test.rb +47 -54
- data/test/style/interior_test.rb +32 -41
- data/test/style/number_format_test.rb +26 -37
- data/test/style/protection_test.rb +24 -28
- data/test/table_test.rb +48 -45
- data/test/workbook_test.rb +51 -46
- data/test/worksheet_test.rb +51 -50
- data/test/xml_test.rb +61 -60
- data/test/xmlss_test.rb +23 -21
- data/xmlss.gemspec +2 -2
- metadata +23 -27
- data/test/env.rb +0 -10
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,31 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xmlss (0.2.
|
5
|
-
enumeration (~> 1.
|
4
|
+
xmlss (0.2.1)
|
5
|
+
enumeration (~> 1.2)
|
6
6
|
nokogiri (~> 1.4.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
shoulda (2.11.3)
|
18
|
-
test-belt (0.2.1)
|
19
|
-
kelredd-useful (~> 0.4.0)
|
20
|
-
leftright (~> 0.9.0)
|
21
|
-
shoulda (~> 2.11)
|
11
|
+
ansi (1.3.0)
|
12
|
+
assert (0.3.0)
|
13
|
+
ansi (~> 1.3)
|
14
|
+
enumeration (1.2.1)
|
15
|
+
nokogiri (1.4.7)
|
16
|
+
rake (0.9.2)
|
22
17
|
|
23
18
|
PLATFORMS
|
24
19
|
ruby
|
25
20
|
|
26
21
|
DEPENDENCIES
|
22
|
+
assert (~> 0.3)
|
27
23
|
bundler (~> 1.0)
|
28
|
-
|
29
|
-
nokogiri (~> 1.4.0)
|
30
|
-
test-belt (= 0.2.1)
|
24
|
+
rake (~> 0.9.2)
|
31
25
|
xmlss!
|
data/Rakefile
CHANGED
data/lib/xmlss/version.rb
CHANGED
data/test/cell_test.rb
CHANGED
@@ -1,86 +1,89 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'xmlss/cell'
|
3
3
|
|
4
4
|
module Xmlss
|
5
|
-
class CellTest <
|
5
|
+
class CellTest < Assert::Context
|
6
|
+
desc "Xmlss::Cell"
|
7
|
+
subject { Cell.new }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
should have_accessor :index, :data
|
10
|
+
should have_accessor :formula, :href, :merge_across, :merge_down
|
11
|
+
should have_reader :h_ref
|
9
12
|
|
10
|
-
|
11
|
-
should_have_accessor :formula, :href, :merge_across, :merge_down
|
12
|
-
should_have_reader :h_ref
|
13
|
+
should_have_style(Cell)
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
[:data, :formula, :href].each do |a|
|
18
|
-
assert_equal nil, subject.send(a)
|
19
|
-
end
|
20
|
-
assert_equal nil, subject.merge_across
|
21
|
-
assert_equal nil, subject.merge_down
|
15
|
+
should "set it's defaults" do
|
16
|
+
[:data, :formula, :href].each do |a|
|
17
|
+
assert_equal nil, subject.send(a)
|
22
18
|
end
|
19
|
+
assert_equal nil, subject.merge_across
|
20
|
+
assert_equal nil, subject.merge_down
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
should "provide alias for :href" do
|
24
|
+
c = Cell.new({:href => "http://www.google.com"})
|
25
|
+
assert_equal "http://www.google.com", c.href
|
26
|
+
assert_equal "http://www.google.com", c.h_ref
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
assert_raises ArgumentError do
|
35
|
-
Cell.new({:index => 2.5})
|
36
|
-
end
|
37
|
-
assert_nothing_raised do
|
38
|
-
Cell.new({:index => 2})
|
39
|
-
end
|
29
|
+
should "bark when setting non Fixnum indices" do
|
30
|
+
assert_raises ArgumentError do
|
31
|
+
Cell.new({:index => "do it"})
|
40
32
|
end
|
41
|
-
|
42
|
-
|
43
|
-
assert_raises ArgumentError do
|
44
|
-
Cell.new({:merge_across => "do it"})
|
45
|
-
end
|
46
|
-
assert_raises ArgumentError do
|
47
|
-
Cell.new({:merge_down => 2.5})
|
48
|
-
end
|
49
|
-
assert_nothing_raised do
|
50
|
-
Cell.new({:merge_across => 2})
|
51
|
-
end
|
52
|
-
assert_nothing_raised do
|
53
|
-
Cell.new({:merge_down => 3})
|
54
|
-
end
|
33
|
+
assert_raises ArgumentError do
|
34
|
+
Cell.new({:index => 2.5})
|
55
35
|
end
|
56
|
-
|
57
|
-
|
58
|
-
[:index, :merge_across, :merge_down].each do |a|
|
59
|
-
assert_equal nil, Cell.new({a => -1}).send(a)
|
60
|
-
assert_equal nil, Cell.new({a => 0}).send(a)
|
61
|
-
assert_equal 1, Cell.new({a => 1}).send(a)
|
62
|
-
end
|
36
|
+
assert_nothing_raised do
|
37
|
+
Cell.new({:index => 2})
|
63
38
|
end
|
39
|
+
end
|
64
40
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
assert_equal 12, subject.data.value
|
75
|
-
end
|
41
|
+
should "bark when setting non Fixnum merge attrs" do
|
42
|
+
assert_raises ArgumentError do
|
43
|
+
Cell.new({:merge_across => "do it"})
|
44
|
+
end
|
45
|
+
assert_raises ArgumentError do
|
46
|
+
Cell.new({:merge_down => 2.5})
|
47
|
+
end
|
48
|
+
assert_nothing_raised do
|
49
|
+
Cell.new({:merge_across => 2})
|
76
50
|
end
|
51
|
+
assert_nothing_raised do
|
52
|
+
Cell.new({:merge_down => 3})
|
53
|
+
end
|
54
|
+
end
|
77
55
|
|
78
|
-
|
79
|
-
|
80
|
-
|
56
|
+
should "nil out merge/index values that are <= 0" do
|
57
|
+
[:index, :merge_across, :merge_down].each do |a|
|
58
|
+
assert_equal nil, Cell.new({a => -1}).send(a)
|
59
|
+
assert_equal nil, Cell.new({a => 0}).send(a)
|
60
|
+
assert_equal 1, Cell.new({a => 1}).send(a)
|
81
61
|
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
class CellDataTest < Assert::Context
|
67
|
+
desc "when using cell data"
|
68
|
+
subject do
|
69
|
+
Cell.new({
|
70
|
+
:data => Data.new(12, {:type => :number})
|
71
|
+
})
|
72
|
+
end
|
82
73
|
|
74
|
+
should "should build a data object" do
|
75
|
+
assert_kind_of Data, subject.data
|
76
|
+
assert_equal 12, subject.data.value
|
83
77
|
end
|
84
78
|
|
85
79
|
end
|
80
|
+
|
81
|
+
class CellDataXmlTest < CellDataTest
|
82
|
+
desc "for generating XML"
|
83
|
+
|
84
|
+
should have_reader :xml
|
85
|
+
should_build_node
|
86
|
+
|
87
|
+
end
|
88
|
+
|
86
89
|
end
|
data/test/column_test.rb
CHANGED
@@ -1,46 +1,47 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'xmlss/column'
|
3
3
|
|
4
4
|
module Xmlss
|
5
|
-
class ColumnTest <
|
5
|
+
class ColumnTest < Assert::Context
|
6
|
+
desc "Xmlss::Column"
|
7
|
+
subject { Column.new }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
should_have_style(Column)
|
10
|
+
should have_accessor :width, :auto_fit_width, :hidden
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
assert_equal false, subject.auto_fit_width
|
16
|
-
assert_equal false, subject.hidden
|
17
|
-
end
|
12
|
+
should "set it's defaults" do
|
13
|
+
assert_equal nil, subject.width
|
14
|
+
assert_equal false, subject.auto_fit_width
|
15
|
+
assert_equal false, subject.hidden
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
assert_nothing_raised do
|
24
|
-
Column.new({:width => 2})
|
25
|
-
end
|
26
|
-
assert_nothing_raised do
|
27
|
-
Column.new({:width => 3.5})
|
28
|
-
end
|
18
|
+
should "bark when setting non Numeric width" do
|
19
|
+
assert_raises ArgumentError do
|
20
|
+
Column.new({:width => "do it"})
|
29
21
|
end
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal nil, Column.new({:width => -1.2}).width
|
33
|
-
assert_equal nil, Column.new({:width => -1}).width
|
34
|
-
assert_equal 0, Column.new({:width => 0}).width
|
35
|
-
assert_equal 1.2, Column.new({:width => 1.2}).width
|
22
|
+
assert_nothing_raised do
|
23
|
+
Column.new({:width => 2})
|
36
24
|
end
|
37
|
-
|
38
|
-
|
39
|
-
should_have_reader :xml
|
40
|
-
should_build_node
|
25
|
+
assert_nothing_raised do
|
26
|
+
Column.new({:width => 3.5})
|
41
27
|
end
|
28
|
+
end
|
42
29
|
|
30
|
+
should "nil out height values that are < 0" do
|
31
|
+
assert_equal nil, Column.new({:width => -1.2}).width
|
32
|
+
assert_equal nil, Column.new({:width => -1}).width
|
33
|
+
assert_equal 0, Column.new({:width => 0}).width
|
34
|
+
assert_equal 1.2, Column.new({:width => 1.2}).width
|
43
35
|
end
|
44
36
|
|
45
37
|
end
|
38
|
+
|
39
|
+
class ColumnXmlTest < ColumnTest
|
40
|
+
desc "for generating XML"
|
41
|
+
|
42
|
+
should have_reader :xml
|
43
|
+
should_build_node
|
44
|
+
|
45
|
+
end
|
46
|
+
|
46
47
|
end
|
data/test/data_test.rb
CHANGED
@@ -1,75 +1,82 @@
|
|
1
|
-
require "
|
1
|
+
require "assert"
|
2
2
|
require 'xmlss/data'
|
3
3
|
|
4
4
|
module Xmlss
|
5
|
-
class DataTest <
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
5
|
+
class DataTest < Assert::Context
|
6
|
+
desc "Xmlss::Data"
|
7
|
+
subject { Data.new }
|
8
|
+
|
9
|
+
should have_accessor :type, :value
|
10
|
+
should have_instance_method :xml_value
|
11
|
+
|
12
|
+
should "set it's defaults" do
|
13
|
+
assert_equal Data.type(:string), subject.type
|
14
|
+
assert_equal "", subject.value
|
15
|
+
end
|
16
|
+
|
17
|
+
should "generate it's xml value" do
|
18
|
+
assert_equal "12", Data.new(12).xml_value
|
19
|
+
assert_equal "string", Data.new("string").xml_value
|
20
|
+
assert_equal "line#{Data::LB}break", Data.new("line\nbreak").xml_value
|
21
|
+
assert_equal "return#{Data::LB}break", Data.new("return\rbreak").xml_value
|
22
|
+
assert_equal "returnline#{Data::LB}break", Data.new("returnline\r\nbreak").xml_value
|
23
|
+
assert_equal "2011-03-01T00:00:00", Data.new(DateTime.parse('2011/03/01')).xml_value
|
24
|
+
assert_equal "2011-03-01T00:00:00", Data.new(Date.parse('2011/03/01')).xml_value
|
25
|
+
time = Time.now
|
26
|
+
assert_equal time.strftime("%Y-%m-%dT%H:%M:%S"), Data.new(time).xml_value
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class ExplicitDataTest < DataTest
|
32
|
+
desc "when using explicit type"
|
33
|
+
subject do
|
34
|
+
Data.new(12, {:type => :string})
|
35
|
+
end
|
36
|
+
|
37
|
+
should "should ignore the value type" do
|
38
|
+
assert_equal Data.type(:string), subject.type
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class NoTypeDataTest < DataTest
|
44
|
+
desc "when no type is specified"
|
45
|
+
|
46
|
+
should "cast types for Number, DateTime, Boolean, String" do
|
47
|
+
assert_equal Data.type(:number), Data.new(12).type
|
48
|
+
assert_equal Data.type(:number), Data.new(123.45).type
|
49
|
+
assert_equal Data.type(:date_time), Data.new(Time.now).type
|
50
|
+
assert_equal Data.type(:boolean), Data.new(true).type
|
51
|
+
assert_equal Data.type(:boolean), Data.new(false).type
|
52
|
+
assert_equal Data.type(:string), Data.new("a string").type
|
53
|
+
assert_equal Data.type(:string), Data.new(:symbol).type
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class WhitespaceDataTest < DataTest
|
59
|
+
desc "dealing with line breaks and leading space"
|
60
|
+
subject do
|
61
|
+
Data.new(%s{
|
55
62
|
Should
|
56
63
|
honor
|
57
64
|
this
|
58
|
-
|
59
|
-
|
65
|
+
})
|
66
|
+
end
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
68
|
+
should "honor them when generating xml" do
|
69
|
+
reg = /#{Data::LB}Should#{Data::LB}\s{2}honor#{Data::LB}\s{4}this#{Data::LB}/
|
70
|
+
assert_match reg, subject.xml_value
|
71
|
+
end
|
66
72
|
|
67
|
-
|
68
|
-
should_have_reader :xml
|
69
|
-
should_build_node
|
70
|
-
end
|
73
|
+
end
|
71
74
|
|
72
|
-
|
75
|
+
class XmlDataTest < DataTest
|
76
|
+
desc "for generating XML"
|
73
77
|
|
78
|
+
should have_reader :xml
|
79
|
+
should_build_node
|
74
80
|
end
|
81
|
+
|
75
82
|
end
|