Skip to content

Commit

Permalink
handle multiple include statements, fixes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
gurkankaymak committed Dec 5, 2022
1 parent b15a24d commit d921461
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (p *parser) extractObject(isSubObject ...bool) (Object, error) {
p.consumeComment()
}

if p.scanner.TokenText() == includeToken {
for p.scanner.TokenText() == includeToken {
p.advance()

includedObject, err := p.parseIncludedResource()
Expand Down
13 changes: 13 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,19 @@ func TestExtractObject(t *testing.T) {
assertDeepEqual(t, got, expected)
})

t.Run("merge multiple included objects with the existing", func(t *testing.T) {
parser := newParser(strings.NewReader(
`c:3
include "testdata/a.conf"
include "testdata/b.conf"
`))
parser.advance()
expected := Object{"a": Int(1), "b": Int(2), "c": Int(3)}
got, err := parser.extractObject()
assertNoError(t, err)
assertDeepEqual(t, got, expected)
})

t.Run("parse correctly if the last line is a comment", func(t *testing.T) {
config := `{
a: 1
Expand Down
1 change: 1 addition & 0 deletions testdata/b.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b:2

0 comments on commit d921461

Please sign in to comment.