# -*- coding: utf-8 -*- require 'helper' require 'write_xlsx/workbook' require 'write_xlsx/worksheet' require 'stringio' class TestWriteAutofilter < Minitest::Test def setup @workbook = WriteXLSX.new(StringIO.new) end def test_write_auto_filter_with_no_filter worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_East filter = 'x == East' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_East_or_x_North filter = 'x == East or x == North' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_East_and_x_North filter = 'x == East and x == North' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_ne_East filter = 'x != East' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_start_with_S filter = 'x == S*' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_not_start_with_S filter = 'x != S*' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_end_with_h filter = 'x == *h' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_not_end_with_h filter = 'x != *h' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_contains_o filter = 'x =~ *o*' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_not_contains_r filter = 'x !~ *r*' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('A', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_1000 filter = 'x == 1000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_ne_2000 filter = 'x != 2000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_gt_3000 filter = 'x > 3000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_ge_4000 filter = 'x >= 4000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_lt_5000 filter = 'x < 5000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_x_le_6000 filter = 'x <= 6000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_1000_le_x_and_x_le_2000 filter = 'x >= 1000 and x <= 2000' worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column('C', filter) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_matches_East matches = ['East'] worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column_list('A', matches) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_matches_East_and_North matches = ['East', 'North'] worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column_list('A', matches) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end def test_write_auto_filter_with_filter_matches_four_values matches = %w(February January July June) worksheet = @workbook.add_worksheet('Sheet1') worksheet.autofilter('A1:D51') worksheet.filter_column_list('D', matches) worksheet.__send__('write_auto_filter') result = worksheet.instance_variable_get(:@writer).string expected = '' assert_equal(expected, result) end end