hocon 1.1.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/CHANGELOG.md +11 -0
- data/HISTORY.md +2016 -0
- data/README.md +123 -0
- data/bin/hocon +5 -0
- data/lib/hocon/cli.rb +225 -0
- data/lib/hocon/config_render_options.rb +3 -2
- data/lib/hocon/impl/abstract_config_value.rb +7 -10
- data/lib/hocon/impl/config_delayed_merge.rb +1 -1
- data/lib/hocon/impl/config_node_object.rb +1 -2
- data/lib/hocon/impl/config_node_root.rb +1 -1
- data/lib/hocon/impl/simple_config_document.rb +1 -1
- data/lib/hocon/version.rb +5 -0
- data/spec/fixtures/parse_render/example1/output.conf +3 -3
- data/spec/test_utils.rb +2 -1
- data/spec/unit/cli/cli_spec.rb +157 -0
- data/spec/unit/typesafe/config/config_document_spec.rb +41 -41
- data/spec/unit/typesafe/config/config_node_spec.rb +12 -12
- data/spec/unit/typesafe/config/config_value_spec.rb +24 -0
- metadata +18 -12
data/spec/test_utils.rb
CHANGED
@@ -12,6 +12,7 @@ require 'hocon/impl/config_node_single_token'
|
|
12
12
|
require 'hocon/impl/config_node_object'
|
13
13
|
require 'hocon/impl/config_node_array'
|
14
14
|
require 'hocon/impl/config_node_concatenation'
|
15
|
+
require 'hocon/cli'
|
15
16
|
|
16
17
|
module TestUtils
|
17
18
|
Tokens = Hocon::Impl::Tokens
|
@@ -427,7 +428,7 @@ module TestUtils
|
|
427
428
|
end
|
428
429
|
|
429
430
|
def self.node_key_value_pair(key, value)
|
430
|
-
nodes = [key,
|
431
|
+
nodes = [key, node_colon, node_space, value]
|
431
432
|
Hocon::Impl::ConfigNodeField.new(nodes)
|
432
433
|
end
|
433
434
|
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'test_utils'
|
5
|
+
|
6
|
+
|
7
|
+
describe Hocon::CLI do
|
8
|
+
####################
|
9
|
+
# Argument Parsing
|
10
|
+
####################
|
11
|
+
context 'argument parsing' do
|
12
|
+
it 'should find all the flags and arguments' do
|
13
|
+
args = %w(-i foo -o bar set some.path some_value --json)
|
14
|
+
expected_options = {
|
15
|
+
in_file: 'foo',
|
16
|
+
out_file: 'bar',
|
17
|
+
subcommand: 'set',
|
18
|
+
path: 'some.path',
|
19
|
+
new_value: 'some_value',
|
20
|
+
json: true
|
21
|
+
}
|
22
|
+
expect(Hocon::CLI.parse_args(args)).to eq(expected_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should set -i and -o to -f if given' do
|
26
|
+
args = %w(-f foo set some.path some_value)
|
27
|
+
expected_options = {
|
28
|
+
file: 'foo',
|
29
|
+
in_file: 'foo',
|
30
|
+
out_file: 'foo',
|
31
|
+
subcommand: 'set',
|
32
|
+
path: 'some.path',
|
33
|
+
new_value: 'some_value'
|
34
|
+
}
|
35
|
+
expect(Hocon::CLI.parse_args(args)).to eq(expected_options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'subcommands' do
|
40
|
+
hocon_text =
|
41
|
+
'foo.bar {
|
42
|
+
baz = 42
|
43
|
+
array = [1, 2, 3]
|
44
|
+
hash: {key: value}
|
45
|
+
}'
|
46
|
+
|
47
|
+
context 'do_get()' do
|
48
|
+
it 'should get simple values' do
|
49
|
+
options = {path: 'foo.bar.baz'}
|
50
|
+
expect(Hocon::CLI.do_get(options, hocon_text)).to eq('42')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should work with arrays' do
|
54
|
+
options = {path: 'foo.bar.array'}
|
55
|
+
expected = "[\n 1,\n 2,\n 3\n]"
|
56
|
+
expect(Hocon::CLI.do_get(options, hocon_text)).to eq(expected)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should work with hashes' do
|
60
|
+
options = {path: 'foo.bar.hash'}
|
61
|
+
expected = "key: value\n"
|
62
|
+
expect(Hocon::CLI.do_get(options, hocon_text)).to eq(expected)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should output json if specified' do
|
66
|
+
options = {path: 'foo.bar.hash', json: true}
|
67
|
+
|
68
|
+
# Note that this is valid json, while the test above is not
|
69
|
+
expected = "{\n \"key\": \"value\"\n}\n"
|
70
|
+
expect(Hocon::CLI.do_get(options, hocon_text)).to eq(expected)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should throw a MissingPathError if the path does not exist' do
|
74
|
+
options = {path: 'not.a.path'}
|
75
|
+
expect {Hocon::CLI.do_get(options, hocon_text)}
|
76
|
+
.to raise_error(Hocon::CLI::MissingPathError)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should throw a MissingPathError if the path leads into an array' do
|
80
|
+
options = {path: 'foo.array.1'}
|
81
|
+
expect {Hocon::CLI.do_get(options, hocon_text)}
|
82
|
+
.to raise_error(Hocon::CLI::MissingPathError)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should throw a MissingPathError if the path leads into a string' do
|
86
|
+
options = {path: 'foo.hash.key.value'}
|
87
|
+
expect {Hocon::CLI.do_get(options, hocon_text)}
|
88
|
+
.to raise_error(Hocon::CLI::MissingPathError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'do_set()' do
|
93
|
+
it 'should overwrite values' do
|
94
|
+
options = {path: 'foo.bar.baz', new_value: 'pi'}
|
95
|
+
expected = hocon_text.sub(/42/, 'pi')
|
96
|
+
expect(Hocon::CLI.do_set(options, hocon_text)).to eq(expected)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should create new nested values' do
|
100
|
+
options = {path: 'new.nested.path', new_value: 'hello'}
|
101
|
+
expected = "new: {\n nested: {\n path: hello\n }\n}"
|
102
|
+
# No config is supplied, so it will need to add new nested hashes
|
103
|
+
expect(Hocon::CLI.do_set(options, '')).to eq(expected)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should allow arrays to be set' do
|
107
|
+
options = {path: 'my_array', new_value: '[1, 2, 3]'}
|
108
|
+
expected = 'my_array: [1, 2, 3]'
|
109
|
+
expect(Hocon::CLI.do_set(options, '')).to eq(expected)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should allow arrays in strings to be set as strings' do
|
113
|
+
options = {path: 'my_array', new_value: '"[1, 2, 3]"'}
|
114
|
+
expected = 'my_array: "[1, 2, 3]"'
|
115
|
+
expect(Hocon::CLI.do_set(options, '')).to eq(expected)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should allow hashes to be set' do
|
119
|
+
do_set_options = {path: 'my_hash', new_value: '{key: value}'}
|
120
|
+
do_set_expected = 'my_hash: {key: value}'
|
121
|
+
do_set_result = Hocon::CLI.do_set(do_set_options, '')
|
122
|
+
expect(do_set_result).to eq(do_set_expected)
|
123
|
+
|
124
|
+
# Make sure it can be parsed again and be seen as a real hash
|
125
|
+
do_get_options = {path: 'my_hash.key'}
|
126
|
+
do_get_expected = 'value'
|
127
|
+
expect(Hocon::CLI.do_get(do_get_options, do_set_result)).to eq(do_get_expected)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should allow hashes to be set as strings' do
|
131
|
+
do_set_options = {path: 'my_hash', new_value: '"{key: value}"'}
|
132
|
+
do_set_expected = 'my_hash: "{key: value}"'
|
133
|
+
do_set_result = Hocon::CLI.do_set(do_set_options, '')
|
134
|
+
expect(do_set_result).to eq(do_set_expected)
|
135
|
+
|
136
|
+
# Make sure it can't be parsed again and be seen as a real hash
|
137
|
+
do_get_options = {path: 'my_hash.key'}
|
138
|
+
expect{Hocon::CLI.do_get(do_get_options, do_set_result)}
|
139
|
+
.to raise_error(Hocon::CLI::MissingPathError)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'do_unset()' do
|
144
|
+
it 'should remove values' do
|
145
|
+
options = {path: 'foo.bar.baz'}
|
146
|
+
expected = hocon_text.sub(/baz = 42/, '')
|
147
|
+
expect(Hocon::CLI.do_unset(options, hocon_text)).to eq(expected)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should throw a MissingPathError if the path does not exist' do
|
151
|
+
options = {path: 'fake.path'}
|
152
|
+
expect{Hocon::CLI.do_unset(options, hocon_text)}
|
153
|
+
.to raise_error(Hocon::CLI::MissingPathError)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -188,7 +188,7 @@ describe "ConfigDocument" do
|
|
188
188
|
it "should add the setting if only a multi-element duplicate exists" do
|
189
189
|
orig_text = "{a.b.c: d}"
|
190
190
|
config_doc = ConfigDocumentFactory.parse_string(orig_text)
|
191
|
-
expect(config_doc.set_value("a", "2").render).to eq("{ a
|
191
|
+
expect(config_doc.set_value("a", "2").render).to eq("{ a: 2}")
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
@@ -198,19 +198,19 @@ describe "ConfigDocument" do
|
|
198
198
|
let (:replace_path) { "\"e\"" }
|
199
199
|
|
200
200
|
context "set a new value in CONF" do
|
201
|
-
let (:final_text) { "{\n\t\"a\":\"b\",\n\t\"c\":\"d\"\n\t\"e\"
|
201
|
+
let (:final_text) { "{\n\t\"a\":\"b\",\n\t\"c\":\"d\"\n\t\"e\": \"f\"\n}" }
|
202
202
|
include_examples "config document replace CONF test"
|
203
203
|
end
|
204
204
|
|
205
205
|
context "set a new value in JSON" do
|
206
|
-
let (:final_text) { "{\n\t\"a\":\"b\",\n\t\"c\":\"d\",\n\t\"e\"
|
206
|
+
let (:final_text) { "{\n\t\"a\":\"b\",\n\t\"c\":\"d\",\n\t\"e\": \"f\"\n}" }
|
207
207
|
include_examples "config document replace JSON test"
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
211
|
context "config document set new value no braces" do
|
212
212
|
let (:orig_text) { "\"a\":\"b\",\n\"c\":\"d\"\n" }
|
213
|
-
let (:final_text) { "\"a\":\"b\",\n\"c\":\"d\"\n\"e\"
|
213
|
+
let (:final_text) { "\"a\":\"b\",\n\"c\":\"d\"\n\"e\": \"f\"\n" }
|
214
214
|
let (:new_value) { "\"f\"" }
|
215
215
|
let (:replace_path) { "\"e\"" }
|
216
216
|
|
@@ -219,7 +219,7 @@ describe "ConfigDocument" do
|
|
219
219
|
|
220
220
|
context "config document set new value multi level CONF" do
|
221
221
|
let (:orig_text) { "a:b\nc:d" }
|
222
|
-
let (:final_text) { "a:b\nc:d\ne
|
222
|
+
let (:final_text) { "a:b\nc:d\ne: {\n f: {\n g: 12\n }\n}" }
|
223
223
|
let (:new_value) { "12" }
|
224
224
|
let (:replace_path) { "e.f.g" }
|
225
225
|
|
@@ -228,7 +228,7 @@ describe "ConfigDocument" do
|
|
228
228
|
|
229
229
|
context "config document set new value multi level JSON" do
|
230
230
|
let (:orig_text) { "{\"a\":\"b\",\n\"c\":\"d\"}" }
|
231
|
-
let (:final_text) { "{\"a\":\"b\",\n\"c\":\"d\",\n \"e\"
|
231
|
+
let (:final_text) { "{\"a\":\"b\",\n\"c\":\"d\",\n \"e\": {\n \"f\": {\n \"g\": 12\n }\n }}" }
|
232
232
|
let (:new_value) { "12" }
|
233
233
|
let (:replace_path) { "e.f.g" }
|
234
234
|
|
@@ -306,10 +306,10 @@ describe "ConfigDocument" do
|
|
306
306
|
|
307
307
|
context "config document remove overridden" do
|
308
308
|
it "should remove all instances of keys even if overridden by a top-level key/value pair" do
|
309
|
-
orig_text = "a { b: 42 }, a.b = 43, a { b: { c: 44 } }, a
|
309
|
+
orig_text = "a { b: 42 }, a.b = 43, a { b: { c: 44 } }, a: 57 "
|
310
310
|
config_doc = ConfigDocumentFactory.parse_string(orig_text)
|
311
311
|
removed = config_doc.remove_value("a.b")
|
312
|
-
expect(removed.render).to eq("a { }, a { }, a
|
312
|
+
expect(removed.render).to eq("a { }, a { }, a: 57 ")
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
@@ -382,37 +382,37 @@ describe "ConfigDocument" do
|
|
382
382
|
it "should properly indent a value in a single-line map" do
|
383
383
|
orig_text = "a { b: c }"
|
384
384
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
385
|
-
expect(config_document.set_value("a.d", "e").render).to eq("a { b: c, d
|
385
|
+
expect(config_document.set_value("a.d", "e").render).to eq("a { b: c, d: e }")
|
386
386
|
end
|
387
387
|
|
388
388
|
it "should properly indent a value in the top-level when it is on a single line" do
|
389
389
|
orig_text = "a { b: c }, d: e"
|
390
390
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
391
|
-
expect(config_document.set_value("f", "g").render).to eq("a { b: c }, d: e, f
|
391
|
+
expect(config_document.set_value("f", "g").render).to eq("a { b: c }, d: e, f: g")
|
392
392
|
end
|
393
393
|
|
394
394
|
it "should not preserve trailing commas" do
|
395
395
|
orig_text = "a { b: c }, d: e,"
|
396
396
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
397
|
-
expect(config_document.set_value("f", "g").render).to eq("a { b: c }, d: e, f
|
397
|
+
expect(config_document.set_value("f", "g").render).to eq("a { b: c }, d: e, f: g")
|
398
398
|
end
|
399
399
|
|
400
400
|
it "should add necessary keys along the path to the value and properly space them" do
|
401
401
|
orig_text = "a { b: c }, d: e,"
|
402
402
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
403
|
-
expect(config_document.set_value("f.g.h", "i").render).to eq("a { b: c }, d: e, f
|
403
|
+
expect(config_document.set_value("f.g.h", "i").render).to eq("a { b: c }, d: e, f: { g: { h: i } }")
|
404
404
|
end
|
405
405
|
|
406
406
|
it "should properly indent keys added to the top-level with curly braces" do
|
407
407
|
orig_text = "{a { b: c }, d: e}"
|
408
408
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
409
|
-
expect(config_document.set_value("f", "g").render).to eq("{a { b: c }, d: e, f
|
409
|
+
expect(config_document.set_value("f", "g").render).to eq("{a { b: c }, d: e, f: g}")
|
410
410
|
end
|
411
411
|
|
412
412
|
it "should add necessary keys along the path to the value and properly space them when the root has braces" do
|
413
413
|
orig_text = "{a { b: c }, d: e}"
|
414
414
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
415
|
-
expect(config_document.set_value("f.g.h", "i").render).to eq("{a { b: c }, d: e, f
|
415
|
+
expect(config_document.set_value("f.g.h", "i").render).to eq("{a { b: c }, d: e, f: { g: { h: i } }}")
|
416
416
|
end
|
417
417
|
end
|
418
418
|
|
@@ -422,11 +422,11 @@ describe "ConfigDocument" do
|
|
422
422
|
let (:config_document) { ConfigDocumentFactory.parse_string(orig_text) }
|
423
423
|
|
424
424
|
it "should properly indent a value in a multi-line map" do
|
425
|
-
expect(config_document.set_value("a.e", "f").render).to eq("a {\n b: c\n e
|
425
|
+
expect(config_document.set_value("a.e", "f").render).to eq("a {\n b: c\n e: f\n}")
|
426
426
|
end
|
427
427
|
|
428
428
|
it "should properly add/indent any necessary objects along the way to the value" do
|
429
|
-
expect(config_document.set_value("a.d.e.f", "g").render).to eq("a {\n b: c\n d
|
429
|
+
expect(config_document.set_value("a.d.e.f", "g").render).to eq("a {\n b: c\n d: {\n e: {\n f: g\n }\n }\n}")
|
430
430
|
end
|
431
431
|
end
|
432
432
|
|
@@ -435,11 +435,11 @@ describe "ConfigDocument" do
|
|
435
435
|
let (:config_document) { ConfigDocumentFactory.parse_string(orig_text) }
|
436
436
|
|
437
437
|
it "should properly indent a value at the root with multiple lines" do
|
438
|
-
expect(config_document.set_value("d", "e").render).to eq("a {\n b: c\n}\nd
|
438
|
+
expect(config_document.set_value("d", "e").render).to eq("a {\n b: c\n}\nd: e\n")
|
439
439
|
end
|
440
440
|
|
441
441
|
it "should properly add/indent any necessary objects along the way to the value" do
|
442
|
-
expect(config_document.set_value("d.e.f", "g").render).to eq("a {\n b: c\n}\nd
|
442
|
+
expect(config_document.set_value("d.e.f", "g").render).to eq("a {\n b: c\n}\nd: {\n e: {\n f: g\n }\n}\n")
|
443
443
|
end
|
444
444
|
end
|
445
445
|
end
|
@@ -448,13 +448,13 @@ describe "ConfigDocument" do
|
|
448
448
|
it "should properly space a new key/value pair in a nested map in a single-line document" do
|
449
449
|
orig_text = "a { b { c { d: e } } }"
|
450
450
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
451
|
-
expect(config_document.set_value("a.b.c.f", "g").render).to eq("a { b { c { d: e, f
|
451
|
+
expect(config_document.set_value("a.b.c.f", "g").render).to eq("a { b { c { d: e, f: g } } }")
|
452
452
|
end
|
453
453
|
|
454
454
|
it "should properly space a new key/value pair in a nested map in a multi-line document" do
|
455
455
|
orig_text = "a {\n b {\n c {\n d: e\n }\n }\n}"
|
456
456
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
457
|
-
expect(config_document.set_value("a.b.c.f", "g").render).to eq("a {\n b {\n c {\n d: e\n f
|
457
|
+
expect(config_document.set_value("a.b.c.f", "g").render).to eq("a {\n b {\n c {\n d: e\n f: g\n }\n }\n}")
|
458
458
|
end
|
459
459
|
end
|
460
460
|
|
@@ -462,13 +462,13 @@ describe "ConfigDocument" do
|
|
462
462
|
it "should properly space a new key/value pair in a single-line empty object" do
|
463
463
|
orig_text = "a { }"
|
464
464
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
465
|
-
expect(config_document.set_value("a.b", "c").render).to eq("a { b
|
465
|
+
expect(config_document.set_value("a.b", "c").render).to eq("a { b: c }")
|
466
466
|
end
|
467
467
|
|
468
468
|
it "should properly indent a new key/value pair in a multi-line empty object" do
|
469
469
|
orig_text = "a {\n b {\n }\n}"
|
470
470
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
471
|
-
expect(config_document.set_value("a.b.c", "d").render).to eq("a {\n b {\n c
|
471
|
+
expect(config_document.set_value("a.b.c", "d").render).to eq("a {\n b {\n c: d\n }\n}")
|
472
472
|
end
|
473
473
|
end
|
474
474
|
|
@@ -478,12 +478,12 @@ describe "ConfigDocument" do
|
|
478
478
|
|
479
479
|
it "should successfully insert and indent a multi-line object" do
|
480
480
|
expect(config_document.set_value("a.b.c.f", "{\n g: h\n i: j\n k: {\n l: m\n }\n}").render
|
481
|
-
).to eq("a {\n b {\n c {\n d: e\n f
|
481
|
+
).to eq("a {\n b {\n c {\n d: e\n f: {\n g: h\n i: j\n k: {\n l: m\n }\n }\n }\n }\n}")
|
482
482
|
end
|
483
483
|
|
484
484
|
it "should successfully insert a concatenation with a multi-line array" do
|
485
485
|
expect(config_document.set_value("a.b.c.f", "12 13 [1,\n2,\n3,\n{\n a:b\n}]").render
|
486
|
-
).to eq("a {\n b {\n c {\n d: e\n f
|
486
|
+
).to eq("a {\n b {\n c {\n d: e\n f: 12 13 [1,\n 2,\n 3,\n {\n a:b\n }]\n }\n }\n}")
|
487
487
|
end
|
488
488
|
end
|
489
489
|
|
@@ -491,7 +491,7 @@ describe "ConfigDocument" do
|
|
491
491
|
it "should get weird indentation when adding a multi-line value to a single-line object" do
|
492
492
|
orig_text = "a { b { } }"
|
493
493
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
494
|
-
expect(config_document.set_value("a.b.c", "{\n c:d\n}").render).to eq("a { b { c
|
494
|
+
expect(config_document.set_value("a.b.c", "{\n c:d\n}").render).to eq("a { b { c: {\n c:d\n } } }")
|
495
495
|
end
|
496
496
|
end
|
497
497
|
|
@@ -499,38 +499,38 @@ describe "ConfigDocument" do
|
|
499
499
|
it "should treat an object with no new-lines outside of its values as a single-line object" do
|
500
500
|
orig_text = "a { b {\n c: d\n} }"
|
501
501
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
502
|
-
expect(config_document.set_value("a.e", "f").render).to eq("a { b {\n c: d\n}, e
|
502
|
+
expect(config_document.set_value("a.e", "f").render).to eq("a { b {\n c: d\n}, e: f }")
|
503
503
|
end
|
504
504
|
end
|
505
505
|
|
506
506
|
context "config document indentation replacing with multi line value" do
|
507
507
|
it "should properly indent a multi-line value when replacing a single-line value" do
|
508
|
-
orig_text = "a {\n b {\n c
|
508
|
+
orig_text = "a {\n b {\n c: 22\n }\n}"
|
509
509
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
510
|
-
expect(config_document.set_value("a.b.c", "{\n d:e\n}").render).to eq("a {\n b {\n c
|
510
|
+
expect(config_document.set_value("a.b.c", "{\n d:e\n}").render).to eq("a {\n b {\n c: {\n d:e\n }\n }\n}")
|
511
511
|
end
|
512
512
|
|
513
513
|
it "should properly indent a multi-line value when replacing a single-line value in an object with multiple keys" do
|
514
|
-
orig_text = "a {\n b {\n f
|
514
|
+
orig_text = "a {\n b {\n f: 10\n c: 22\n }\n}"
|
515
515
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
516
|
-
expect(config_document.set_value("a.b.c", "{\n d:e\n}").render).to eq("a {\n b {\n f
|
516
|
+
expect(config_document.set_value("a.b.c", "{\n d:e\n}").render).to eq("a {\n b {\n f: 10\n c: {\n d:e\n }\n }\n}")
|
517
517
|
end
|
518
518
|
end
|
519
519
|
|
520
520
|
context "config document indentation value with include" do
|
521
521
|
it "should indent an include node" do
|
522
|
-
orig_text = "a {\n b {\n c
|
522
|
+
orig_text = "a {\n b {\n c: 22\n }\n}"
|
523
523
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
524
524
|
expect(config_document.set_value("a.b.d", "{\n include \"foo\"\n e:f\n}").render
|
525
|
-
).to eq("a {\n b {\n c
|
525
|
+
).to eq("a {\n b {\n c: 22\n d: {\n include \"foo\"\n e:f\n }\n }\n}")
|
526
526
|
end
|
527
527
|
end
|
528
528
|
|
529
529
|
context "config document indentation based on include node" do
|
530
530
|
it "should indent properly when only an include node is present in the object in which the value is inserted" do
|
531
|
-
orig_text = "a
|
531
|
+
orig_text = "a: b\n include \"foo\"\n"
|
532
532
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
533
|
-
expect(config_document.set_value("c", "d").render).to eq("a
|
533
|
+
expect(config_document.set_value("c", "d").render).to eq("a: b\n include \"foo\"\n c: d\n")
|
534
534
|
end
|
535
535
|
end
|
536
536
|
|
@@ -538,13 +538,13 @@ describe "ConfigDocument" do
|
|
538
538
|
it "should successfully insert a value into an empty document" do
|
539
539
|
orig_text = ""
|
540
540
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
541
|
-
expect(config_document.set_value("a", "1").render).to eq("a
|
541
|
+
expect(config_document.set_value("a", "1").render).to eq("a: 1")
|
542
542
|
end
|
543
543
|
|
544
544
|
it "should successfully insert a multi-line object into an empty document" do
|
545
545
|
orig_text = ""
|
546
546
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
547
|
-
expect(config_document.set_value("a.b", "1").render).to eq("a
|
547
|
+
expect(config_document.set_value("a.b", "1").render).to eq("a: {\n b: 1\n}")
|
548
548
|
end
|
549
549
|
|
550
550
|
it "should successfully insert a hash into an empty document" do
|
@@ -552,7 +552,7 @@ describe "ConfigDocument" do
|
|
552
552
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
553
553
|
map_val = ConfigValueFactory.from_any_ref({"a" => 1, "b" => 2})
|
554
554
|
|
555
|
-
expect(config_document.set_config_value("a", map_val).render).to eq("a
|
555
|
+
expect(config_document.set_config_value("a", map_val).render).to eq("a: {\n \"a\": 1,\n \"b\": 2\n}")
|
556
556
|
end
|
557
557
|
|
558
558
|
it "should successfully insert an array into an empty document" do
|
@@ -560,17 +560,17 @@ describe "ConfigDocument" do
|
|
560
560
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
561
561
|
array_val = ConfigValueFactory.from_any_ref([1,2])
|
562
562
|
|
563
|
-
expect(config_document.set_config_value("a", array_val).render).to eq("a
|
563
|
+
expect(config_document.set_config_value("a", array_val).render).to eq("a: [\n 1,\n 2\n]")
|
564
564
|
end
|
565
565
|
end
|
566
566
|
|
567
567
|
context "can insert a map parsed with ConfigValueFactory" do
|
568
568
|
it "should successfully insert a map into a document" do
|
569
|
-
orig_text = "{ a
|
569
|
+
orig_text = "{ a: b }"
|
570
570
|
config_document = ConfigDocumentFactory.parse_string(orig_text)
|
571
571
|
|
572
572
|
map = ConfigValueFactory.from_any_ref({"a" => 1, "b" => 2})
|
573
|
-
expect(config_document.set_config_value("a", map).render).to eq("{ a
|
573
|
+
expect(config_document.set_config_value("a", map).render).to eq("{ a: {\n \"a\": 1,\n \"b\": 2\n } }")
|
574
574
|
end
|
575
575
|
end
|
576
|
-
end
|
576
|
+
end
|