<commit_before># -*- coding: utf-8 -*-

require File.join(File.dirname(__FILE__), './spec_helper')

$VERBOSE = nil

include RobustExcelOle
include General

describe ListObject do
 
  before(:all) do
    excel = Excel.new(:reuse => true)
    open_books = excel == nil ? 0 : excel.Workbooks.Count
    puts "*** open books *** : #{open_books}" if open_books > 0
    Excel.kill_all
  end 

  before do
    @dir = create_tmpdir
    @listobject_file = @dir + '/workbook_listobjects.xlsx'
    @book = Workbook.open(@listobject_file, :visible => true)
    @sheet = @book.sheet(3)
  end

  after do
    @book.close(:if_unsaved => :forget)
    Excel.kill_all
    rm_tmp(@dir)
  end

  describe "creating" do

    context "with standard" do

      it "should simply create a new table" do
        table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amount"])
        table.Name.should == "table_name"
        table.HeaderRowRange.Value.first.should == ["Person","Amount"]
        table.ListRows.Count.should == 3
        @sheet[1,1].Value.should == "Person"
      end

      it "should type-lift a Win32ole list object into a RobustExcelOle list object" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(ole_table)
        table.Name.should == "table3"
        table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
        table.ListRows.Count.should == 6
        @sheet[3,4].Value.should == "Number"
      end

      it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(@sheet, "table3")
        table.Name.should == "table3"
        table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
        table.ListRows.Count.should == 6
        @sheet[3,4].Value.should == "Number"
      end

      it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(@sheet, 1)
        table.Name.should == "table3"
        table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
        table.ListRows.Count.should == 6
        @sheet[3,4].Value.should == "Number"
      end

      it "should simply create a new table from a ole-worksheet" do<commit_msg>test for idempotence<commit_after># -*- coding: utf-8 -*-

require File.join(File.dirname(__FILE__), './spec_helper')

$VERBOSE = nil

include RobustExcelOle
include General

describe ListObject do
 
  before(:all) do
    excel = Excel.new(:reuse => true)
    open_books = excel == nil ? 0 : excel.Workbooks.Count
    puts "*** open books *** : #{open_books}" if open_books > 0
    Excel.kill_all
  end 

  before do
    @dir = create_tmpdir
    @listobject_file = @dir + '/workbook_listobjects.xlsx'
    @book = Workbook.open(@listobject_file, :visible => true)
    @sheet = @book.sheet(3)
  end

  after do
    @book.close(:if_unsaved => :forget)
    Excel.kill_all
    rm_tmp(@dir)
  end

  describe "creating" do

    context "with standard" do

      it "should simply create a new table" do
        table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amount"])
        table.Name.should == "table_name"
        table.HeaderRowRange.Value.first.should == ["Person","Amount"]
        table.ListRows.Count.should == 3
        @sheet[1,1].Value.should == "Person"
      end

      it "should do the idempotence" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(ole_table)
        table2 = Table.new(table)
        table2.ole_table.should be_a WIN32OLE
      end

      it "should type-lift a Win32ole list object into a RobustExcelOle list object" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(ole_table)
        table.Name.should == "table3"
        table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
        table.ListRows.Count.should == 6
        @sheet[3,4].Value.should == "Number"
      end

      it "should type-lift a Win32ole list object into a RobustExcelOle list object with table name" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(@sheet, "table3")
        table.Name.should == "table3"
        table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
        table.ListRows.Count.should == 6
        @sheet[3,4].Value.should == "Number"
      end

      it "should type-lift a Win32ole list object into a RobustExcelOle list object with item number" do
        ole_table = @sheet.ListObjects.Item(1)
        table = Table.new(@sheet, 1)
        table.Name.should == "table3"
        table.HeaderRowRange.Value.first.should == ["Number","Person","Amount","Time","Price"]
        table.ListRows.Count.should == 6
        @sheet[3,4].Value.should == "Number"
      end

      it "should simply create a new table from a ole-worksheet" do
{'fraction_non_alphanumeric': 0.1362365161805833, 'fraction_numerical': 0.01418298042349181, 'mean_word_length': 2.8309104820198927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2232567', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1567, 'n_words': 381}