Skip to content

Commit

Permalink
Fix FlattenYaml tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ceritium committed Mar 14, 2024
1 parent 6841e60 commit 03bdb2b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/flatito/flatten_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(pathname)
@pathname = pathname
end

def items
def items
with_line_numbers.compact.flat_map do |line|
flatten_hash(line) if line.is_a?(Hash)
end.compact
Expand Down
84 changes: 42 additions & 42 deletions test/graml/flatten_yaml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,75 @@

class Flatito::FlattenYamlTest < Minitest::Test
test "a json" do
entries = Flatito::FlattenYaml.new("test/fixtures/a.json").entries
items = Flatito::FlattenYaml.new("test/fixtures/a.json").items

assert_equal 5, entries.size
assert_equal "one", entries[0].key
assert_equal "One", entries[0].value
assert_equal 2, entries[0].line
assert_equal 5, items.size
assert_equal "one", items[0].key
assert_equal "One", items[0].value
assert_equal 2, items[0].line
end

test "no nested" do
entries = Flatito::FlattenYaml.new("test/fixtures/no_nested.yml").entries
items = Flatito::FlattenYaml.new("test/fixtures/no_nested.yml").items

assert_equal 3, entries.size
assert_equal "one", entries[0].key
assert_equal "One", entries[0].value
assert_equal 1, entries[0].line
assert_equal 3, items.size
assert_equal "one", items[0].key
assert_equal "One", items[0].value
assert_equal 1, items[0].line
end

test "nested" do
entries = Flatito::FlattenYaml.new("test/fixtures/nested.yml").entries
items = Flatito::FlattenYaml.new("test/fixtures/nested.yml").items

assert_equal 3, entries.size
assert_equal "nested1.one", entries[0].key
assert_equal "One", entries[0].value
assert_equal 2, entries[0].line
assert_equal 3, items.size
assert_equal "nested1.one", items[0].key
assert_equal "One", items[0].value
assert_equal 2, items[0].line

assert_equal "nested1.nested2.two", entries[1].key
assert_equal "Two", entries[1].value
assert_equal 4, entries[1].line
assert_equal "nested1.nested2.two", items[1].key
assert_equal "Two", items[1].value
assert_equal 4, items[1].line

assert_equal "three", entries[2].key
assert_equal "Three", entries[2].value
assert_equal 5, entries[2].line
assert_equal "three", items[2].key
assert_equal "Three", items[2].value
assert_equal 5, items[2].line
end

test "with merging hashes" do
entries = Flatito::FlattenYaml.new("test/fixtures/merge.yml").entries
items = Flatito::FlattenYaml.new("test/fixtures/merge.yml").items

assert_equal 3, entries.size
assert_equal 3, items.size

assert_equal "default.adapter", entries[0].key
assert_equal "postgresql", entries[0].value
assert_equal 2, entries[0].line
assert_equal "default.adapter", items[0].key
assert_equal "postgresql", items[0].value
assert_equal 2, items[0].line

assert_equal "development.database", entries[1].key
assert_equal "keepthissite_development", entries[1].value
assert_equal 4, entries[1].line
assert_equal "development.database", items[1].key
assert_equal "keepthissite_development", items[1].value
assert_equal 4, items[1].line

assert_equal "development.adapter", entries[2].key
assert_equal "postgresql", entries[2].value
assert_equal 2, entries[2].line
assert_equal "development.adapter", items[2].key
assert_equal "postgresql", items[2].value
assert_equal 2, items[2].line
end

test "multiline values" do
entries = Flatito::FlattenYaml.new("test/fixtures/multiline.yml").entries
items = Flatito::FlattenYaml.new("test/fixtures/multiline.yml").items

assert_equal "en.long_message", entries[0].key
assert_equal 2, entries[0].line
assert_equal "en.long_message", items[0].key
assert_equal 2, items[0].line

assert_equal "en.a_sequence", entries[1].key
assert_equal 7, entries[1].line
assert_equal "en.a_sequence", items[1].key
assert_equal 7, items[1].line
end

test "with ruby objects" do
entries = Flatito::FlattenYaml.new("test/fixtures/with_ruby_objects.yml").entries
items = Flatito::FlattenYaml.new("test/fixtures/with_ruby_objects.yml").items

assert_equal 3, entries.size
assert_equal 3, items.size

assert_equal "two", entries[1].key
assert_equal "[object: OpenStruct]", entries[1].value
assert_equal 2, entries[1].line
assert_equal "two", items[1].key
assert_equal "[object: OpenStruct]", items[1].value
assert_equal 2, items[1].line
end
end

0 comments on commit 03bdb2b

Please sign in to comment.