Sha256: c87ac3286576a4b457879ba1fe50b9fd825124893438f9ce8497292c2d6916f3

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

require 'psych/helper'

module Psych
  class TestMergeKeys < TestCase
    def test_missing_merge_key
      yaml = <<-eoyml
bar:
  << : *foo
      eoyml
      exp = assert_raises(Psych::BadAlias) { Psych.load yaml }
      assert_match 'foo', exp.message
    end

    # [ruby-core:34679]
    def test_merge_key
      yaml = <<-eoyml
foo: &foo
  hello: world
bar:
  << : *foo
  baz: boo
      eoyml

      hash = {
        "foo" => { "hello" => "world"},
        "bar" => { "hello" => "world", "baz" => "boo" } }
      assert_equal hash, Psych.load(yaml)
    end

    def test_multiple_maps
      yaml = <<-eoyaml
---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }

# All the following maps are equal:

- # Merge multiple maps
  << : [ *CENTER, *BIG ]
  label: center/big
      eoyaml

      hash = {
        'x' => 1,
        'y' => 2,
        'r' => 10,
        'label' => 'center/big'
      }

      assert_equal hash, Psych.load(yaml)[4]
    end

    def test_override
      yaml = <<-eoyaml
---
- &CENTER { x: 1, y: 2 }
- &LEFT { x: 0, y: 2 }
- &BIG { r: 10 }
- &SMALL { r: 1 }

# All the following maps are equal:

- # Override
  << : [ *BIG, *LEFT, *SMALL ]
  x: 1
  label: center/big
      eoyaml

      hash = {
        'x' => 1,
        'y' => 2,
        'r' => 10,
        'label' => 'center/big'
      }

      assert_equal hash, Psych.load(yaml)[4]
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
psych-1.3.4 test/psych/test_merge_keys.rb
psych-1.3.3 test/psych/test_merge_keys.rb
psych-1.3.2 test/psych/test_merge_keys.rb
psych-1.3.1 test/psych/test_merge_keys.rb
psych-1.3.0 test/psych/test_merge_keys.rb
psych-1.2.2 test/psych/test_merge_keys.rb
psych-1.2.2.rc1 test/psych/test_merge_keys.rb
psych-1.2.1 test/psych/test_merge_keys.rb