Upgrading server dependancies (#8154)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8d66523ba7
Коммит
961c04cae9
4
vendor/github.com/pelletier/go-toml/.travis.yml
сгенерированный
поставляемый
4
vendor/github.com/pelletier/go-toml/.travis.yml
сгенерированный
поставляемый
@@ -1,8 +1,8 @@
|
||||
sudo: false
|
||||
language: go
|
||||
go:
|
||||
- 1.8.4
|
||||
- 1.9.1
|
||||
- 1.8.5
|
||||
- 1.9.2
|
||||
- tip
|
||||
matrix:
|
||||
allow_failures:
|
||||
|
||||
104
vendor/github.com/pelletier/go-toml/keysparsing.go
сгенерированный
поставляемый
104
vendor/github.com/pelletier/go-toml/keysparsing.go
сгенерированный
поставляемый
@@ -6,36 +6,16 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var escapeSequenceMap = map[rune]rune{
|
||||
'b': '\b',
|
||||
't': '\t',
|
||||
'n': '\n',
|
||||
'f': '\f',
|
||||
'r': '\r',
|
||||
'"': '"',
|
||||
'\\': '\\',
|
||||
}
|
||||
|
||||
type parseKeyState int
|
||||
|
||||
const (
|
||||
bare parseKeyState = iota
|
||||
basic
|
||||
literal
|
||||
esc
|
||||
unicode4
|
||||
unicode8
|
||||
)
|
||||
|
||||
// Convert the bare key group string to an array.
|
||||
// The input supports double quotation to allow "." inside the key name,
|
||||
// but escape sequences are not supported. Lexers must unescape them beforehand.
|
||||
func parseKey(key string) ([]string, error) {
|
||||
groups := []string{}
|
||||
var buffer bytes.Buffer
|
||||
var hex bytes.Buffer
|
||||
state := bare
|
||||
inQuotes := false
|
||||
wasInQuotes := false
|
||||
ignoreSpace := true
|
||||
expectDot := false
|
||||
@@ -47,67 +27,17 @@ func parseKey(key string) ([]string, error) {
|
||||
}
|
||||
ignoreSpace = false
|
||||
}
|
||||
|
||||
if state == esc {
|
||||
if char == 'u' {
|
||||
state = unicode4
|
||||
hex.Reset()
|
||||
} else if char == 'U' {
|
||||
state = unicode8
|
||||
hex.Reset()
|
||||
} else if newChar, ok := escapeSequenceMap[char]; ok {
|
||||
buffer.WriteRune(newChar)
|
||||
state = basic
|
||||
} else {
|
||||
return nil, fmt.Errorf(`invalid escape sequence \%c`, char)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if state == unicode4 || state == unicode8 {
|
||||
if isHexDigit(char) {
|
||||
hex.WriteRune(char)
|
||||
}
|
||||
if (state == unicode4 && hex.Len() == 4) || (state == unicode8 && hex.Len() == 8) {
|
||||
if value, err := strconv.ParseInt(hex.String(), 16, 32); err == nil {
|
||||
buffer.WriteRune(rune(value))
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
state = basic
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
switch char {
|
||||
case '\\':
|
||||
if state == basic {
|
||||
state = esc
|
||||
} else if state == literal {
|
||||
buffer.WriteRune(char)
|
||||
}
|
||||
case '\'':
|
||||
if state == bare {
|
||||
state = literal
|
||||
} else if state == literal {
|
||||
groups = append(groups, buffer.String())
|
||||
buffer.Reset()
|
||||
wasInQuotes = true
|
||||
state = bare
|
||||
}
|
||||
expectDot = false
|
||||
case '"':
|
||||
if state == bare {
|
||||
state = basic
|
||||
} else if state == basic {
|
||||
if inQuotes {
|
||||
groups = append(groups, buffer.String())
|
||||
buffer.Reset()
|
||||
state = bare
|
||||
wasInQuotes = true
|
||||
}
|
||||
inQuotes = !inQuotes
|
||||
expectDot = false
|
||||
case '.':
|
||||
if state != bare {
|
||||
if inQuotes {
|
||||
buffer.WriteRune(char)
|
||||
} else {
|
||||
if !wasInQuotes {
|
||||
@@ -122,31 +52,25 @@ func parseKey(key string) ([]string, error) {
|
||||
wasInQuotes = false
|
||||
}
|
||||
case ' ':
|
||||
if state == basic {
|
||||
if inQuotes {
|
||||
buffer.WriteRune(char)
|
||||
} else {
|
||||
expectDot = true
|
||||
}
|
||||
default:
|
||||
if state == bare {
|
||||
if !isValidBareChar(char) {
|
||||
return nil, fmt.Errorf("invalid bare character: %c", char)
|
||||
} else if expectDot {
|
||||
return nil, errors.New("what?")
|
||||
}
|
||||
if !inQuotes && !isValidBareChar(char) {
|
||||
return nil, fmt.Errorf("invalid bare character: %c", char)
|
||||
}
|
||||
if !inQuotes && expectDot {
|
||||
return nil, errors.New("what?")
|
||||
}
|
||||
buffer.WriteRune(char)
|
||||
expectDot = false
|
||||
}
|
||||
}
|
||||
|
||||
// state must be bare at the end
|
||||
if state == esc {
|
||||
return nil, errors.New("unfinished escape sequence")
|
||||
} else if state != bare {
|
||||
if inQuotes {
|
||||
return nil, errors.New("mismatched quotes")
|
||||
}
|
||||
|
||||
if buffer.Len() > 0 {
|
||||
groups = append(groups, buffer.String())
|
||||
}
|
||||
|
||||
13
vendor/github.com/pelletier/go-toml/keysparsing_test.go
сгенерированный
поставляемый
13
vendor/github.com/pelletier/go-toml/keysparsing_test.go
сгенерированный
поставляемый
@@ -50,17 +50,10 @@ func TestBaseKeyPound(t *testing.T) {
|
||||
func TestQuotedKeys(t *testing.T) {
|
||||
testResult(t, `hello."foo".bar`, []string{"hello", "foo", "bar"})
|
||||
testResult(t, `"hello!"`, []string{"hello!"})
|
||||
testResult(t, `"hello\tworld"`, []string{"hello\tworld"})
|
||||
testResult(t, `"\U0001F914"`, []string{"\U0001F914"})
|
||||
testResult(t, `"\u2764"`, []string{"\u2764"})
|
||||
testResult(t, `foo."ba.r".baz`, []string{"foo", "ba.r", "baz"})
|
||||
|
||||
testResult(t, `hello.'foo'.bar`, []string{"hello", "foo", "bar"})
|
||||
testResult(t, `'hello!'`, []string{"hello!"})
|
||||
testResult(t, `'hello\tworld'`, []string{`hello\tworld`})
|
||||
|
||||
testError(t, `"\w"`, `invalid escape sequence \w`)
|
||||
testError(t, `"\`, `unfinished escape sequence`)
|
||||
testError(t, `"\t`, `mismatched quotes`)
|
||||
// escape sequences must not be converted
|
||||
testResult(t, `"hello\tworld"`, []string{`hello\tworld`})
|
||||
}
|
||||
|
||||
func TestEmptyKey(t *testing.T) {
|
||||
|
||||
42
vendor/github.com/pelletier/go-toml/lexer.go
сгенерированный
поставляемый
42
vendor/github.com/pelletier/go-toml/lexer.go
сгенерированный
поставляемый
@@ -204,6 +204,14 @@ func (l *tomlLexer) lexRvalue() tomlLexStateFn {
|
||||
return l.lexFalse
|
||||
}
|
||||
|
||||
if l.follow("inf") {
|
||||
return l.lexInf
|
||||
}
|
||||
|
||||
if l.follow("nan") {
|
||||
return l.lexNan
|
||||
}
|
||||
|
||||
if isSpace(next) {
|
||||
l.skip()
|
||||
continue
|
||||
@@ -265,6 +273,18 @@ func (l *tomlLexer) lexFalse() tomlLexStateFn {
|
||||
return l.lexRvalue
|
||||
}
|
||||
|
||||
func (l *tomlLexer) lexInf() tomlLexStateFn {
|
||||
l.fastForward(3)
|
||||
l.emit(tokenInf)
|
||||
return l.lexRvalue
|
||||
}
|
||||
|
||||
func (l *tomlLexer) lexNan() tomlLexStateFn {
|
||||
l.fastForward(3)
|
||||
l.emit(tokenNan)
|
||||
return l.lexRvalue
|
||||
}
|
||||
|
||||
func (l *tomlLexer) lexEqual() tomlLexStateFn {
|
||||
l.next()
|
||||
l.emit(tokenEqual)
|
||||
@@ -277,6 +297,8 @@ func (l *tomlLexer) lexComma() tomlLexStateFn {
|
||||
return l.lexRvalue
|
||||
}
|
||||
|
||||
// Parse the key and emits its value without escape sequences.
|
||||
// bare keys, basic string keys and literal string keys are supported.
|
||||
func (l *tomlLexer) lexKey() tomlLexStateFn {
|
||||
growingString := ""
|
||||
|
||||
@@ -287,7 +309,16 @@ func (l *tomlLexer) lexKey() tomlLexStateFn {
|
||||
if err != nil {
|
||||
return l.errorf(err.Error())
|
||||
}
|
||||
growingString += `"` + str + `"`
|
||||
growingString += str
|
||||
l.next()
|
||||
continue
|
||||
} else if r == '\'' {
|
||||
l.next()
|
||||
str, err := l.lexLiteralStringAsString(`'`, false)
|
||||
if err != nil {
|
||||
return l.errorf(err.Error())
|
||||
}
|
||||
growingString += str
|
||||
l.next()
|
||||
continue
|
||||
} else if r == '\n' {
|
||||
@@ -527,6 +558,7 @@ func (l *tomlLexer) lexTableKey() tomlLexStateFn {
|
||||
return l.lexInsideTableKey
|
||||
}
|
||||
|
||||
// Parse the key till "]]", but only bare keys are supported
|
||||
func (l *tomlLexer) lexInsideTableArrayKey() tomlLexStateFn {
|
||||
for r := l.peek(); r != eof; r = l.peek() {
|
||||
switch r {
|
||||
@@ -550,6 +582,7 @@ func (l *tomlLexer) lexInsideTableArrayKey() tomlLexStateFn {
|
||||
return l.errorf("unclosed table array key")
|
||||
}
|
||||
|
||||
// Parse the key till "]" but only bare keys are supported
|
||||
func (l *tomlLexer) lexInsideTableKey() tomlLexStateFn {
|
||||
for r := l.peek(); r != eof; r = l.peek() {
|
||||
switch r {
|
||||
@@ -638,7 +671,14 @@ func (l *tomlLexer) lexNumber() tomlLexStateFn {
|
||||
|
||||
if r == '+' || r == '-' {
|
||||
l.next()
|
||||
if l.follow("inf") {
|
||||
return l.lexInf
|
||||
}
|
||||
if l.follow("nan") {
|
||||
return l.lexNan
|
||||
}
|
||||
}
|
||||
|
||||
pointSeen := false
|
||||
expSeen := false
|
||||
digitSeen := false
|
||||
|
||||
2
vendor/github.com/pelletier/go-toml/lexer_test.go
сгенерированный
поставляемый
2
vendor/github.com/pelletier/go-toml/lexer_test.go
сгенерированный
поставляемый
@@ -690,7 +690,7 @@ func TestKeyGroupArray(t *testing.T) {
|
||||
|
||||
func TestQuotedKey(t *testing.T) {
|
||||
testFlow(t, "\"a b\" = 42", []token{
|
||||
{Position{1, 1}, tokenKey, "\"a b\""},
|
||||
{Position{1, 1}, tokenKey, "a b"},
|
||||
{Position{1, 7}, tokenEqual, "="},
|
||||
{Position{1, 9}, tokenInteger, "42"},
|
||||
{Position{1, 11}, tokenEOF, ""},
|
||||
|
||||
137
vendor/github.com/pelletier/go-toml/marshal.go
сгенерированный
поставляемый
137
vendor/github.com/pelletier/go-toml/marshal.go
сгенерированный
поставляемый
@@ -230,7 +230,7 @@ func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tval.Set(opts.name, opts.comment, opts.commented, val)
|
||||
tval.SetWithComment(opts.name, opts.comment, opts.commented, val)
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
@@ -245,9 +245,9 @@ func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tval.SetPath([]string{keyStr}, "", false, val)
|
||||
tval.SetPath([]string{keyStr}, val)
|
||||
} else {
|
||||
tval.Set(key.String(), "", false, val)
|
||||
tval.Set(key.String(), val)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -486,96 +486,55 @@ func (d *Decoder) valueFromToml(mtype reflect.Type, tval interface{}) (reflect.V
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to a slice", tval, tval)
|
||||
default:
|
||||
switch mtype.Kind() {
|
||||
case reflect.Bool:
|
||||
val, ok := tval.(bool)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to bool", tval, tval)
|
||||
case reflect.Bool, reflect.Struct:
|
||||
val := reflect.ValueOf(tval)
|
||||
// if this passes for when mtype is reflect.Struct, tval is a time.Time
|
||||
if !val.Type().ConvertibleTo(mtype) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||
}
|
||||
return reflect.ValueOf(val), nil
|
||||
case reflect.Int:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to int", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(int(val)), nil
|
||||
case reflect.Int8:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to int", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(int8(val)), nil
|
||||
case reflect.Int16:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to int", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(int16(val)), nil
|
||||
case reflect.Int32:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to int", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(int32(val)), nil
|
||||
case reflect.Int64:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to int", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(val), nil
|
||||
case reflect.Uint:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to uint", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(uint(val)), nil
|
||||
case reflect.Uint8:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to uint", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(uint8(val)), nil
|
||||
case reflect.Uint16:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to uint", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(uint16(val)), nil
|
||||
case reflect.Uint32:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to uint", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(uint32(val)), nil
|
||||
case reflect.Uint64:
|
||||
val, ok := tval.(int64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to uint", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(uint64(val)), nil
|
||||
case reflect.Float32:
|
||||
val, ok := tval.(float64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to float", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(float32(val)), nil
|
||||
case reflect.Float64:
|
||||
val, ok := tval.(float64)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to float", tval, tval)
|
||||
}
|
||||
return reflect.ValueOf(val), nil
|
||||
|
||||
return val.Convert(mtype), nil
|
||||
case reflect.String:
|
||||
val, ok := tval.(string)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to string", tval, tval)
|
||||
val := reflect.ValueOf(tval)
|
||||
// stupidly, int64 is convertible to string. So special case this.
|
||||
if !val.Type().ConvertibleTo(mtype) || val.Kind() == reflect.Int64 {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||
}
|
||||
return reflect.ValueOf(val), nil
|
||||
case reflect.Struct:
|
||||
val, ok := tval.(time.Time)
|
||||
if !ok {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to time", tval, tval)
|
||||
|
||||
return val.Convert(mtype), nil
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
val := reflect.ValueOf(tval)
|
||||
if !val.Type().ConvertibleTo(mtype) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||
}
|
||||
return reflect.ValueOf(val), nil
|
||||
if reflect.Indirect(reflect.New(mtype)).OverflowInt(val.Int()) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
||||
}
|
||||
|
||||
return val.Convert(mtype), nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
val := reflect.ValueOf(tval)
|
||||
if !val.Type().ConvertibleTo(mtype) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||
}
|
||||
if val.Int() < 0 {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) is negative so does not fit in %v", tval, tval, mtype.String())
|
||||
}
|
||||
if reflect.Indirect(reflect.New(mtype)).OverflowUint(uint64(val.Int())) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
||||
}
|
||||
|
||||
return val.Convert(mtype), nil
|
||||
case reflect.Float32, reflect.Float64:
|
||||
val := reflect.ValueOf(tval)
|
||||
if !val.Type().ConvertibleTo(mtype) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v", tval, tval, mtype.String())
|
||||
}
|
||||
if reflect.Indirect(reflect.New(mtype)).OverflowFloat(val.Float()) {
|
||||
return reflect.ValueOf(nil), fmt.Errorf("%v(%T) would overflow %v", tval, tval, mtype.String())
|
||||
}
|
||||
|
||||
return val.Convert(mtype), nil
|
||||
default:
|
||||
return reflect.ValueOf(nil), fmt.Errorf("Can't convert %v(%T) to %v(%v)", tval, tval, mtype, mtype.Kind())
|
||||
}
|
||||
|
||||
19
vendor/github.com/pelletier/go-toml/parser.go
сгенерированный
поставляемый
19
vendor/github.com/pelletier/go-toml/parser.go
сгенерированный
поставляемый
@@ -5,6 +5,7 @@ package toml
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -110,7 +111,7 @@ func (p *tomlParser) parseGroupArray() tomlParserStateFn {
|
||||
newTree := newTree()
|
||||
newTree.position = startToken.Position
|
||||
array = append(array, newTree)
|
||||
p.tree.SetPath(p.currentTable, "", false, array)
|
||||
p.tree.SetPath(p.currentTable, array)
|
||||
|
||||
// remove all keys that were children of this table array
|
||||
prefix := key.val + "."
|
||||
@@ -185,10 +186,7 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
|
||||
}
|
||||
|
||||
// assign value to the found table
|
||||
keyVals, err := parseKey(key.val)
|
||||
if err != nil {
|
||||
p.raiseError(key, "%s", err)
|
||||
}
|
||||
keyVals := []string{key.val}
|
||||
if len(keyVals) != 1 {
|
||||
p.raiseError(key, "Invalid key")
|
||||
}
|
||||
@@ -246,6 +244,13 @@ func (p *tomlParser) parseRvalue() interface{} {
|
||||
return true
|
||||
case tokenFalse:
|
||||
return false
|
||||
case tokenInf:
|
||||
if tok.val[0] == '-' {
|
||||
return math.Inf(-1)
|
||||
}
|
||||
return math.Inf(1)
|
||||
case tokenNan:
|
||||
return math.NaN()
|
||||
case tokenInteger:
|
||||
cleanedVal := cleanupNumberToken(tok.val)
|
||||
var err error
|
||||
@@ -340,7 +345,7 @@ Loop:
|
||||
key := p.getToken()
|
||||
p.assume(tokenEqual)
|
||||
value := p.parseRvalue()
|
||||
tree.Set(key.val, "", false, value)
|
||||
tree.Set(key.val, value)
|
||||
case tokenComma:
|
||||
if previous == nil {
|
||||
p.raiseError(follow, "inline table cannot start with a comma")
|
||||
@@ -350,7 +355,7 @@ Loop:
|
||||
}
|
||||
p.getToken()
|
||||
default:
|
||||
p.raiseError(follow, "unexpected token type in inline table: %s", follow.typ.String())
|
||||
p.raiseError(follow, "unexpected token type in inline table: %s", follow.String())
|
||||
}
|
||||
previous = follow
|
||||
}
|
||||
|
||||
63
vendor/github.com/pelletier/go-toml/parser_test.go
сгенерированный
поставляемый
63
vendor/github.com/pelletier/go-toml/parser_test.go
сгенерированный
поставляемый
@@ -2,6 +2,7 @@ package toml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -46,7 +47,7 @@ func assertTree(t *testing.T, tree *Tree, err error, ref map[string]interface{})
|
||||
func TestCreateSubTree(t *testing.T) {
|
||||
tree := newTree()
|
||||
tree.createSubTree([]string{"a", "b", "c"}, Position{})
|
||||
tree.Set("a.b.c", "", false, 42)
|
||||
tree.Set("a.b.c", 42)
|
||||
if tree.Get("a.b.c") != 42 {
|
||||
t.Fail()
|
||||
}
|
||||
@@ -72,6 +73,17 @@ func TestNumberInKey(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIncorrectKeyExtraSquareBracket(t *testing.T) {
|
||||
_, err := Load(`[a]b]
|
||||
zyx = 42`)
|
||||
if err == nil {
|
||||
t.Error("Error should have been returned.")
|
||||
}
|
||||
if err.Error() != "(1, 4): unexpected token" {
|
||||
t.Error("Bad error message:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleNumbers(t *testing.T) {
|
||||
tree, err := Load("a = +42\nb = -21\nc = +4.2\nd = -2.1")
|
||||
assertTree(t, tree, err, map[string]interface{}{
|
||||
@@ -82,6 +94,25 @@ func TestSimpleNumbers(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSpecialFloats(t *testing.T) {
|
||||
tree, err := Load(`
|
||||
normalinf = inf
|
||||
plusinf = +inf
|
||||
minusinf = -inf
|
||||
normalnan = nan
|
||||
plusnan = +nan
|
||||
minusnan = -nan
|
||||
`)
|
||||
assertTree(t, tree, err, map[string]interface{}{
|
||||
"normalinf": math.Inf(1),
|
||||
"plusinf": math.Inf(1),
|
||||
"minusinf": math.Inf(-1),
|
||||
"normalnan": math.NaN(),
|
||||
"plusnan": math.NaN(),
|
||||
"minusnan": math.NaN(),
|
||||
})
|
||||
}
|
||||
|
||||
func TestHexIntegers(t *testing.T) {
|
||||
tree, err := Load(`a = 0xDEADBEEF`)
|
||||
assertTree(t, tree, err, map[string]interface{}{"a": int64(3735928559)})
|
||||
@@ -208,6 +239,36 @@ func TestSpaceKey(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestDoubleQuotedKey(t *testing.T) {
|
||||
tree, err := Load(`
|
||||
"key" = "a"
|
||||
"\t" = "b"
|
||||
"\U0001F914" = "c"
|
||||
"\u2764" = "d"
|
||||
`)
|
||||
assertTree(t, tree, err, map[string]interface{}{
|
||||
"key": "a",
|
||||
"\t": "b",
|
||||
"\U0001F914": "c",
|
||||
"\u2764": "d",
|
||||
})
|
||||
}
|
||||
|
||||
func TestSingleQuotedKey(t *testing.T) {
|
||||
tree, err := Load(`
|
||||
'key' = "a"
|
||||
'\t' = "b"
|
||||
'\U0001F914' = "c"
|
||||
'\u2764' = "d"
|
||||
`)
|
||||
assertTree(t, tree, err, map[string]interface{}{
|
||||
`key`: "a",
|
||||
`\t`: "b",
|
||||
`\U0001F914`: "c",
|
||||
`\u2764`: "d",
|
||||
})
|
||||
}
|
||||
|
||||
func TestStringEscapables(t *testing.T) {
|
||||
tree, err := Load("a = \"a \\n b\"")
|
||||
assertTree(t, tree, err, map[string]interface{}{
|
||||
|
||||
1
vendor/github.com/pelletier/go-toml/test.sh
сгенерированный
поставляемый
1
vendor/github.com/pelletier/go-toml/test.sh
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
# fail out of the script if anything here fails
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
# set the path to the present working directory
|
||||
export GOPATH=`pwd`
|
||||
|
||||
4
vendor/github.com/pelletier/go-toml/token.go
сгенерированный
поставляемый
4
vendor/github.com/pelletier/go-toml/token.go
сгенерированный
поставляемый
@@ -23,6 +23,8 @@ const (
|
||||
tokenTrue
|
||||
tokenFalse
|
||||
tokenFloat
|
||||
tokenInf
|
||||
tokenNan
|
||||
tokenEqual
|
||||
tokenLeftBracket
|
||||
tokenRightBracket
|
||||
@@ -55,6 +57,8 @@ var tokenTypeNames = []string{
|
||||
"True",
|
||||
"False",
|
||||
"Float",
|
||||
"Inf",
|
||||
"NaN",
|
||||
"=",
|
||||
"[",
|
||||
"]",
|
||||
|
||||
27
vendor/github.com/pelletier/go-toml/toml.go
сгенерированный
поставляемый
27
vendor/github.com/pelletier/go-toml/toml.go
сгенерированный
поставляемый
@@ -71,18 +71,15 @@ func (t *Tree) Keys() []string {
|
||||
}
|
||||
|
||||
// Get the value at key in the Tree.
|
||||
// Key is a dot-separated path (e.g. a.b.c).
|
||||
// Key is a dot-separated path (e.g. a.b.c) without single/double quoted strings.
|
||||
// If you need to retrieve non-bare keys, use GetPath.
|
||||
// Returns nil if the path does not exist in the tree.
|
||||
// If keys is of length zero, the current tree is returned.
|
||||
func (t *Tree) Get(key string) interface{} {
|
||||
if key == "" {
|
||||
return t
|
||||
}
|
||||
comps, err := parseKey(key)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return t.GetPath(comps)
|
||||
return t.GetPath(strings.Split(key, "."))
|
||||
}
|
||||
|
||||
// GetPath returns the element in the tree indicated by 'keys'.
|
||||
@@ -181,14 +178,26 @@ func (t *Tree) GetDefault(key string, def interface{}) interface{} {
|
||||
// Set an element in the tree.
|
||||
// Key is a dot-separated path (e.g. a.b.c).
|
||||
// Creates all necessary intermediate trees, if needed.
|
||||
func (t *Tree) Set(key string, comment string, commented bool, value interface{}) {
|
||||
t.SetPath(strings.Split(key, "."), comment, commented, value)
|
||||
func (t *Tree) Set(key string, value interface{}) {
|
||||
t.SetWithComment(key, "", false, value)
|
||||
}
|
||||
|
||||
// SetWithComment is the same as Set, but allows you to provide comment
|
||||
// information to the key, that will be reused by Marshal().
|
||||
func (t *Tree) SetWithComment(key string, comment string, commented bool, value interface{}) {
|
||||
t.SetPathWithComment(strings.Split(key, "."), comment, commented, value)
|
||||
}
|
||||
|
||||
// SetPath sets an element in the tree.
|
||||
// Keys is an array of path elements (e.g. {"a","b","c"}).
|
||||
// Creates all necessary intermediate trees, if needed.
|
||||
func (t *Tree) SetPath(keys []string, comment string, commented bool, value interface{}) {
|
||||
func (t *Tree) SetPath(keys []string, value interface{}) {
|
||||
t.SetPathWithComment(keys, "", false, value)
|
||||
}
|
||||
|
||||
// SetPathWithComment is the same as SetPath, but allows you to provide comment
|
||||
// information to the key, that will be reused by Marshal().
|
||||
func (t *Tree) SetPathWithComment(keys []string, comment string, commented bool, value interface{}) {
|
||||
subtree := t
|
||||
for _, intermediateKey := range keys[:len(keys)-1] {
|
||||
nextTree, exists := subtree.values[intermediateKey]
|
||||
|
||||
4
vendor/github.com/pelletier/go-toml/tomltree_write.go
сгенерированный
поставляемый
4
vendor/github.com/pelletier/go-toml/tomltree_write.go
сгенерированный
поставляемый
@@ -54,9 +54,9 @@ func tomlValueStringRepresentation(v interface{}, indent string, arraysOneElemen
|
||||
// Ensure a round float does contain a decimal point. Otherwise feeding
|
||||
// the output back to the parser would convert to an integer.
|
||||
if math.Trunc(value) == value {
|
||||
return strconv.FormatFloat(value, 'f', 1, 32), nil
|
||||
return strings.ToLower(strconv.FormatFloat(value, 'f', 1, 32)), nil
|
||||
}
|
||||
return strconv.FormatFloat(value, 'f', -1, 32), nil
|
||||
return strings.ToLower(strconv.FormatFloat(value, 'f', -1, 32)), nil
|
||||
case string:
|
||||
return "\"" + encodeTomlString(value) + "\"", nil
|
||||
case []byte:
|
||||
|
||||
18
vendor/github.com/pelletier/go-toml/tomltree_write_test.go
сгенерированный
поставляемый
18
vendor/github.com/pelletier/go-toml/tomltree_write_test.go
сгенерированный
поставляемый
@@ -309,6 +309,24 @@ func TestTreeWriteToFloat(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTreeWriteToSpecialFloat(t *testing.T) {
|
||||
expected := `a = +inf
|
||||
b = -inf
|
||||
c = nan`
|
||||
|
||||
tree, err := Load(expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
str, err := tree.ToTomlString()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user