# -*- coding: utf-8 -*-
require 'helper'
require 'write_xlsx/chart'
class TestWriteDLbls < Test::Unit::TestCase
def setup
@chart = Writexlsx::Chart.new('Pie')
@series = Writexlsx::Chart::Series.new(@chart)
end
def test_write_d_lbls_value_only
expected = ''
labels = @series.__send__(:labels_properties, :value => 1)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_series_name_only
expected = ''
labels = @series.__send__(:labels_properties, :series_name => 1)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_category_only
expected = ''
labels = @series.__send__(:labels_properties, :category => 1)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_value_category_and_series
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:category => 1,
:series_name => 1
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_center
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'center'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_left
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'left'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_right
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'right'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_top
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'top'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_above
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'above'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_bottom
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'bottom'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_position_below
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:position => 'below'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:leader_lines => 1
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie_position_empty
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:leader_lines => 1,
:position => ''
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie_position_center
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:leader_lines => 1,
:position => 'center'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie_position_inside_end
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:leader_lines => 1,
:position => 'inside_end'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie_position_outside_end
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:leader_lines => 1,
:position => 'outside_end'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie_position_best_fit
expected = ''
labels = @series.__send__(:labels_properties,
{
:value => 1,
:leader_lines => 1,
:position => 'best_fit'
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def test_write_d_lbls_pie_percentage
expected = ''
labels = @series.__send__(:labels_properties,
{
:leader_lines => 1,
:percentage => 1
}
)
@chart.__send__(:write_d_lbls, labels)
result = chart_writer_string
assert_equal(expected, result)
end
def chart_writer_string
@chart.instance_variable_get(:@writer).string
end
end