summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAli Mujtaba <[email protected]>2019-10-15 00:37:56 +0500
committerStefan Daschek <[email protected]>2019-10-29 01:40:55 +0100
commiteaa635a3e4a519556d9e6fe0191afba9aa9125d7 (patch)
tree0dfafe9114b2ed8aebb2819bc87a225e3e57d5c9
parent2cdaed0178d95c8f0e63ae60c94cfd8bd787e5c6 (diff)
downloadcaxlsx-eaa635a3e4a519556d9e6fe0191afba9aa9125d7.tar.gz
caxlsx-eaa635a3e4a519556d9e6fe0191afba9aa9125d7.zip
fix validate document with font option underline
-rw-r--r--lib/axlsx/stylesheet/font.rb12
-rw-r--r--test/stylesheet/tc_font.rb16
-rw-r--r--test/stylesheet/tc_styles.rb28
3 files changed, 51 insertions, 5 deletions
diff --git a/lib/axlsx/stylesheet/font.rb b/lib/axlsx/stylesheet/font.rb
index baa1ef83..d9a4a4d8 100644
--- a/lib/axlsx/stylesheet/font.rb
+++ b/lib/axlsx/stylesheet/font.rb
@@ -76,7 +76,10 @@ module Axlsx
attr_reader :i
# Indicates if the font should be rendered underlined
- # @return [Boolean]
+ # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true, false
+ # @return [String]
+ # @note
+ # true or false is for backwards compatibility and is reassigned to :single or :none respectively
attr_reader :u
# Indicates if the font should be rendered with a strikthrough
@@ -118,7 +121,12 @@ module Axlsx
# @see i
def i=(v) Axlsx::validate_boolean v; @i = v end
# @see u
- def u=(v) Axlsx::validate_boolean v; @u = v end
+ def u=(v)
+ v = :single if (v == true || v == 1 || v == :true || v == 'true')
+ v = :none if (v == false || v == 0 || v == :false || v == 'false')
+ Axlsx::validate_cell_u v
+ @u = v
+ end
# @see strike
def strike=(v) Axlsx::validate_boolean v; @strike = v end
# @see outline
diff --git a/test/stylesheet/tc_font.rb b/test/stylesheet/tc_font.rb
index 7b3da25a..4d548d7c 100644
--- a/test/stylesheet/tc_font.rb
+++ b/test/stylesheet/tc_font.rb
@@ -62,11 +62,23 @@ class TestFont < Test::Unit::TestCase
assert_equal(@item.i, true)
end
- # def u=(v) Axlsx::validate_boolean v; @u = v end
+ # def u=(v) Axlsx::validate_cell_u v; @u = v end
def test_u
assert_raise(ArgumentError) { @item.u = -7 }
+ assert_nothing_raised { @item.u = :single }
+ assert_equal(@item.u, :single)
+ doc = Nokogiri::XML(@item.to_xml_string)
+ assert(doc.xpath('//u[@val="single"]'))
+ end
+
+ def test_u_backward_compatibility
+ # backward compatibility for true
assert_nothing_raised { @item.u = true }
- assert_equal(@item.u, true)
+ assert_equal(@item.u, :single)
+
+ # backward compatibility for false
+ assert_nothing_raised { @item.u = false }
+ assert_equal(@item.u, :none)
end
# def strike=(v) Axlsx::validate_boolean v; @strike = v end
diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb
index eb1680ad..72bf1466 100644
--- a/test/stylesheet/tc_styles.rb
+++ b/test/stylesheet/tc_styles.rb
@@ -124,7 +124,7 @@ class TestStyles < Test::Unit::TestCase
:sz => 20,
:b => 1,
:i => 1,
- :u => 1,
+ :u => :single,
:strike => 1,
:outline => 1,
:shadow => 1,
@@ -232,4 +232,30 @@ class TestStyles < Test::Unit::TestCase
style = @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf
assert_equal(1, style, "returns the second dxfId")
end
+
+ def test_valid_document_with_font_options
+ font_options = {
+ :fg_color => "FF050505",
+ :sz => 20,
+ :b => 1,
+ :i => 1,
+ :u => :single,
+ :strike => 1,
+ :outline => 1,
+ :shadow => 1,
+ :charset => 9,
+ :family => 1,
+ :font_name => "woot font"
+ }
+ @styles.add_style font_options
+
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
+ doc = Nokogiri::XML(@styles.to_xml_string)
+ errors = []
+ schema.validate(doc).each do |error|
+ errors.push error
+ puts error.message
+ end
+ assert(errors.size == 0)
+ end
end