aboutsummaryrefslogtreecommitdiff
path: root/lib/parser/parser_example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parser/parser_example_test.go')
-rw-r--r--lib/parser/parser_example_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/parser/parser_example_test.go b/lib/parser/parser_example_test.go
new file mode 100644
index 00000000..41e75455
--- /dev/null
+++ b/lib/parser/parser_example_test.go
@@ -0,0 +1,29 @@
+// Copyright 2019, Shulhan <m.shulhan@gmail.com>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package parser
+
+import (
+ "fmt"
+ "strings"
+)
+
+func ExampleNew() {
+ content := "[test]\nkey = value"
+ p := New(content, "=[]")
+
+ for {
+ token, del := p.Token()
+ token = strings.TrimSpace(token)
+ fmt.Printf("%q %q\n", token, del)
+ if del == 0 {
+ break
+ }
+ }
+ // Output:
+ // "" '['
+ // "test" ']'
+ // "key" '='
+ // "value" '\x00'
+}