diff options
| author | Shulhan <ms@kilabit.info> | 2023-04-10 20:27:00 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-04-13 01:30:56 +0700 |
| commit | 2409f21063c5aeff7fc8cf4ba703ee07bd797bee (patch) | |
| tree | 3bbfb1b4461c1e6913b931080319f4e72397e8c8 /lib/bytes/parser_example_test.go | |
| parent | 5120d36fdb9e374cb77f7aa21f7caca170d0a4b8 (diff) | |
| download | pakakeh.go-2409f21063c5aeff7fc8cf4ba703ee07bd797bee.tar.xz | |
lib/bytes: move unit Test for Read and SkipLine to Example
Using an example not only test the code but also provide example snippet
when opened in the godoc.
Diffstat (limited to 'lib/bytes/parser_example_test.go')
| -rw-r--r-- | lib/bytes/parser_example_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/bytes/parser_example_test.go b/lib/bytes/parser_example_test.go index a30bda5a..a81e9fc7 100644 --- a/lib/bytes/parser_example_test.go +++ b/lib/bytes/parser_example_test.go @@ -37,6 +37,26 @@ func ExampleParser_Delimiters() { // =; } +func ExampleParser_Read() { + var ( + content = []byte("a = b; ") + delims = []byte{'=', ';'} + parser = libbytes.NewParser(content, delims) + ) + + token, c := parser.Read() + fmt.Printf("token:'%s' c:'%c'\n", token, c) + token, c = parser.Read() + fmt.Printf("token:'%s' c:'%c'\n", token, c) + token, c = parser.Read() + fmt.Printf("token:'%s' c:%d\n", token, c) + + // Output: + // token:'a ' c:'=' + // token:' b' c:';' + // token:' ' c:0 +} + func ExampleParser_ReadLine() { var ( content = []byte("a=b;\nc=d;") @@ -191,6 +211,25 @@ func ExampleParser_Skip() { // } +func ExampleParser_SkipLine() { + var ( + content = []byte("a\nb\nc\nd e\n") + delims = []byte("\n") + parser = libbytes.NewParser(content, delims) + ) + + parser.SkipLine() + token, _ := parser.Read() + fmt.Printf("token:'%s'\n", token) + + parser.SkipLine() + token, _ = parser.Read() + fmt.Printf("token:'%s'\n", token) + // Output: + // token:'b' + // token:'d e' +} + func ExampleParser_SkipN() { var ( content = []byte(`a=b;c=d;`) |
