From 111527ef6b1e9972906634738b14adaa21f97c24 Mon Sep 17 00:00:00 2001 From: Andy Balholm Date: Thu, 28 Mar 2013 12:41:56 -0700 Subject: [PATCH] Go fmt. --- yaml/config.go | 24 +++++++++----------- yaml/config_test.go | 16 +++++++------- yaml/doc.go | 54 ++++++++++++++++++++++----------------------- yaml/parser.go | 18 +++++++-------- yaml/parser_test.go | 10 ++++----- 5 files changed, 60 insertions(+), 62 deletions(-) diff --git a/yaml/config.go b/yaml/config.go index 2f230d5..fb1fa6d 100644 --- a/yaml/config.go +++ b/yaml/config.go @@ -90,34 +90,32 @@ func (f *File) Get(spec string) (string, error) { } func (f *File) GetInt(spec string) (int64, error) { - s, err := f.Get( spec ) + s, err := f.Get(spec) if err != nil { - return 0,err + return 0, err } - i, err := strconv.ParseInt( s, 10, 64 ) + i, err := strconv.ParseInt(s, 10, 64) if err != nil { return 0, err } - - return i,nil + + return i, nil } func (f *File) GetBool(spec string) (bool, error) { - s, err := f.Get( spec ) + s, err := f.Get(spec) if err != nil { - return false,err + return false, err } - b, err := strconv.ParseBool( s ) + b, err := strconv.ParseBool(s) if err != nil { return false, err } - - return b,nil -} - + return b, nil +} // Count retrieves a the number of elements in the specified list from the file // using the same format as that expected by Child. If the final node is not a @@ -169,7 +167,7 @@ func (f *File) Require(spec string) string { // The node tree is walked from the given node, considering each token of the // above format. If a node along the evaluation path is not found, an error is // returned. If a node is not the proper type, an error is returned. If the -// final node is not a Scalar, an error is returned. +// final node is not a Scalar, an error is returned. func Child(root Node, spec string) (Node, error) { if len(spec) == 0 { return root, nil diff --git a/yaml/config_test.go b/yaml/config_test.go index 58df7b3..d0f5530 100644 --- a/yaml/config_test.go +++ b/yaml/config_test.go @@ -67,19 +67,19 @@ func TestGet(t *testing.T) { } } - i, err := config.GetInt( "mapping.key3" ) + i, err := config.GetInt("mapping.key3") if err != nil || i != 5 { - t.Errorf("GetInt mapping.key3 wrong" ) + t.Errorf("GetInt mapping.key3 wrong") } - b, err := config.GetBool( "mapping.key4" ) - if err != nil || b != true { - t.Errorf("GetBool mapping.key4 wrong" ) + b, err := config.GetBool("mapping.key4") + if err != nil || b != true { + t.Errorf("GetBool mapping.key4 wrong") } - b, err = config.GetBool( "mapping.key5" ) - if err != nil || b != false { - t.Errorf("GetBool mapping.key5 wrong" ) + b, err = config.GetBool("mapping.key5") + if err != nil || b != false { + t.Errorf("GetBool mapping.key5 wrong") } } diff --git a/yaml/doc.go b/yaml/doc.go index 46de03d..e52eff5 100644 --- a/yaml/doc.go +++ b/yaml/doc.go @@ -4,42 +4,42 @@ // tabs, and GYPSY does not ever consider a tab to be a space character. It is // recommended that your editor be configured to convert tabs to spaces when // editing Gypsy config files. -// +// // Gypsy understands the following to be a list: -// +// // - one // - two // - three -// +// // This is parsed as a `yaml.List`, and can be retrieved from the // `yaml.Node.List()` method. In this case, each element of the `yaml.List` would // be a `yaml.Scalar` whose value can be retrieved with the `yaml.Scalar.String()` // method. -// +// // Gypsy understands the following to be a mapping: -// +// // key: value // foo: bar // running: away -// +// // A mapping is an unordered list of `key:value` pairs. All whitespace after the // colon is stripped from the value and is used for alignment purposes during // export. If the value is not a list or a map, everything after the first // non-space character until the end of the line is used as the `yaml.Scalar` // value. -// +// // Gypsy allows arbitrary nesting of maps inside lists, lists inside of maps, and // maps and/or lists nested inside of themselves. -// +// // A map inside of a list: -// +// // - name: John Smith // age: 42 // - name: Jane Smith // age: 45 -// +// // A list inside of a map: -// +// // schools: // - Meadow Glen // - Forest Creek @@ -47,9 +47,9 @@ // libraries: // - Joseph Hollingsworth Memorial // - Andrew Keriman Memorial -// +// // A list of lists: -// +// // - - one // - two // - three @@ -59,9 +59,9 @@ // - - ichi // - ni // - san -// +// // A map of maps: -// +// // google: // company: Google, Inc. // ticker: GOOG @@ -70,11 +70,11 @@ // company: Yahoo, Inc. // ticker: YHOO // url: http://yahoo.com/ -// +// // In the case of a map of maps, all sub-keys must be on subsequent lines and // indented equally. It is allowable for the first key/value to be on the same // line if there is more than one key/value pair, but this is not recommended. -// +// // Values can also be expressed in long form (leading whitespace of the first line // is removed from it and all subsequent lines). In the normal (baz) case, // newlines are treated as spaces, all indentation is removed. In the folded case @@ -83,40 +83,40 @@ // line is removed, and newlines at the end of indented lines are preserved. In // the verbatim (foo) case, only the indent at the level of the first line is // stripped. The example: -// +// // foo: | // lorem ipsum dolor // sit amet // bar: > // lorem ipsum -// +// // dolor -// +// // sit amet // baz: // lorem ipsum // dolor sit amet -// +// // The YAML subset understood by Gypsy can be expressed (loosely) in the following // grammar (not including comments): -// +// // OBJECT = MAPPING | SEQUENCE | SCALAR . // SHORT-OBJECT = SHORT-MAPPING | SHORT-SEQUENCE | SHORT-SCALAR . // EOL = '\n' -// +// // MAPPING = { LONG-MAPPING | SHORT-MAPPING } . // SEQUENCE = { LONG-SEQUENCE | SHORT-SEQUENCE } . // SCALAR = { LONG-SCALAR | SHORT-SCALAR } . -// +// // LONG-MAPPING = { INDENT KEY ':' OBJECT EOL } . // SHORT-MAPPING = '{' KEY ':' SHORT-OBJECT { ',' KEY ':' SHORT-OBJECT } '}' EOL . -// +// // LONG-SEQUENCE = { INDENT '-' OBJECT EOL } EOL . // SHORT-SEQUENCE = '[' SHORT-OBJECT { ',' SHORT-OBJECT } ']' EOL . -// +// // LONG-SCALAR = ( '|' | '>' | ) EOL { INDENT SHORT-SCALAR EOL } // SHORT-SCALAR = { alpha | digit | punct | ' ' | '\t' } . -// +// // KEY = { alpha | digit } // INDENT = { ' ' } // diff --git a/yaml/parser.go b/yaml/parser.go index 640ce09..d860ae9 100644 --- a/yaml/parser.go +++ b/yaml/parser.go @@ -107,23 +107,23 @@ func parseNode(r lineReader, ind int, initial Node) (node Node) { trimmed := bytes.TrimSpace(end) if len(trimmed) == 1 && trimmed[0] == '|' { text := "" - + for { l := r.Next(1) if l == nil { break } - + s := string(l.line) - s = strings.TrimSpace( s ) + s = strings.TrimSpace(s) if len(s) == 0 { break } text = text + "\n" + s } - + types = append(types, typScalar) - pieces = append(pieces, string(text)) + pieces = append(pieces, string(text)) return } inlineValue(end) @@ -241,8 +241,8 @@ func getType(line []byte) (typ, split int) { // need to iterate past the first word // things like "foo:" and "foo :" are mappings // everything else is a scalar - - idx := bytes.IndexAny( line, " \":" ) + + idx := bytes.IndexAny(line, " \":") if idx < 0 { return } @@ -276,11 +276,11 @@ func getType(line []byte) (typ, split int) { } } - if typ == typMapping && split + 1 < len(line) && line[split+1] != ' ' { + if typ == typMapping && split+1 < len(line) && line[split+1] != ' ' { typ = typScalar split = 0 } - + return } diff --git a/yaml/parser_test.go b/yaml/parser_test.go index f7363e2..1c5c552 100644 --- a/yaml/parser_test.go +++ b/yaml/parser_test.go @@ -204,16 +204,16 @@ func TestGetType(t *testing.T) { } func Test_MultiLineString(t *testing.T) { - buf := bytes.NewBufferString( "a : |\n a\n b\n\nc : d" ) - node, err := Parse( buf ) + buf := bytes.NewBufferString("a : |\n a\n b\n\nc : d") + node, err := Parse(buf) if err != nil { - t.Error( err ) + t.Error(err) } else { m := node.(Map) v := m["a"].(Scalar) - v2 := strings.TrimSpace( string(v) ) + v2 := strings.TrimSpace(string(v)) if v2 != "a\nb" { - t.Errorf( "multi line parsed wrong thing: %v", v ) + t.Errorf("multi line parsed wrong thing: %v", v) } } }