summaryrefslogtreecommitdiffhomepage
path: root/test/workbook/tc_shared_strings_table.rb
blob: b0e9de05cef8b0cba4898a152bedf061fd8e8dd6 (plain)
1
2
3
4
5
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
require 'test/unit'
require 'axlsx.rb'

class TestSharedStringsTable < Test::Unit::TestCase

  def setup    
    @p = Axlsx::Package.new :use_shared_strings=>true
    ws = @p.workbook.add_worksheet
    ws.add_row ['a', 1, 'b']
    ws.add_row ['b', 1, 'c']
    ws.add_row ['c', 1, 'd']    
  end

  def test_workbook_has_shared_strings
    assert(@p.workbook.shared_strings.is_a?(Axlsx::SharedStringsTable), "shared string table was not created")
  end

  def test_count
    sst = @p.workbook.shared_strings
    assert_equal(sst.count, 6)
  end

  def test_unique_count
    sst = @p.workbook.shared_strings
    assert_equal(sst.unique_count, 4)
  end

  def test_valid_document    
    schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
    doc = Nokogiri::XML(@p.workbook.shared_strings.to_xml)
    errors = []
    schema.validate(doc).each do |error|
      puts error.message
      errors << error
    end
    assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map{ |e| e.message }.to_s)
  end

end