MCPcopy
hub / github.com/pelletier/go-toml / ExampleParser

Function ExampleParser

unstable/parser_test.go:987–1008  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

985}
986
987func ExampleParser() {
988 doc := `
989 hello = "world"
990 value = 42
991 `
992 p := Parser{}
993 p.Reset([]byte(doc))
994 for p.NextExpression() {
995 e := p.Expression()
996 fmt.Printf("Expression: %s\n", e.Kind)
997 value := e.Value()
998 it := e.Key()
999 k := it.Node() // shortcut: we know there is no dotted key in the example
1000 fmt.Printf("%s -> (%s) %s\n", k.Data, value.Kind, value.Data)
1001 }
1002
1003 // Output:
1004 // Expression: KeyValue
1005 // hello -> (String) world
1006 // Expression: KeyValue
1007 // value -> (Integer) 42
1008}
1009
1010func TestParserErrorPosition(t *testing.T) {
1011 examples := []struct {

Callers

nothing calls this directly

Calls 6

ResetMethod · 0.95
NextExpressionMethod · 0.95
ExpressionMethod · 0.95
ValueMethod · 0.80
NodeMethod · 0.80
KeyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…