Sha256: 536e774c9a52fc49925e56ed0fd013f831da81bd31316e5769ebe24107022ded

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require "test_helper"
require "cairo"

class PainterTest < Test::Unit::TestCase
  def setup
    @painter = ShogiKoma::Painter.new
  end

  class SetFontTest < self
    def test_found
      part_of_name = "M"
      assert_match(/#{part_of_name}/, @painter.set_font(part_of_name))
    end

    def test_not_found
      part_of_name = "ABCDE12345"
      assert_nil(@painter.set_font(part_of_name))
    end
  end

  class DrawTest < self
    def test_one_character
      assert_nothing_raised_in_draw("A")
    end

    def test_two_characters
      assert_nothing_raised_in_draw("AB")
    end

    def test_three_characters
      assert_nothing_raised_in_draw("ABC")
    end

    def test_body_color_with_rgb
      @painter.set_body_rgb(0.2, 0.2, 0.2)
      assert_nothing_raised_in_draw("D")
    end

    def test_text_color_with_name
      @painter.set_text_color(:deep_pink)
      assert_nothing_raised_in_draw("E")
    end

    def test_text_color_with_hex
      @painter.set_text_color("#ACE")
      assert_nothing_raised_in_draw("G")
    end

    private
    def assert_nothing_raised_in_draw(text)
      width =  200
      height = 200
      assert_nothing_raised do
        Cairo::ImageSurface.new(:argb32, width, height) do |surface|
          Cairo::Context.new(surface) do |context|
            context.scale(width, height)
            @painter.draw(context, text)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shogi_koma-0.0.6 test/painter_test.rb