* Port toml-test to pure Go
This change basically ports the toml-test examples test suite to pure
Go. This removes the snowflake test.sh required to run such tests, and
allows us to the example tests on any platform (which includes Windows
as part of the pull-request testing).
* Allow CircleCI failure for go tip
When a struct is unmarshalled, go-toml now looks at the `default` tag to
provide a default value in case the key is not present in the TOML
document. This is only implemented for string, bool, int, int64,
float64. Additional types can be further implemented on a request-basis.
The name for each field in a struct is used to look up a key in the TOML
tree. A few different (case-sensitive) forms of this name are tried.
Previously, the current, lower-cased, and title-cased versions of the
name are tried. This precludes camelCased keys from mapping back to
fields in structs. This change adds camelCase to the set of keys to
try.
For example, the following TOML:
fooBar = 10
Would previously *not* map to the following struct:
type Foo struct {
FooBar int
}
This change corrects this.
Decoder: allow to customize default field name tag "toml" on decoding.
Example:
```
type doc struct {
title `file:"header"`
}
```
Encoder: allow to customize tags for encoding struct to toml.
Example:
```
type doc struct {
title `file:"header" description:"document title"`
}
```
Fixes#238
The new multiline tag works just like the existing 'commented' tag (i.e.
`multiline:"true"`), and tells go-toml to marshal the value as a
multi-line string. The tag currently has no impact on any non-string
fields.
* Update Travis CI to use latest Go releases
* Fix go vet issues for Go 1.10
Starting in Go 1.10, the `go test` command now automatically runs `go
vet`. This commit fixes two issues flagged by vet that cause `go test`
to fail.
* Fix gofmt issue for Go 1.10
Go 1.10 introduced a small formatting change with comments in empty
multiline slice definitions. This commit attempts to move the offending
comment in such a way that all version of gofmt will agree on its
location.
* Remove go-vet from test.sh
Starting in Go 1.10, the `go test` command automatically runs `go vet`,
so we don't need to run `go vet` explicitly from within test.sh.
Fixes#222
Patch #185 introduced a backward incompatibility by changing the arguments
of the `Set*` methods on `Tree`.
This change restores the arguments to what they previous were, and
introduces `SetWithComment` and `SetPathWithComment` to perform the same
action.
This fixes two unmarshalling issues:
1. Unmarshalling into a custom integer/float type (e.g. `time.Duration`).
2. Checks for overflows happen before unmarshalling, erroring if an overflow
would happen.
Apart from this it also reduces code duplication a bit.
Patch #193 introduced a regression in the toml-tests examples, but it was
never caught because test.sh was exiting with a zero status code, even
though the tests failed. This is because of the `|tee` operation when
invoking toml-test, without setting the pipefail option, reporting the
status code of `tee` instead of `toml-test`.
Add support for non-decimal integers. At the time of writing, this is an
unreleased backward-compatible feature of TOML:
```
Non-negative integer values may also be expressed in hexadecimal, octal, or
binary. In these formats, leading zeros are allowed (after the prefix). Hex
values are case insensitive. Underscores are allowed between digits (but
not between the prefix and the value).
# hexadecimal with prefix `0x`
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef
# octal with prefix `0o`
oct1 = 0o01234567
oct2 = 0o755 # useful for Unix file permissions
# binary with prefix `0b`
bin1 = 0b11010110
```
Fixes#204
A new Encoder option emits arrays with more than one line on multiple lines.
This is off by default and toggled with `ArraysWithOneElementPerLine`.
For example:
```
A = [1,2,3]
```
Becomes:
```
A = [
1,
2,
3
]
```
Fixes#200
Usage is similar to the stdlibs JSON encoder/decoder but I tried to
leave the general structure of the code the same.
Main motivation was to support encoding/decoding options to allow
encoding string-type map keys as quoted TOML keys.
This was implemented on the Encoder with QuoteMapKeys(bool).
> The TOML spec supports using UTF-8 strings as keys.
> https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md#table