Sha256: a2e7f79cc342f40331d4ff45e782fb0f4ada7957a78b35c1e21d98ded96de97f

Contents?: true

Size: 1.89 KB

Versions: 20

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

# Copyright (c) 2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'minitest/autorun'
require 'loog'
require_relative '../../lib/factbase'
require_relative '../../lib/factbase/to_yaml'

# Test.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
# License:: MIT
class TestToYAML < Minitest::Test
  def test_simple_rendering
    fb = Factbase.new
    f = fb.insert
    f._id = 1
    f.foo = 42
    f.foo = 256
    fb.insert._id = 2
    to = Factbase::ToYAML.new(fb)
    yaml = YAML.load(to.yaml)
    assert_equal(2, yaml.size)
    assert_equal(42, yaml[0]['foo'][0])
    assert_equal(256, yaml[0]['foo'][1])
  end

  def test_sorts_keys
    fb = Factbase.new
    f = fb.insert
    f.b = 42
    f.a = 256
    f.c = 10
    yaml = Factbase::ToYAML.new(fb).yaml
    assert(yaml.include?("a: 256\n  b: 42\n  c: 10"), yaml)
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
factbase-0.4.0 test/factbase/test_to_yaml.rb
factbase-0.3.0 test/factbase/test_to_yaml.rb
factbase-0.2.1 test/factbase/test_to_yaml.rb
factbase-0.2.0 test/factbase/test_to_yaml.rb
factbase-0.1.1 test/factbase/test_to_yaml.rb
factbase-0.1.0 test/factbase/test_to_yaml.rb
factbase-0.0.60 test/factbase/test_to_yaml.rb
factbase-0.0.59 test/factbase/test_to_yaml.rb
factbase-0.0.58 test/factbase/test_to_yaml.rb
factbase-0.0.57 test/factbase/test_to_yaml.rb
factbase-0.0.56 test/factbase/test_to_yaml.rb
factbase-0.0.55 test/factbase/test_to_yaml.rb
factbase-0.0.54 test/factbase/test_to_yaml.rb
factbase-0.0.53 test/factbase/test_to_yaml.rb
factbase-0.0.52 test/factbase/test_to_yaml.rb
factbase-0.0.51 test/factbase/test_to_yaml.rb
factbase-0.0.50 test/factbase/test_to_yaml.rb
factbase-0.0.49 test/factbase/test_to_yaml.rb
factbase-0.0.48 test/factbase/test_to_yaml.rb
factbase-0.0.47 test/factbase/test_to_yaml.rb