test_sitef.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require 'atto'
  2. include Atto::Test
  3. require_relative '../lib/sitef'
  4. SITEF_NAME = '/tmp/sitef_test.sitef'
  5. SITEF_NAME2 = '/tmp/sitef_test2.sitef'
  6. TEST_DATA = []
  7. TEST_DATA << { :nid => 10, :text => "I'm a 10 text man\nAnd I go on several\nlines." }
  8. TEST_DATA << { :nid => 27, :text => "--\nA tricky text. 3 newlines:\n\n\nSlashes: \n\\\n:nid:27\n\n.text\n.." }
  9. module Foo
  10. class Try
  11. attr_reader :foo
  12. attr_reader :bar
  13. def initialize (h = {})
  14. @foo = h['foo']
  15. @bar = h['bar']
  16. end
  17. def self.from_sitef(h)
  18. self.new(h)
  19. end
  20. end
  21. end
  22. TEST_DATA2 = [ Foo::Try.new('foo' => 1, 'bar' => "Yeah"),
  23. Foo::Try.new('foo' => 1, 'bar' => "Oh")]
  24. assert { Sitef }
  25. assert { Sitef.save_filename(SITEF_NAME, TEST_DATA) }
  26. assert "Loading" do
  27. res, err = Sitef.load_filename(SITEF_NAME)
  28. p res
  29. res && err.empty? && res[0]["nid"] == "10" && res[1]["nid"] == "27"
  30. end
  31. assert "Text round trip" do
  32. res, err = Sitef.load_filename(SITEF_NAME)
  33. to = TEST_DATA[1][:text]
  34. tl = res[1]["text"]
  35. p to, tl
  36. to == tl
  37. end
  38. assert do
  39. Sitef.save_filename(SITEF_NAME2, TEST_DATA2, :foo, :bar)
  40. end
  41. assert do
  42. res, err = Sitef.load_objects(SITEF_NAME2)
  43. p res
  44. res
  45. end