From b5d44bf2f3a98bf078f06c674df5b01d5a024978 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 15 May 2015 20:59:33 +0300 Subject: [PATCH] split the tests in to files --- test/helper.rb | 8 +++ test/test_all.rb | 3 ++ test/test_basic.rb | 90 ++++++--------------------------- test/{sof.rb => test_object.rb} | 68 +++++-------------------- 4 files changed, 39 insertions(+), 130 deletions(-) create mode 100644 test/test_all.rb rename test/{sof.rb => test_object.rb} (50%) diff --git a/test/helper.rb b/test/helper.rb index e820498..9bd07db 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -14,3 +14,11 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test')) require 'salama-object-file' + +module Checker + def check should + same = (should == @out) + puts "Shouldda\n#{@out}" unless same + assert_equal should , @out + end +end diff --git a/test/test_all.rb b/test/test_all.rb new file mode 100644 index 0000000..ba5e4d5 --- /dev/null +++ b/test/test_all.rb @@ -0,0 +1,3 @@ +require_relative "test_basic" +require_relative "test_object" +require_relative "test_ext" diff --git a/test/test_basic.rb b/test/test_basic.rb index b1fa264..6ade56f 100644 --- a/test/test_basic.rb +++ b/test/test_basic.rb @@ -1,106 +1,48 @@ require_relative "helper" -require "yaml" - -class ObjectWithAttributes - def initialize - @name = "some name" - @number = 1234 - end - attr_accessor :extra -end -OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)" class BasicSof < MiniTest::Test - def check should - same = (should == @out) - puts "Shouldda\n#{@out}" unless same - assert_equal should , @out - end + include Checker + def test_true @out = Sof::Writer.write(true) - check "true" + check "true" + end + def test_string + @out = Sof::Writer.write("true") + check "'true'" end def test_num @out = Sof::Writer.write(124) - check "124" - end - def test_simple_object - @out = Sof::Writer.write(ObjectWithAttributes.new) - check "#{OBJECT_STRING}" - end - def test_object_extra_array - object = ObjectWithAttributes.new - object.extra = [:sym , 123] - @out = Sof::Writer.write(object) - check "#{OBJECT_STRING}\n :extra [:sym, 123]" + check "124" end def test_simple_array @out = Sof::Writer.write([true, 1234]) - check "[true, 1234]" - end - def test_array_object - @out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new]) - check "-true\n-1234\n-#{OBJECT_STRING}" + check "[true, 1234]" end def test_array_array @out = Sof::Writer.write([true, 1 , [true , 12 ]]) - check "-true\n-1\n-[true, 12]" + check "-true\n-1\n-[true, 12]" end def test_array_array_reverse @out = Sof::Writer.write([ [true , 12 ], true, 1]) - check "-[true, 12]\n-true\n-1" + check "-[true, 12]\n-true\n-1" end def test_array_array_array @out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]]) - check "-true\n-1\n--true\n -12\n -[true, 123]" - end - def test_array_array_object - @out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]]) - check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}" + check "-true\n-1\n--true\n -12\n -[true, 123]" end def test_simple_hash @out = Sof::Writer.write({ one: 1 , tru: true }) - check "{:one => 1, :tru => true}" - end - def test_hash_object - @out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new }) - check "-:one => 1\n-:two => #{OBJECT_STRING}" + check "{:one => 1, :tru => true}" end def test_array_hash @out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }]) - check "-true\n-1\n-{:one => 1, :tru => true}" - end - def test_hash_array - @out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true }) - check "-:one => -1\n -#{OBJECT_STRING}\n-:two => true" + check "-true\n-1\n-{:one => 1, :tru => true}" end def test_array_recursive ar = [true, 1 ] ar << ar @out = Sof::Writer.write(ar) - check "&1 [true, 1, *1]" + check "&1 [true, 1, *1]" end - def test_object_recursive - object = ObjectWithAttributes.new - object.extra = object - @out = Sof::Writer.write(object) - check "&1 ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)" - end - def test_object_inline - object = ObjectWithAttributes.new - object.extra = Object.new - @out = Sof::Writer.write(object) - check "ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => Object())" - end - def test_class - @out = Sof::Writer.write(ObjectWithAttributes) - check "ObjectWithAttributes" - end - def test_class_ref - object = ObjectWithAttributes.new - object.extra = ObjectWithAttributes - ar = [object , ObjectWithAttributes] - @out = Sof::Writer.write(ar) - check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)\n-&1 ObjectWithAttributes" - end -end \ No newline at end of file +end diff --git a/test/sof.rb b/test/test_object.rb similarity index 50% rename from test/sof.rb rename to test/test_object.rb index b1fa264..43f1701 100644 --- a/test/sof.rb +++ b/test/test_object.rb @@ -1,6 +1,3 @@ -require_relative "helper" -require "yaml" - class ObjectWithAttributes def initialize @name = "some name" @@ -10,87 +7,46 @@ class ObjectWithAttributes end OBJECT_STRING = "ObjectWithAttributes(:name => 'some name', :number => 1234)" -class BasicSof < MiniTest::Test - def check should - same = (should == @out) - puts "Shouldda\n#{@out}" unless same - assert_equal should , @out - end - def test_true - @out = Sof::Writer.write(true) - check "true" - end - def test_num - @out = Sof::Writer.write(124) - check "124" - end +class ObjectSof < MiniTest::Test + include Checker + def test_simple_object @out = Sof::Writer.write(ObjectWithAttributes.new) - check "#{OBJECT_STRING}" + check "#{OBJECT_STRING}" end def test_object_extra_array object = ObjectWithAttributes.new object.extra = [:sym , 123] @out = Sof::Writer.write(object) - check "#{OBJECT_STRING}\n :extra [:sym, 123]" - end - def test_simple_array - @out = Sof::Writer.write([true, 1234]) - check "[true, 1234]" + check "#{OBJECT_STRING}\n :extra [:sym, 123]" end def test_array_object @out = Sof::Writer.write([true, 1234 , ObjectWithAttributes.new]) - check "-true\n-1234\n-#{OBJECT_STRING}" - end - def test_array_array - @out = Sof::Writer.write([true, 1 , [true , 12 ]]) - check "-true\n-1\n-[true, 12]" - end - def test_array_array_reverse - @out = Sof::Writer.write([ [true , 12 ], true, 1]) - check "-[true, 12]\n-true\n-1" - end - def test_array_array_array - @out = Sof::Writer.write([true, 1 , [true , 12 , [true , 123 ]]]) - check "-true\n-1\n--true\n -12\n -[true, 123]" + check "-true\n-1234\n-#{OBJECT_STRING}" end def test_array_array_object @out = Sof::Writer.write([true, 1 , [true , 12 , ObjectWithAttributes.new]]) - check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}" - end - def test_simple_hash - @out = Sof::Writer.write({ one: 1 , tru: true }) - check "{:one => 1, :tru => true}" + check "-true\n-1\n--true\n -12\n -#{OBJECT_STRING}" end def test_hash_object @out = Sof::Writer.write({ one: 1 , two: ObjectWithAttributes.new }) - check "-:one => 1\n-:two => #{OBJECT_STRING}" - end - def test_array_hash - @out = Sof::Writer.write([true, 1 , { one: 1 , tru: true }]) - check "-true\n-1\n-{:one => 1, :tru => true}" + check "-:one => 1\n-:two => #{OBJECT_STRING}" end def test_hash_array @out = Sof::Writer.write({ one: [1 , ObjectWithAttributes.new] , two: true }) - check "-:one => -1\n -#{OBJECT_STRING}\n-:two => true" - end - def test_array_recursive - ar = [true, 1 ] - ar << ar - @out = Sof::Writer.write(ar) - check "&1 [true, 1, *1]" + check "-:one => -1\n -#{OBJECT_STRING}\n-:two => true" end def test_object_recursive object = ObjectWithAttributes.new object.extra = object @out = Sof::Writer.write(object) - check "&1 ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)" + check "&1 ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)" end def test_object_inline object = ObjectWithAttributes.new object.extra = Object.new @out = Sof::Writer.write(object) - check "ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => Object())" + check "ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => Object())" end def test_class @out = Sof::Writer.write(ObjectWithAttributes) @@ -103,4 +59,4 @@ class BasicSof < MiniTest::Test @out = Sof::Writer.write(ar) check "-ObjectWithAttributes(:name => 'some name', :number => 1234, :extra => *1)\n-&1 ObjectWithAttributes" end -end \ No newline at end of file +end