Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty section means back to global #10

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ on:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
go-version: 1.22
- name: Lint
run: go vet ./...
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion tinyini.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Pair struct {
}

var matchercomment = regexp.MustCompile(`^\s*;`)
var matchersection = regexp.MustCompile(`^\s*\[(.+?)\]`)
var matchersection = regexp.MustCompile(`^\s*\[(.*?)\]`)
var matcherkeyval = regexp.MustCompile(`^\s*(.+?)\s*=\s*(.*?)\s*(;.*)?$`)
var matcherkeyvalq = regexp.MustCompile(`^\s*(.+?)\s*=\s*"((\\.|[^"\\])*)"\s*(;.*)?$`)
var matcherempty = regexp.MustCompile(`^\s*$`)
Expand Down
35 changes: 35 additions & 0 deletions tinyini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,41 @@ section2var=notseen
})
}

func TestEmptySection(t *testing.T) {
config := `
main1 = value1

[section]
subkey=subval

[]
main2=value2

[another-section]
another-key=another-value
`
sections, errs := ti.Parse(strings.NewReader(config))
if len(errs) != 0 {
t.Error(errs)
}
if !reflect.DeepEqual(
sections,
ti.Sections{
"": ti.Section{
"main1": []ti.Pair{ti.Pair{"value1", 2}},
"main2": []ti.Pair{ti.Pair{"value2", 8}},
},
"section": ti.Section{
"subkey": []ti.Pair{ti.Pair{"subval", 5}},
},
"another-section": ti.Section{
"another-key": []ti.Pair{ti.Pair{"another-value", 11}},
},
}) {
t.Errorf("bad values, got %#v", sections)
}
}

func ExampleSections() {
config := `
value=123
Expand Down
Loading