From c8fdfeedeac4db5fbb4f2dbbc4833b3f03dbe0f0 Mon Sep 17 00:00:00 2001 From: kwatch Date: Sat, 19 Nov 2016 12:52:47 +0900 Subject: [PATCH] feat(psych): add another test case --- test/psych/visitors/test_custom_class.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/psych/visitors/test_custom_class.rb b/test/psych/visitors/test_custom_class.rb index cf623ab..5ac8aec 100644 --- a/test/psych/visitors/test_custom_class.rb +++ b/test/psych/visitors/test_custom_class.rb @@ -61,6 +61,38 @@ def method_missing(method, *args) assert_equal "F", team.members[0].gender end + def test_merge_mapping + input = <<-END + column-defaults: + - &id + name : id + type : int + pkey : true + tables: + - name : admin_users + columns: + - <<: *id + name: user_id + END + # + classmap = { + "tables" => Struct.new('Table', 'name', 'columns'), + "columns" => Struct.new('Column', 'name', 'type', 'pkey', 'required'), + } + # + visitor = Psych::Visitors::CustomClassVisitor.create(classmap) + tree = Psych.parse(input) + ydoc = visitor.accept(tree) + # + assert_kind_of classmap["tables"], ydoc['tables'][0] + assert_kind_of classmap["columns"], ydoc['tables'][0]['columns'][0] + # + table = ydoc['tables'][0] + assert_equal "int", table.columns[0].type # merged + assert_equal true, table.columns[0].pkey # merged + assert_equal "user_id", table.columns[0].name # ovrerwritten + end + end end end -- 2.9.3 (Apple Git-75)