mirror of
https://github.com/1f349/lotus.git
synced 2024-11-12 23:11:36 +00:00
40 lines
669 B
Go
40 lines
669 B
Go
package config_parser
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
var configParserData = []struct {
|
|
Input string
|
|
Values [][2]string
|
|
}{
|
|
{
|
|
"a = a",
|
|
[][2]string{{"a", "a"}},
|
|
},
|
|
{
|
|
" a = a ",
|
|
[][2]string{{"a", "a"}},
|
|
},
|
|
{
|
|
" # this is a comment\n a = a, b\nb = c, d",
|
|
[][2]string{{"a", "a, b"}, {"b", "c, d"}},
|
|
},
|
|
}
|
|
|
|
func TestConfigParser(t *testing.T) {
|
|
for _, i := range configParserData {
|
|
t.Run(i.Input, func(t *testing.T) {
|
|
a := NewConfigParser(strings.NewReader(i.Input))
|
|
n := 0
|
|
for a.Scan() {
|
|
assert.False(t, n >= len(i.Values))
|
|
assert.Equal(t, i.Values[n], a.pair)
|
|
n++
|
|
}
|
|
})
|
|
}
|
|
}
|