adds simple hash and test

This commit is contained in:
Torsten Ruger 2014-08-15 17:14:49 +03:00
parent 2d6a43cf0e
commit 16261f96b0
3 changed files with 19 additions and 1 deletions

View File

@ -3,6 +3,7 @@ require_relative "members"
require_relative "volotile"
require_relative "writer"
require_relative "array"
require_relative "hash"
require_relative "occurence"
Symbol.class_eval do

13
lib/sof/hash.rb Normal file
View File

@ -0,0 +1,13 @@
Hash.class_eval do
def to_sof(io , members , level)
each_with_index do |pair , i|
key , object = pair
io.write(" " * level) unless i == 0
io.write "-"
members.output( io , key)
io.write( " " )
members.output( io , object)
io.write("\n")
end
end
end

View File

@ -41,5 +41,9 @@ class BasicSof < MiniTest::Test
out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]])
assert_equal "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}\n\n\n" , out
end
def test_simple_hash
out = Sof::Writer.write({ one: 1 , tru: true })
puts out
assert_equal "-:one 1\n-:tru true\n" , out
end
end