osheet 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +33 -0
- data/README.rdoc +103 -61
- data/Rakefile +5 -56
- data/examples/basic.rb +73 -0
- data/examples/formats.rb +366 -0
- data/examples/trivial.rb +21 -0
- data/lib/osheet/associations.rb +62 -0
- data/lib/osheet/cell.rb +44 -10
- data/lib/osheet/column.rb +34 -7
- data/lib/osheet/format/accounting.rb +21 -0
- data/lib/osheet/format/currency.rb +23 -0
- data/lib/osheet/format/custom.rb +13 -0
- data/lib/osheet/format/datetime.rb +13 -0
- data/lib/osheet/format/fraction.rb +33 -0
- data/lib/osheet/format/general.rb +9 -0
- data/lib/osheet/format/number.rb +13 -0
- data/lib/osheet/format/numeric.rb +113 -0
- data/lib/osheet/format/percentage.rb +25 -0
- data/lib/osheet/format/scientific.rb +25 -0
- data/lib/osheet/format/special.rb +28 -0
- data/lib/osheet/format/text.rb +11 -0
- data/lib/osheet/format.rb +30 -0
- data/lib/osheet/row.rb +32 -7
- data/lib/osheet/style.rb +65 -0
- data/lib/osheet/style_set.rb +39 -0
- data/lib/osheet/styled_element.rb +18 -0
- data/lib/osheet/template.rb +32 -0
- data/lib/osheet/template_set.rb +57 -0
- data/lib/osheet/version.rb +1 -11
- data/lib/osheet/workbook.rb +32 -16
- data/lib/osheet/workbook_element.rb +21 -0
- data/lib/osheet/worksheet.rb +18 -20
- data/lib/osheet/worksheet_element.rb +15 -0
- data/lib/osheet/xmlss_writer/base.rb +42 -0
- data/lib/osheet/xmlss_writer/elements.rb +68 -0
- data/lib/osheet/xmlss_writer/styles.rb +176 -0
- data/lib/osheet/xmlss_writer.rb +1 -0
- data/lib/osheet.rb +7 -27
- data/osheet.gemspec +26 -0
- data/test/cell_test.rb +83 -0
- data/test/column_test.rb +81 -0
- data/test/env.rb +9 -0
- data/test/format/accounting_test.rb +158 -0
- data/test/format/currency_test.rb +158 -0
- data/test/format/custom_test.rb +22 -0
- data/test/format/datetime_test.rb +22 -0
- data/test/format/fraction_test.rb +84 -0
- data/test/format/general_test.rb +21 -0
- data/test/format/number_test.rb +93 -0
- data/test/format/percentage_test.rb +116 -0
- data/test/format/scientific_test.rb +116 -0
- data/test/format/special_test.rb +51 -0
- data/test/format/text_test.rb +18 -0
- data/test/format_test.rb +35 -0
- data/test/helper.rb +101 -0
- data/test/osheet_test.rb +14 -0
- data/test/row_test.rb +78 -0
- data/test/style_set_test.rb +50 -0
- data/test/style_test.rb +92 -0
- data/test/template_set_test.rb +76 -0
- data/test/template_test.rb +63 -0
- data/test/workbook_test.rb +142 -0
- data/test/worksheet_test.rb +77 -0
- data/test/xmlss_writer/base_test.rb +92 -0
- data/test/xmlss_writer/elements_test.rb +168 -0
- data/test/xmlss_writer/styles_test.rb +253 -0
- metadata +141 -30
- data/lib/osheet/base.rb +0 -95
@@ -0,0 +1,158 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/currency'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class CurrencyTest < Test::Unit::TestCase
|
7
|
+
context "Currency format" do
|
8
|
+
subject { Currency.new }
|
9
|
+
|
10
|
+
should_have_accessors :decimal_places, :symbol, :comma_separator, :negative_numbers
|
11
|
+
|
12
|
+
should "provide symbol options" do
|
13
|
+
assert_equal 3, Currency.symbol_set.size
|
14
|
+
[:none, :dollar, :euro].each do |a|
|
15
|
+
assert Currency.symbol_set.include?(a)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "provide negative numbers options" do
|
20
|
+
assert_equal 4, Currency.negative_numbers_set.size
|
21
|
+
[:black, :black_parenth, :red, :red_parenth].each do |a|
|
22
|
+
assert Currency.negative_numbers_set.include?(a)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
should "set default values" do
|
27
|
+
assert_equal 2, subject.decimal_places
|
28
|
+
assert_equal :dollar, subject.symbol
|
29
|
+
assert_equal true, subject.comma_separator
|
30
|
+
assert_equal :black, subject.negative_numbers
|
31
|
+
end
|
32
|
+
|
33
|
+
should "only allow Fixnum decimal places between 0 and 30" do
|
34
|
+
assert_raises ArgumentError do
|
35
|
+
Currency.new({:decimal_places => -1})
|
36
|
+
end
|
37
|
+
assert_raises ArgumentError do
|
38
|
+
Currency.new({:decimal_places => 31})
|
39
|
+
end
|
40
|
+
assert_raises ArgumentError do
|
41
|
+
Currency.new({:decimal_places => 'poo'})
|
42
|
+
end
|
43
|
+
assert_nothing_raised do
|
44
|
+
Currency.new({:decimal_places => 1})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
should "generate decimal place style strings" do
|
49
|
+
assert_equal "0", Currency.new({
|
50
|
+
:decimal_places => 0,
|
51
|
+
:comma_separator => false,
|
52
|
+
:symbol => :none
|
53
|
+
}).style
|
54
|
+
(1..5).each do |n|
|
55
|
+
assert_equal "0.#{'0'*n}", Currency.new({
|
56
|
+
:decimal_places => n,
|
57
|
+
:comma_separator => false,
|
58
|
+
:symbol => :none
|
59
|
+
}).style
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
should "generate comma separator style strings" do
|
64
|
+
assert_equal "0", Currency.new({
|
65
|
+
:comma_separator => false,
|
66
|
+
:decimal_places => 0,
|
67
|
+
:symbol => :none
|
68
|
+
}).style
|
69
|
+
assert_equal "#,##0", Currency.new({
|
70
|
+
:comma_separator => true,
|
71
|
+
:decimal_places => 0,
|
72
|
+
:symbol => :none
|
73
|
+
}).style
|
74
|
+
end
|
75
|
+
|
76
|
+
should "generate parenth negative numbers style strings" do
|
77
|
+
assert_equal "0", Currency.new({
|
78
|
+
:negative_numbers => :black,
|
79
|
+
:decimal_places => 0,
|
80
|
+
:comma_separator => false,
|
81
|
+
:symbol => :none
|
82
|
+
}).style
|
83
|
+
assert_equal "0_);\(0\)", Currency.new({
|
84
|
+
:negative_numbers => :black_parenth,
|
85
|
+
:decimal_places => 0,
|
86
|
+
:comma_separator => false,
|
87
|
+
:symbol => :none
|
88
|
+
}).style
|
89
|
+
end
|
90
|
+
|
91
|
+
should "generate red negative numbers style strings" do
|
92
|
+
assert_equal "0;[Red]0", Currency.new({
|
93
|
+
:negative_numbers => :red,
|
94
|
+
:decimal_places => 0,
|
95
|
+
:comma_separator => false,
|
96
|
+
:symbol => :none
|
97
|
+
}).style
|
98
|
+
assert_equal "0_);[Red]\(0\)", Currency.new({
|
99
|
+
:negative_numbers => :red_parenth,
|
100
|
+
:decimal_places => 0,
|
101
|
+
:comma_separator => false,
|
102
|
+
:symbol => :none
|
103
|
+
}).style
|
104
|
+
end
|
105
|
+
|
106
|
+
should "generate symbol style strings" do
|
107
|
+
assert_equal "0", Currency.new({
|
108
|
+
:decimal_places => 0,
|
109
|
+
:comma_separator => false,
|
110
|
+
:symbol => :none
|
111
|
+
}).style
|
112
|
+
assert_equal "\"$\"0", Currency.new({
|
113
|
+
:decimal_places => 0,
|
114
|
+
:comma_separator => false,
|
115
|
+
:symbol => :dollar
|
116
|
+
}).style
|
117
|
+
assert_equal "[$€-2]\ 0", Currency.new({
|
118
|
+
:decimal_places => 0,
|
119
|
+
:comma_separator => false,
|
120
|
+
:symbol => :euro
|
121
|
+
}).style
|
122
|
+
end
|
123
|
+
|
124
|
+
should "generate complex style string" do
|
125
|
+
assert_equal("\"$\"0.00_);\(\"$\"0.00\)", Currency.new({
|
126
|
+
:symbol => :dollar,
|
127
|
+
:decimal_places => 2,
|
128
|
+
:negative_numbers => :black_parenth,
|
129
|
+
:comma_separator => false
|
130
|
+
}).style)
|
131
|
+
assert_equal("[$€-2]\ #,##0.0000_);[Red]\([$€-2]\ #,##0.0000\)", Currency.new({
|
132
|
+
:symbol => :euro,
|
133
|
+
:decimal_places => 4,
|
134
|
+
:negative_numbers => :red_parenth,
|
135
|
+
:comma_separator => true
|
136
|
+
}).style)
|
137
|
+
end
|
138
|
+
|
139
|
+
should "provide unique format keys" do
|
140
|
+
assert_equal("currency_dollar_2_nocomma_blackparenth", Currency.new({
|
141
|
+
:decimal_places => 2,
|
142
|
+
:negative_numbers => :black_parenth,
|
143
|
+
:comma_separator => false
|
144
|
+
}).key)
|
145
|
+
assert_equal("currency_none_4_comma_redparenth", Currency.new({
|
146
|
+
:symbol => :none,
|
147
|
+
:decimal_places => 4,
|
148
|
+
:negative_numbers => :red_parenth,
|
149
|
+
:comma_separator => true
|
150
|
+
}).key)
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/custom'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class CustomTest < Test::Unit::TestCase
|
7
|
+
context "Custom format" do
|
8
|
+
should "generate a basic style string and key" do
|
9
|
+
f = Custom.new '@'
|
10
|
+
assert_equal "@", f.style
|
11
|
+
assert_equal "custom_@", f.key
|
12
|
+
end
|
13
|
+
|
14
|
+
should "generate a more complex style string and key" do
|
15
|
+
f = Custom.new 'm/d/yy'
|
16
|
+
assert_equal 'm/d/yy', f.style
|
17
|
+
assert_equal "custom_m/d/yy", f.key
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/datetime'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class DatetimeTest < Test::Unit::TestCase
|
7
|
+
context "Datetime format" do
|
8
|
+
should "generate a basic style string and key" do
|
9
|
+
f = Datetime.new 'mm/dd/yyyy'
|
10
|
+
assert_equal "mm/dd/yyyy", f.style
|
11
|
+
assert_equal "datetime_mm/dd/yyyy", f.key
|
12
|
+
end
|
13
|
+
|
14
|
+
should "generate a more complex style string and key" do
|
15
|
+
f = Datetime.new 'yy-m'
|
16
|
+
assert_equal 'yy-m', f.style
|
17
|
+
assert_equal "datetime_yy-m", f.key
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/fraction'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class FractionTest < Test::Unit::TestCase
|
7
|
+
context "Fraction format" do
|
8
|
+
subject { Fraction.new }
|
9
|
+
|
10
|
+
should_have_accessors :type
|
11
|
+
|
12
|
+
should "provide options for type" do
|
13
|
+
assert_equal 9, Fraction.type_set.size
|
14
|
+
[ :one_digit, :two_digits, :three_digits,
|
15
|
+
:halves, :quarters, :eighths, :sixteenths,
|
16
|
+
:tenths, :hundredths
|
17
|
+
].each do |a|
|
18
|
+
assert Fraction.type_set.include?(a)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "set default values" do
|
23
|
+
assert_equal '??/??', subject.type
|
24
|
+
assert_equal :two_digits, subject.type_key
|
25
|
+
end
|
26
|
+
|
27
|
+
should "generate a one_digit type style strings and key" do
|
28
|
+
f = Fraction.new(:type => :one_digit)
|
29
|
+
assert_equal "#\ ?/?", f.style
|
30
|
+
assert_equal "fraction_onedigit", f.key
|
31
|
+
end
|
32
|
+
|
33
|
+
should "generate a two_digit type style strings and key" do
|
34
|
+
f = Fraction.new(:type => :two_digits)
|
35
|
+
assert_equal "#\ ??/??", f.style
|
36
|
+
assert_equal "fraction_twodigits", f.key
|
37
|
+
end
|
38
|
+
|
39
|
+
should "generate a three_digit type style strings and key" do
|
40
|
+
f = Fraction.new(:type => :three_digits)
|
41
|
+
assert_equal "#\ ???/???", f.style
|
42
|
+
assert_equal "fraction_threedigits", f.key
|
43
|
+
end
|
44
|
+
|
45
|
+
should "generate a halves type style strings and key" do
|
46
|
+
f = Fraction.new(:type => :halves)
|
47
|
+
assert_equal "#\ ?/2", f.style
|
48
|
+
assert_equal "fraction_halves", f.key
|
49
|
+
end
|
50
|
+
|
51
|
+
should "generate a quarters type style strings and key" do
|
52
|
+
f = Fraction.new(:type => :quarters)
|
53
|
+
assert_equal "#\ ?/4", f.style
|
54
|
+
assert_equal "fraction_quarters", f.key
|
55
|
+
end
|
56
|
+
|
57
|
+
should "generate a eighths type style strings and key" do
|
58
|
+
f = Fraction.new(:type => :eighths)
|
59
|
+
assert_equal "#\ ?/8", f.style
|
60
|
+
assert_equal "fraction_eighths", f.key
|
61
|
+
end
|
62
|
+
|
63
|
+
should "generate a sixteenths type style strings and key" do
|
64
|
+
f = Fraction.new(:type => :sixteenths)
|
65
|
+
assert_equal "#\ ??/16", f.style
|
66
|
+
assert_equal "fraction_sixteenths", f.key
|
67
|
+
end
|
68
|
+
|
69
|
+
should "generate a tenths type style strings and key" do
|
70
|
+
f = Fraction.new(:type => :tenths)
|
71
|
+
assert_equal "#\ ?/10", f.style
|
72
|
+
assert_equal "fraction_tenths", f.key
|
73
|
+
end
|
74
|
+
|
75
|
+
should "generate a hundredths type style strings and key" do
|
76
|
+
f = Fraction.new(:type => :hundredths)
|
77
|
+
assert_equal "#\ ??/100", f.style
|
78
|
+
assert_equal "fraction_hundredths", f.key
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/general'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class GeneralTest < Test::Unit::TestCase
|
7
|
+
context "General format" do
|
8
|
+
subject { General.new }
|
9
|
+
|
10
|
+
should "always provide a nil style string" do
|
11
|
+
assert_equal nil, subject.style
|
12
|
+
end
|
13
|
+
|
14
|
+
should "always provide and empty format key" do
|
15
|
+
assert_equal '', subject.key
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/number'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class NumberTest < Test::Unit::TestCase
|
7
|
+
context "Number format" do
|
8
|
+
subject { Number.new }
|
9
|
+
|
10
|
+
should_have_accessors :decimal_places, :comma_separator, :negative_numbers
|
11
|
+
|
12
|
+
should "provide options for negative numbers" do
|
13
|
+
assert_equal 4, Number.negative_numbers_set.size
|
14
|
+
[:black, :black_parenth, :red, :red_parenth].each do |a|
|
15
|
+
assert Number.negative_numbers_set.include?(a)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set default values" do
|
20
|
+
assert_equal 0, subject.decimal_places
|
21
|
+
assert_equal false, subject.comma_separator
|
22
|
+
assert_equal :black, subject.negative_numbers
|
23
|
+
end
|
24
|
+
|
25
|
+
should "only allow Fixnum decimal places between 0 and 30" do
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
Number.new({:decimal_places => -1})
|
28
|
+
end
|
29
|
+
assert_raises ArgumentError do
|
30
|
+
Number.new({:decimal_places => 31})
|
31
|
+
end
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
Number.new({:decimal_places => 'poo'})
|
34
|
+
end
|
35
|
+
assert_nothing_raised do
|
36
|
+
Number.new({:decimal_places => 1})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "generate decimal place style strings" do
|
41
|
+
assert_equal "0", Number.new({:decimal_places => 0}).style
|
42
|
+
(1..5).each do |n|
|
43
|
+
assert_equal "0.#{'0'*n}", Number.new({:decimal_places => n}).style
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
should "generate comma separator style strings" do
|
48
|
+
assert_equal "0", Number.new({:comma_separator => false}).style
|
49
|
+
assert_equal "#,##0", Number.new({:comma_separator => true}).style
|
50
|
+
end
|
51
|
+
|
52
|
+
should "generate parenth negative numbers style strings" do
|
53
|
+
assert_equal "0", Number.new({:negative_numbers => :black}).style
|
54
|
+
assert_equal "0_);\(0\)", Number.new({:negative_numbers => :black_parenth}).style
|
55
|
+
end
|
56
|
+
|
57
|
+
should "generate red negative numbers style strings" do
|
58
|
+
assert_equal "0;[Red]0", Number.new({:negative_numbers => :red}).style
|
59
|
+
assert_equal "0_);[Red]\(0\)", Number.new({:negative_numbers => :red_parenth}).style
|
60
|
+
end
|
61
|
+
|
62
|
+
should "generate complex style string" do
|
63
|
+
assert_equal("0.00_);\(0.00\)", Number.new({
|
64
|
+
:decimal_places => 2,
|
65
|
+
:negative_numbers => :black_parenth,
|
66
|
+
:comma_separator => false
|
67
|
+
}).style)
|
68
|
+
assert_equal("#,##0.0000_);[Red]\(#,##0.0000\)", Number.new({
|
69
|
+
:decimal_places => 4,
|
70
|
+
:negative_numbers => :red_parenth,
|
71
|
+
:comma_separator => true
|
72
|
+
}).style)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "provide unique format keys" do
|
76
|
+
assert_equal("number_none_2_nocomma_blackparenth", Number.new({
|
77
|
+
:decimal_places => 2,
|
78
|
+
:negative_numbers => :black_parenth,
|
79
|
+
:comma_separator => false
|
80
|
+
}).key)
|
81
|
+
assert_equal("number_none_4_comma_redparenth", Number.new({
|
82
|
+
:decimal_places => 4,
|
83
|
+
:negative_numbers => :red_parenth,
|
84
|
+
:comma_separator => true
|
85
|
+
}).key)
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/percentage'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class PercentageTest < Test::Unit::TestCase
|
7
|
+
context "Percentage format" do
|
8
|
+
subject { Percentage.new }
|
9
|
+
|
10
|
+
should_have_accessors :decimal_places, :symbol, :comma_separator, :negative_numbers
|
11
|
+
|
12
|
+
should "provide negative numbers options" do
|
13
|
+
assert_equal 4, Percentage.negative_numbers_set.size
|
14
|
+
[:black, :black_parenth, :red, :red_parenth].each do |a|
|
15
|
+
assert Percentage.negative_numbers_set.include?(a)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set default values" do
|
20
|
+
assert_equal 2, subject.decimal_places
|
21
|
+
assert_equal false, subject.comma_separator
|
22
|
+
assert_equal :black, subject.negative_numbers
|
23
|
+
end
|
24
|
+
|
25
|
+
should "only allow Fixnum decimal places between 0 and 30" do
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
Percentage.new({:decimal_places => -1})
|
28
|
+
end
|
29
|
+
assert_raises ArgumentError do
|
30
|
+
Percentage.new({:decimal_places => 31})
|
31
|
+
end
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
Percentage.new({:decimal_places => 'poo'})
|
34
|
+
end
|
35
|
+
assert_nothing_raised do
|
36
|
+
Percentage.new({:decimal_places => 1})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "generate decimal place style strings" do
|
41
|
+
assert_equal "0%", Percentage.new({
|
42
|
+
:decimal_places => 0
|
43
|
+
}).style
|
44
|
+
(1..5).each do |n|
|
45
|
+
assert_equal "0.#{'0'*n}%", Percentage.new({
|
46
|
+
:decimal_places => n
|
47
|
+
}).style
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
should "generate comma separator style strings" do
|
52
|
+
assert_equal "0%", Percentage.new({
|
53
|
+
:comma_separator => false,
|
54
|
+
:decimal_places => 0
|
55
|
+
}).style
|
56
|
+
assert_equal "#,##0%", Percentage.new({
|
57
|
+
:comma_separator => true,
|
58
|
+
:decimal_places => 0
|
59
|
+
}).style
|
60
|
+
end
|
61
|
+
|
62
|
+
should "generate parenth negative numbers style strings" do
|
63
|
+
assert_equal "0%", Percentage.new({
|
64
|
+
:negative_numbers => :black,
|
65
|
+
:decimal_places => 0
|
66
|
+
}).style
|
67
|
+
assert_equal "0%_);\(0%\)", Percentage.new({
|
68
|
+
:negative_numbers => :black_parenth,
|
69
|
+
:decimal_places => 0
|
70
|
+
}).style
|
71
|
+
end
|
72
|
+
|
73
|
+
should "generate red negative numbers style strings" do
|
74
|
+
assert_equal "0%;[Red]0%", Percentage.new({
|
75
|
+
:negative_numbers => :red,
|
76
|
+
:decimal_places => 0
|
77
|
+
}).style
|
78
|
+
assert_equal "0%_);[Red]\(0%\)", Percentage.new({
|
79
|
+
:negative_numbers => :red_parenth,
|
80
|
+
:decimal_places => 0
|
81
|
+
}).style
|
82
|
+
end
|
83
|
+
|
84
|
+
should "generate complex style string" do
|
85
|
+
assert_equal("0.00%_);\(0.00%\)", Percentage.new({
|
86
|
+
:decimal_places => 2,
|
87
|
+
:negative_numbers => :black_parenth,
|
88
|
+
:comma_separator => false
|
89
|
+
}).style)
|
90
|
+
assert_equal("#,##0.0000%_);[Red]\(#,##0.0000%\)", Percentage.new({
|
91
|
+
:decimal_places => 4,
|
92
|
+
:negative_numbers => :red_parenth,
|
93
|
+
:comma_separator => true
|
94
|
+
}).style)
|
95
|
+
end
|
96
|
+
|
97
|
+
should "provide unique format keys" do
|
98
|
+
assert_equal("percentage_none_2_nocomma_blackparenth", Percentage.new({
|
99
|
+
:decimal_places => 2,
|
100
|
+
:negative_numbers => :black_parenth,
|
101
|
+
:comma_separator => false
|
102
|
+
}).key)
|
103
|
+
assert_equal("percentage_none_4_comma_redparenth", Percentage.new({
|
104
|
+
:symbol => :none,
|
105
|
+
:decimal_places => 4,
|
106
|
+
:negative_numbers => :red_parenth,
|
107
|
+
:comma_separator => true
|
108
|
+
}).key)
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/scientific'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class ScientificTest < Test::Unit::TestCase
|
7
|
+
context "Scientific format" do
|
8
|
+
subject { Scientific.new }
|
9
|
+
|
10
|
+
should_have_accessors :decimal_places, :symbol, :comma_separator, :negative_numbers
|
11
|
+
|
12
|
+
should "provide negative numbers options" do
|
13
|
+
assert_equal 4, Scientific.negative_numbers_set.size
|
14
|
+
[:black, :black_parenth, :red, :red_parenth].each do |a|
|
15
|
+
assert Scientific.negative_numbers_set.include?(a)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set default values" do
|
20
|
+
assert_equal 2, subject.decimal_places
|
21
|
+
assert_equal false, subject.comma_separator
|
22
|
+
assert_equal :black, subject.negative_numbers
|
23
|
+
end
|
24
|
+
|
25
|
+
should "only allow Fixnum decimal places between 0 and 30" do
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
Scientific.new({:decimal_places => -1})
|
28
|
+
end
|
29
|
+
assert_raises ArgumentError do
|
30
|
+
Scientific.new({:decimal_places => 31})
|
31
|
+
end
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
Scientific.new({:decimal_places => 'poo'})
|
34
|
+
end
|
35
|
+
assert_nothing_raised do
|
36
|
+
Scientific.new({:decimal_places => 1})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "generate decimal place style strings" do
|
41
|
+
assert_equal "0E+00", Scientific.new({
|
42
|
+
:decimal_places => 0
|
43
|
+
}).style
|
44
|
+
(1..5).each do |n|
|
45
|
+
assert_equal "0.#{'0'*n}E+00", Scientific.new({
|
46
|
+
:decimal_places => n
|
47
|
+
}).style
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
should "generate comma separator style strings" do
|
52
|
+
assert_equal "0E+00", Scientific.new({
|
53
|
+
:comma_separator => false,
|
54
|
+
:decimal_places => 0
|
55
|
+
}).style
|
56
|
+
assert_equal "#,##0E+00", Scientific.new({
|
57
|
+
:comma_separator => true,
|
58
|
+
:decimal_places => 0
|
59
|
+
}).style
|
60
|
+
end
|
61
|
+
|
62
|
+
should "generate parenth negative numbers style strings" do
|
63
|
+
assert_equal "0E+00", Scientific.new({
|
64
|
+
:negative_numbers => :black,
|
65
|
+
:decimal_places => 0
|
66
|
+
}).style
|
67
|
+
assert_equal "0E+00_);\(0E+00\)", Scientific.new({
|
68
|
+
:negative_numbers => :black_parenth,
|
69
|
+
:decimal_places => 0
|
70
|
+
}).style
|
71
|
+
end
|
72
|
+
|
73
|
+
should "generate red negative numbers style strings" do
|
74
|
+
assert_equal "0E+00;[Red]0E+00", Scientific.new({
|
75
|
+
:negative_numbers => :red,
|
76
|
+
:decimal_places => 0
|
77
|
+
}).style
|
78
|
+
assert_equal "0E+00_);[Red]\(0E+00\)", Scientific.new({
|
79
|
+
:negative_numbers => :red_parenth,
|
80
|
+
:decimal_places => 0
|
81
|
+
}).style
|
82
|
+
end
|
83
|
+
|
84
|
+
should "generate complex style string" do
|
85
|
+
assert_equal("0.00E+00_);\(0.00E+00\)", Scientific.new({
|
86
|
+
:decimal_places => 2,
|
87
|
+
:negative_numbers => :black_parenth,
|
88
|
+
:comma_separator => false
|
89
|
+
}).style)
|
90
|
+
assert_equal("#,##0.0000E+00_);[Red]\(#,##0.0000E+00\)", Scientific.new({
|
91
|
+
:decimal_places => 4,
|
92
|
+
:negative_numbers => :red_parenth,
|
93
|
+
:comma_separator => true
|
94
|
+
}).style)
|
95
|
+
end
|
96
|
+
|
97
|
+
should "provide unique format keys" do
|
98
|
+
assert_equal("scientific_none_2_nocomma_blackparenth", Scientific.new({
|
99
|
+
:decimal_places => 2,
|
100
|
+
:negative_numbers => :black_parenth,
|
101
|
+
:comma_separator => false
|
102
|
+
}).key)
|
103
|
+
assert_equal("scientific_none_4_comma_redparenth", Scientific.new({
|
104
|
+
:symbol => :none,
|
105
|
+
:decimal_places => 4,
|
106
|
+
:negative_numbers => :red_parenth,
|
107
|
+
:comma_separator => true
|
108
|
+
}).key)
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require 'osheet/format/special'
|
3
|
+
|
4
|
+
module Osheet::Format
|
5
|
+
|
6
|
+
class SpecialTest < Test::Unit::TestCase
|
7
|
+
context "Special format" do
|
8
|
+
subject { Special.new }
|
9
|
+
|
10
|
+
should_have_accessors :type
|
11
|
+
|
12
|
+
should "provide options for type" do
|
13
|
+
assert_equal 4, Special.type_set.size
|
14
|
+
[ :zip_code, :zip_code_plus_4, :phone_number, :social_security_number].each do |a|
|
15
|
+
assert Special.type_set.include?(a)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set default values" do
|
20
|
+
assert_equal nil, subject.type
|
21
|
+
assert_equal nil, subject.type_key
|
22
|
+
end
|
23
|
+
|
24
|
+
should "generate a zip_code type style strings and key" do
|
25
|
+
f = Special.new(:type => :zip_code)
|
26
|
+
assert_equal "00000", f.style
|
27
|
+
assert_equal "special_zipcode", f.key
|
28
|
+
end
|
29
|
+
|
30
|
+
should "generate a zip_code_plus_4 type style strings and key" do
|
31
|
+
f = Special.new(:type => :zip_code_plus_4)
|
32
|
+
assert_equal "00000-0000", f.style
|
33
|
+
assert_equal "special_zipcodeplus4", f.key
|
34
|
+
end
|
35
|
+
|
36
|
+
should "generate a phone_number type style strings and key" do
|
37
|
+
f = Special.new(:type => :phone_number)
|
38
|
+
assert_equal "[<=9999999]###-####;(###) ###-####", f.style
|
39
|
+
assert_equal "special_phonenumber", f.key
|
40
|
+
end
|
41
|
+
|
42
|
+
should "generate a social_security_number type style strings and key" do
|
43
|
+
f = Special.new(:type => :social_security_number)
|
44
|
+
assert_equal "000-00-0000", f.style
|
45
|
+
assert_equal "special_socialsecuritynumber", f.key
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|