Skip to content

Commit

Permalink
Merge pull request #61 from fpringvaldsen/bug/TK-249/bad-comments
Browse files Browse the repository at this point in the history
(TK-249) Remove unnecessary comments in output
  • Loading branch information
jpinsonault committed Jul 14, 2015
2 parents 6b402bc + e893d6f commit be17f2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/hocon/impl/simple_config_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'hocon/impl'
require 'hocon/parser/config_document'
require 'hocon/impl/config_document_parser'
require 'hocon/config_render_options'

class Hocon::Impl::SimpleConfigDocument
include Hocon::Parser::ConfigDocument
Expand All @@ -23,7 +24,9 @@ def set_value(path, new_value)
end

def set_config_value(path, new_value)
set_value(path, new_value.render.strip)
options = Hocon::ConfigRenderOptions.defaults
options.origin_comments = false
set_value(path, new_value.render(options).strip)
end

def remove_value(path)
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/typesafe/config/config_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,15 @@
config_document = ConfigDocumentFactory.parse_string(orig_text)
map_val = ConfigValueFactory.from_any_ref({"a" => 1, "b" => 2})

expect(config_document.set_config_value("a", map_val).render).to eq("a : {\n # hardcoded value\n \"a\" : 1,\n # hardcoded value\n \"b\" : 2\n}")
expect(config_document.set_config_value("a", map_val).render).to eq("a : {\n \"a\" : 1,\n \"b\" : 2\n}")
end

it "should successfully insert an array into an empty document" do
orig_text = ""
config_document = ConfigDocumentFactory.parse_string(orig_text)
array_val = ConfigValueFactory.from_any_ref([1,2])

expect(config_document.set_config_value("a", array_val).render).to eq("a : [\n # hardcoded value\n 1,\n # hardcoded value\n 2\n]")
expect(config_document.set_config_value("a", array_val).render).to eq("a : [\n 1,\n 2\n]")
end
end

Expand All @@ -570,7 +570,7 @@
config_document = ConfigDocumentFactory.parse_string(orig_text)

map = ConfigValueFactory.from_any_ref({"a" => 1, "b" => 2})
expect(config_document.set_config_value("a", map).render).to eq("{ a : {\n # hardcoded value\n \"a\" : 1,\n # hardcoded value\n \"b\" : 2\n } }")
expect(config_document.set_config_value("a", map).render).to eq("{ a : {\n \"a\" : 1,\n \"b\" : 2\n } }")
end
end
end

0 comments on commit be17f2a

Please sign in to comment.