From ad91c0a4bf8c31925f4c64f056ce12a2c833bb4f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 8 Dec 2016 12:48:08 +0200 Subject: [PATCH] add inspect method to dictionary --- lib/typed/parfait/dictionary.rb | 8 ++++++++ test/typed/parfait/test_dictionary.rb | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/typed/parfait/dictionary.rb b/lib/typed/parfait/dictionary.rb index 5278ab38..abdfeba7 100644 --- a/lib/typed/parfait/dictionary.rb +++ b/lib/typed/parfait/dictionary.rb @@ -84,6 +84,14 @@ module Parfait self end + def inspect + string = "Dictionary{" + each do |key , value| + string += key.to_s + " => " + value.to_s + " ," + end + string + "}" + end + def to_sof_node(writer , level , ref) Sof.hash_to_sof_node( self , writer , level , ref) end diff --git a/test/typed/parfait/test_dictionary.rb b/test/typed/parfait/test_dictionary.rb index 03080e91..92808ef0 100644 --- a/test/typed/parfait/test_dictionary.rb +++ b/test/typed/parfait/test_dictionary.rb @@ -30,6 +30,15 @@ class TestDictionary < MiniTest::Test test_one_set2 assert_equal :some , @lookup.get(1) end + def test_inspect1 + @lookup[:key] = :value + assert_equal "Dictionary{key => value ,}" , @lookup.inspect + end + def test_inspect2 + @lookup[:key1] = :value1 + @lookup[:key2] = :value2 + assert_equal "Dictionary{key1 => value1 ,key2 => value2 ,}" , @lookup.inspect + end def test_many_get shouldda = { :one => 1 , :two => 2 , :three => 3} shouldda.each do |k,v|