update dependencies
This commit is contained in:
parent
fce1b99683
commit
397e9c0842
164 changed files with 5207 additions and 2213 deletions
85
vendor/github.com/pelletier/go-toml/tomltree_write_test.go
generated
vendored
85
vendor/github.com/pelletier/go-toml/tomltree_write_test.go
generated
vendored
|
|
@ -16,26 +16,26 @@ type failingWriter struct {
|
|||
buffer bytes.Buffer
|
||||
}
|
||||
|
||||
func (f failingWriter) Write(p []byte) (n int, err error) {
|
||||
func (f *failingWriter) Write(p []byte) (n int, err error) {
|
||||
count := len(p)
|
||||
toWrite := f.failAt - count + f.written
|
||||
toWrite := f.failAt - (count + f.written)
|
||||
if toWrite < 0 {
|
||||
toWrite = 0
|
||||
}
|
||||
if toWrite > count {
|
||||
f.written += count
|
||||
f.buffer.WriteString(string(p))
|
||||
f.buffer.Write(p)
|
||||
return count, nil
|
||||
}
|
||||
|
||||
f.buffer.WriteString(string(p[:toWrite]))
|
||||
f.buffer.Write(p[:toWrite])
|
||||
f.written = f.failAt
|
||||
return f.written, fmt.Errorf("failingWriter failed after writting %d bytes", f.written)
|
||||
return toWrite, fmt.Errorf("failingWriter failed after writting %d bytes", f.written)
|
||||
}
|
||||
|
||||
func assertErrorString(t *testing.T, expected string, err error) {
|
||||
expectedErr := errors.New(expected)
|
||||
if err.Error() != expectedErr.Error() {
|
||||
if err == nil || err.Error() != expectedErr.Error() {
|
||||
t.Errorf("expecting error %s, but got %s instead", expected, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ func TestTreeWriteToInvalidTreeTomlValueArray(t *testing.T) {
|
|||
func TestTreeWriteToFailingWriterInSimpleValue(t *testing.T) {
|
||||
toml, _ := Load(`a = 2`)
|
||||
writer := failingWriter{failAt: 0, written: 0}
|
||||
_, err := toml.WriteTo(writer)
|
||||
_, err := toml.WriteTo(&writer)
|
||||
assertErrorString(t, "failingWriter failed after writting 0 bytes", err)
|
||||
}
|
||||
|
||||
|
|
@ -184,11 +184,11 @@ func TestTreeWriteToFailingWriterInTable(t *testing.T) {
|
|||
[b]
|
||||
a = 2`)
|
||||
writer := failingWriter{failAt: 2, written: 0}
|
||||
_, err := toml.WriteTo(writer)
|
||||
_, err := toml.WriteTo(&writer)
|
||||
assertErrorString(t, "failingWriter failed after writting 2 bytes", err)
|
||||
|
||||
writer = failingWriter{failAt: 13, written: 0}
|
||||
_, err = toml.WriteTo(writer)
|
||||
_, err = toml.WriteTo(&writer)
|
||||
assertErrorString(t, "failingWriter failed after writting 13 bytes", err)
|
||||
}
|
||||
|
||||
|
|
@ -197,11 +197,11 @@ func TestTreeWriteToFailingWriterInArray(t *testing.T) {
|
|||
[[b]]
|
||||
a = 2`)
|
||||
writer := failingWriter{failAt: 2, written: 0}
|
||||
_, err := toml.WriteTo(writer)
|
||||
_, err := toml.WriteTo(&writer)
|
||||
assertErrorString(t, "failingWriter failed after writting 2 bytes", err)
|
||||
|
||||
writer = failingWriter{failAt: 15, written: 0}
|
||||
_, err = toml.WriteTo(writer)
|
||||
_, err = toml.WriteTo(&writer)
|
||||
assertErrorString(t, "failingWriter failed after writting 15 bytes", err)
|
||||
}
|
||||
|
||||
|
|
@ -293,3 +293,66 @@ func TestTreeWriteToMapWithArrayOfInlineTables(t *testing.T) {
|
|||
treeMap := tree.ToMap()
|
||||
testMaps(t, treeMap, expected)
|
||||
}
|
||||
|
||||
func TestTreeWriteToFloat(t *testing.T) {
|
||||
tree, err := Load(`a = 3.0`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
str, err := tree.ToTomlString()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expected := `a = 3.0`
|
||||
if strings.TrimSpace(str) != strings.TrimSpace(expected) {
|
||||
t.Fatalf("Expected:\n%s\nGot:\n%s", expected, str)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTreeToTomlString(b *testing.B) {
|
||||
toml, err := Load(sampleHard)
|
||||
if err != nil {
|
||||
b.Fatal("Unexpected error:", err)
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := toml.ToTomlString()
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sampleHard = `# Test file for TOML
|
||||
# Only this one tries to emulate a TOML file written by a user of the kind of parser writers probably hate
|
||||
# This part you'll really hate
|
||||
|
||||
[the]
|
||||
test_string = "You'll hate me after this - #" # " Annoying, isn't it?
|
||||
|
||||
[the.hard]
|
||||
test_array = [ "] ", " # "] # ] There you go, parse this!
|
||||
test_array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ]
|
||||
# You didn't think it'd as easy as chucking out the last #, did you?
|
||||
another_test_string = " Same thing, but with a string #"
|
||||
harder_test_string = " And when \"'s are in the string, along with # \"" # "and comments are there too"
|
||||
# Things will get harder
|
||||
|
||||
[the.hard."bit#"]
|
||||
"what?" = "You don't think some user won't do that?"
|
||||
multi_line_array = [
|
||||
"]",
|
||||
# ] Oh yes I did
|
||||
]
|
||||
|
||||
# Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
|
||||
|
||||
#[error] if you didn't catch this, your parser is broken
|
||||
#string = "Anything other than tabs, spaces and newline after a keygroup or key value pair has ended should produce an error unless it is a comment" like this
|
||||
#array = [
|
||||
# "This might most likely happen in multiline arrays",
|
||||
# Like here,
|
||||
# "or here,
|
||||
# and here"
|
||||
# ] End of array comment, forgot the #
|
||||
#number = 3.14 pi <--again forgot the # `
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue