diff --git a/.gitignore b/.gitignore index e256a31..23d1a69 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ Session.vim # Go test binaries *.test + +.idea/ diff --git a/fields.go b/fields.go index 5860074..c14c8c1 100644 --- a/fields.go +++ b/fields.go @@ -1,4 +1,4 @@ -// Copyright 2013 The Go Authors. All rights reserved. +// Package yaml Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package yaml @@ -347,8 +347,9 @@ const ( // 4) simpleLetterEqualFold, no specials, no non-letters. // // The letters S and K are special because they map to 3 runes, not just 2: -// * S maps to s and to U+017F 'ſ' Latin small letter long s -// * k maps to K and to U+212A 'K' Kelvin sign +// - S maps to s and to U+017F 'ſ' Latin small letter long s +// - k maps to K and to U+212A 'K' Kelvin sign +// // See http://play.golang.org/p/tTxjOc0OGo // // The returned function is specialized for matching against s and @@ -419,10 +420,7 @@ func equalFoldRight(s, t []byte) bool { t = t[size:] } - if len(t) > 0 { - return false - } - return true + return len(t) <= 0 } // asciiEqualFold is a specialization of bytes.EqualFold for use when diff --git a/yaml.go b/yaml.go index dfd264d..6b5554f 100644 --- a/yaml.go +++ b/yaml.go @@ -7,8 +7,7 @@ // JSON methods MarshalJSON and UnmarshalJSON unlike go-yaml. // // See also http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang -// -package yaml // import "github.com/ghodss/yaml" +package yaml // import "github.com/ghodss/yaml" import ( "bytes" @@ -21,7 +20,7 @@ import ( "gopkg.in/yaml.v2" ) -// Marshals the object into JSON then converts JSON to YAML and returns the +// Marshal Marshals the object into JSON then converts JSON to YAML and returns the // YAML. func Marshal(o interface{}) ([]byte, error) { j, err := json.Marshal(o) @@ -83,7 +82,7 @@ func jsonUnmarshal(r io.Reader, o interface{}, opts ...JSONOpt) error { return nil } -// Convert JSON to YAML. +// JSONToYAML Convert JSON to YAML. func JSONToYAML(j []byte) ([]byte, error) { // Convert the JSON to an object. var jsonObj interface{} @@ -105,12 +104,12 @@ func JSONToYAML(j []byte) ([]byte, error) { // passing JSON through this method should be a no-op. // // Things YAML can do that are not supported by JSON: -// * In YAML you can have binary and null keys in your maps. These are invalid -// in JSON. (int and float keys are converted to strings.) -// * Binary data in YAML with the !!binary tag is not supported. If you want to -// use binary data with this library, encode the data as base64 as usual but do -// not use the !!binary tag in your YAML. This will ensure the original base64 -// encoded data makes it all the way through to the JSON. +// - In YAML you can have binary and null keys in your maps. These are invalid +// in JSON. (int and float keys are converted to strings.) +// - Binary data in YAML with the !!binary tag is not supported. If you want to +// use binary data with this library, encode the data as base64 as usual but do +// not use the !!binary tag in your YAML. This will ensure the original base64 +// encoded data makes it all the way through to the JSON. // // For strict decoding of YAML, use YAMLToJSONStrict. func YAMLToJSON(y []byte) ([]byte, error) { @@ -153,7 +152,7 @@ func convertToJSONableObject(yamlObj interface{}, jsonTarget *reflect.Value) (in // string. if jsonTarget != nil { ju, tu, pv := indirect(*jsonTarget, false) - // We have a JSON or Text Umarshaler at this level, so we can't be trying + // We have a JSON or Text Unmarshaler at this level, so we can't be trying // to decode into a string. if ju != nil || tu != nil { jsonTarget = nil @@ -165,7 +164,7 @@ func convertToJSONableObject(yamlObj interface{}, jsonTarget *reflect.Value) (in // If yamlObj is a number or a boolean, check if jsonTarget is a string - // if so, coerce. Else return normal. // If yamlObj is a map or array, find the field that each key is - // unmarshaling to, and when you recurse pass the reflect.Value for that + // unmarshalling to, and when you recurse pass the reflect.Value for that // field back into this function. switch typedYAMLObj := yamlObj.(type) { case map[interface{}]interface{}: diff --git a/yaml_go110_test.go b/yaml_go110_test.go index 753ee3f..8fcecb8 100644 --- a/yaml_go110_test.go +++ b/yaml_go110_test.go @@ -1,3 +1,4 @@ +//go:build go1.10 // +build go1.10 package yaml @@ -40,10 +41,10 @@ func TestUnmarshalWithTags(t *testing.T) { // duplicate fields in the YAML input. func TestUnmarshalStrictWithJSONOpts(t *testing.T) { for _, tc := range []struct { - yaml []byte - opts []JSONOpt - want UnmarshalString - wantErr string + yaml []byte + opts []JSONOpt + want UnmarshalString + wantErr string }{ { // By default, unknown field is ignored. @@ -52,9 +53,9 @@ func TestUnmarshalStrictWithJSONOpts(t *testing.T) { }, { // Unknown field produces an error with `DisallowUnknownFields` option. - yaml: []byte("a: 1\nunknownField: 2"), - opts: []JSONOpt{DisallowUnknownFields}, - wantErr: `unknown field "unknownField"`, + yaml: []byte("a: 1\nunknownField: 2"), + opts: []JSONOpt{DisallowUnknownFields}, + wantErr: `unknown field "unknownField"`, }, } { po := prettyFunctionName(tc.opts) @@ -69,7 +70,7 @@ func TestUnmarshalStrictWithJSONOpts(t *testing.T) { continue } // We expect that duplicate fields are discovered during JSON unmarshalling. - if want := "error unmarshaling JSON"; tc.wantErr != "" && !strings.Contains(err.Error(), want) { + if want := "error unmarshalling JSON"; tc.wantErr != "" && !strings.Contains(err.Error(), want) { t.Errorf("UnmarshalStrict(%#q, &s, %#v) = %v; want err contains %#q", string(tc.yaml), po, err, want) } if tc.wantErr != "" && !strings.Contains(err.Error(), tc.wantErr) { @@ -95,6 +96,6 @@ func ExampleUnknown() { y := []byte(`unknown: "hello"`) v := WithTaggedField{} fmt.Printf("%v\n", Unmarshal(y, &v, DisallowUnknownFields)) - // Ouptut: - // unmarshaling JSON: while decoding JSON: json: unknown field "unknown" + // Output: + // unmarshalling JSON: while decoding JSON: json: unknown field "unknown" }