Permalink
Browse files

add a newline between entries if one is missing

closes #13
  • Loading branch information...
1 parent 7868ee1 commit 06b67bfe986ddbb0ad52513e9451fe472fe194f4 @geemus geemus committed Aug 15, 2012
Showing with 27 additions and 1 deletion.
  1. +4 −0 data/newlineless.netrc
  2. +8 −1 lib/netrc.rb
  3. +15 −0 test/test_netrc.rb
View
@@ -0,0 +1,4 @@
+# this is my netrc
+machine m
+ login l # this is my username
+ password p
View
@@ -181,7 +181,14 @@ def save
end
def unparse
- @pre + @data.map(&:join).join
+ @pre + @data.map do |datum|
+ datum = datum.join
+ unless datum[-1..-1] == "\n"
+ datum << "\n"
+ else
+ datum
+ end
+ end.join
end
end
View
@@ -114,6 +114,21 @@ def test_add
assert_equal(exp, n.unparse)
end
+ def test_add_newlineless
+ n = Netrc.read("data/newlineless.netrc")
+ n.new_item_prefix = "# added\n"
+ n["x"] = "a", "b"
+ exp = "# this is my netrc\n"+
+ "machine m\n"+
+ " login l # this is my username\n"+
+ " password p\n"+
+ "# added\n"+
+ "machine x\n"+
+ " login a\n"+
+ " password b\n"
+ assert_equal(exp, n.unparse)
+ end
+
def test_add_get
n = Netrc.read("data/sample.netrc")
n.new_item_prefix = "# added\n"

0 comments on commit 06b67bf

Please sign in to comment.