Skip to content

Commit 6ddb3bd

Browse files
committed
Dumped file content should end with newline
1 parent bac90d0 commit 6ddb3bd

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

lib/nestedtext/encode.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module NestedText
99
# @param obj [Object] The object to encode to NestedText.
1010
# @param io [IO] Additionally write the output to this IO object.
1111
# The caller is responsible for that the IO is closed after the call to this method.
12+
# The file willl end with a newline.
1213
# @param indentation [Integer] The indentation of nested levels to use.
1314
# @param strict [Boolean] If strict mode should be used.
1415
#
@@ -21,7 +22,7 @@ def self.dump(obj, io: nil, indentation: 4, strict: false)
2122
dumper = Dumper.new(indentation, strict)
2223
result = dumper.dump obj
2324
unless io.nil?
24-
io.write(result)
25+
io.write(result, "\n")
2526
io.fsync
2627
end
2728
dumper.dump obj

test/fixtures/1.nt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
one:
2-
two: 3
2+
two: 3

test/nestedtext/core_ext_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def test_to_nt_io_param
3636
sio = StringIO.new
3737
dumped = obj.to_nt(io: sio)
3838
assert_equal exp, dumped
39-
assert_equal exp, sio.string
39+
assert_equal "#{exp}\n", sio.string
4040
end
4141
end

test/nestedtext/encode_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def test_io_dump_file
727727

728728
dumped = NestedText.dump_file(obj, @file.path)
729729
assert_equal exp, dumped
730-
assert_equal exp, file_content
730+
assert_equal "#{exp}\n", file_content
731731
end
732732

733733
def test_io_dump_io_param_file
@@ -736,7 +736,7 @@ def test_io_dump_io_param_file
736736

737737
dumped = NestedText.dump(obj, io: @file)
738738
assert_equal exp, dumped
739-
assert_equal exp, file_content
739+
assert_equal "#{exp}\n", file_content
740740
end
741741

742742
def test_io_dump_io_param_stringio
@@ -746,7 +746,7 @@ def test_io_dump_io_param_stringio
746746
sio = StringIO.new
747747
dumped = NestedText.dump(obj, io: sio)
748748
assert_equal exp, dumped
749-
assert_equal exp, sio.string
749+
assert_equal "#{exp}\n", sio.string
750750
end
751751

752752
def test_io_dump_invalid_io_array

0 commit comments

Comments
 (0)