Sha256: a1af5553637b7a844d148f9fb76b164853d17dcbd51c74f1c6574d9f28c2932a

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

# -*- encoding : utf-8 -*-
require File.join(File.dirname(__FILE__), 'helper')

class TestColumn < Minitest::Test

  def new_table
    Workbook::Table.new([
        ["a","b","c","d"],
        [true,3.2,"asdf",1],
        [true,3.2,"asdf",1],
        [false,3.2,"asdf",1],
        [true,3.2,"asdf",1]
      ])
  end

  def test_init
    c = Workbook::Column.new
    assert_equal(Workbook::Column, c.class)
    c = Workbook::Column.new(nil, {:limit=>20,:default=>"asdf", :column_type=>:boolean})
    c = Workbook::Column.new(Workbook::Table.new, {:limit=>20,:default=>"asdf", :column_type=>:boolean})
    assert_equal(20, c.limit)
    assert_equal(Workbook::Cell.new("asdf"), c.default)
    assert_equal(:boolean, c.column_type)
    assert_raises(ArgumentError) { Workbook::Column.new(true) }
    assert_raises(ArgumentError) { Workbook::Column.new(nil, {:limit=>20,:default=>"asdf", :column_type=>:bodfolean}) }
  end

  def test_table
    c = Workbook::Column.new
    c.table = Workbook::Table.new
    assert_equal(Workbook::Table.new, c.table)
    assert_raises(ArgumentError) { c.table = false }
  end

  def test_index
    t = new_table
    assert_equal(t.columns.first.index, 0)
    assert_equal(t.columns.last.index, 3)
  end

  def test_column_type
    t = new_table
    assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
    t = new_table
    t.last.last.value = 1.1
    assert_equal([:boolean, :float, :string, :string], t.columns.collect{|a| a.column_type})
    t = new_table
    t[2][3] = nil
    assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
    t = new_table
    t[2].delete_at(3)
    assert_equal([:boolean, :float, :string, :integer], t.columns.collect{|a| a.column_type})
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
workbook-0.6 test/test_column.rb
workbook-0.5 test/test_column.rb
workbook-0.4.14 test/test_column.rb
workbook-0.4.13 test/test_column.rb
workbook-0.4.12 test/test_column.rb
workbook-0.4.11 test/test_column.rb
workbook-0.4.10 test/test_column.rb