From 98c420f1810add2411a9bdeca0947f3a7515ab8b Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Fri, 23 Mar 2012 23:51:22 +0900 Subject: move table spec inside of worksheet folder to keep in line with gem lib structure --- test/table/tc_table.rb | 72 ------------------------------- test/workbook/worksheet/table/tc_table.rb | 71 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 72 deletions(-) delete mode 100644 test/table/tc_table.rb create mode 100644 test/workbook/worksheet/table/tc_table.rb diff --git a/test/table/tc_table.rb b/test/table/tc_table.rb deleted file mode 100644 index d6bc95d0..00000000 --- a/test/table/tc_table.rb +++ /dev/null @@ -1,72 +0,0 @@ -require 'test/unit' -require 'axlsx.rb' - -class TestTable < Test::Unit::TestCase - def setup - p = Axlsx::Package.new - @ws = p.workbook.add_worksheet - 40.times do - @ws << ["aa","aa","aa","aa","aa","aa"] - end - end - - def test_initialization - assert(@ws.workbook.tables.empty?) - assert(@ws.tables.empty?) - - end - - def test_add_table - name = "test" - table = @ws.add_table("A1:D5", :name => name) - assert(table.is_a?(Axlsx::Table), "must create a table") - assert_equal(@ws.workbook.tables.last, table, "must be added to workbook table collection") - assert_equal(@ws.tables.last, table, "must be added to worksheet table collection") - assert_equal(table.name, name, "options for name are applied") - - end - - def test_charts - assert(@ws.drawing.charts.empty?) - chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) - assert_equal(@ws.drawing.charts.last, chart, "add chart is returned") - chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10]) - assert_equal(@ws.drawing.charts.last, chart, "add chart is returned") - end - - def test_pn - table = @ws.add_table("A1:D5") - assert_equal(@ws.tables.first.pn, "tables/table1.xml") - end - - def test_rId - table = @ws.add_table("A1:D5") - assert_equal(@ws.tables.first.rId, "rId1") - end - - def test_index - table = @ws.add_table("A1:D5") - assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first)) - end - - def test_relationships - assert(@ws.relationships.empty?) - table = @ws.add_table("A1:D5") - assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship") - table = @ws.add_table("F1:J5") - assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship") - end - - def test_to_xml - table = @ws.add_table("A1:D5") - schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) - doc = Nokogiri::XML(table.to_xml) - errors = [] - schema.validate(doc).each do |error| - errors.push error - puts error.message - end - assert(errors.empty?, "error free validation") - end - -end diff --git a/test/workbook/worksheet/table/tc_table.rb b/test/workbook/worksheet/table/tc_table.rb new file mode 100644 index 00000000..fc29bf66 --- /dev/null +++ b/test/workbook/worksheet/table/tc_table.rb @@ -0,0 +1,71 @@ +require 'tc_helper.rb' + +class TestTable < Test::Unit::TestCase + def setup + p = Axlsx::Package.new + @ws = p.workbook.add_worksheet + 40.times do + @ws << ["aa","aa","aa","aa","aa","aa"] + end + end + + def test_initialization + assert(@ws.workbook.tables.empty?) + assert(@ws.tables.empty?) + + end + + def test_add_table + name = "test" + table = @ws.add_table("A1:D5", :name => name) + assert(table.is_a?(Axlsx::Table), "must create a table") + assert_equal(@ws.workbook.tables.last, table, "must be added to workbook table collection") + assert_equal(@ws.tables.last, table, "must be added to worksheet table collection") + assert_equal(table.name, name, "options for name are applied") + + end + + def test_charts + assert(@ws.drawing.charts.empty?) + chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"bob", :start_at=>[0,0], :end_at=>[1,1]) + assert_equal(@ws.drawing.charts.last, chart, "add chart is returned") + chart = @ws.add_chart(Axlsx::Pie3DChart, :title=>"nancy", :start_at=>[1,5], :end_at=>[5,10]) + assert_equal(@ws.drawing.charts.last, chart, "add chart is returned") + end + + def test_pn + table = @ws.add_table("A1:D5") + assert_equal(@ws.tables.first.pn, "tables/table1.xml") + end + + def test_rId + table = @ws.add_table("A1:D5") + assert_equal(@ws.tables.first.rId, "rId1") + end + + def test_index + table = @ws.add_table("A1:D5") + assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first)) + end + + def test_relationships + assert(@ws.relationships.empty?) + table = @ws.add_table("A1:D5") + assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship") + table = @ws.add_table("F1:J5") + assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship") + end + + def test_to_xml + table = @ws.add_table("A1:D5") + schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) + doc = Nokogiri::XML(table.to_xml) + errors = [] + schema.validate(doc).each do |error| + errors.push error + puts error.message + end + assert(errors.empty?, "error free validation") + end + +end -- cgit v1.2.3