# coding: utf-8 require 'test_helper' class Thinreports::Core::Format::TestBuilder < Minitest::Test include Thinreports::TestHelper TEST_RAW_FORMAT = <<-'EOS' { "node1": "あ漢字@㈱Ⅰカナカナ", "node2": { "node2_child":"node2_child value" }, "layout": " " } EOS class TestFormat < Thinreports::Core::Format::Base extend ::Thinreports::Core::Format::Builder config_reader :layout config_accessor :shapes end def setup @raw_format = clean_whitespaces(TEST_RAW_FORMAT) end def test_parse_json expected_format = { "node1" => "あ漢字@㈱Ⅰカナカナ", "node2" => { "node2_child" => "node2_child value" }, "layout" => clean_whitespaces(<<-EOS) EOS } assert_equal TestFormat.parse_json(@raw_format), expected_format end def test_build_layout format = TestFormat.new(TestFormat.parse_json(@raw_format)) format.shapes = {} TestFormat.build_layout(format) do |type, f| Thinreports::Core::Shape::Format(type).build(f) end assert_equal format.layout, clean_whitespaces(<<-'EOS') EOS assert_includes format.shapes.keys, :t1 end def test_clean source = clean_whitespaces(<<-'EOS') EOS TestFormat.clean(source) assert_equal source, clean_whitespaces(<<-'EOS') EOS end def test_clean_with_attributes source = clean_whitespaces(<<-'EOS') EOS TestFormat.clean_with_attributes(source) assert_equal source, clean_whitespaces(<<-'EOS') EOS end def test_shape_tag shape_format = stub(id: :foo) assert_equal TestFormat.shape_tag(shape_format), '<%= r(:"foo")%>' end end