generated from parrogo/gomod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_test.go
54 lines (47 loc) · 1.25 KB
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package lines_test
import (
"embed"
"fmt"
"io/fs"
"os"
"github.com/parrogo/lines"
)
//go:embed fixtures
var fixtureRootFS embed.FS
var fixtureFS, _ = fs.Sub(fixtureRootFS, "fixtures")
// This example show how to use a lines.Buffer
// to acccumulate a bunch of lines and write them
// to console at end using `Write` method.
func ExampleBuffer_Write() {
var lines lines.Buffer
lines.AddLineF("A simple line")
lines.AddLineF("Trailing new lines are not needed\n")
lines.AddLineF("You can use %s arguments", "fmt.Printf")
err := lines.Write(os.Stdout)
if err != nil {
panic(err)
}
// Output: A simple line
// Trailing new lines are not needed
//
// You can use fmt.Printf arguments
}
// This example show how to use a lines.Buffer
func ExampleBuffer_WriteFile() {
var lines lines.Buffer
lines.AddLineF("A simple line")
lines.AddLineF("Trailing new lines are not needed\n")
lines.AddLineF("You can use %s arguments", "fmt.Printf")
err := lines.WriteFile("/tmp/example")
if err != nil {
panic(err)
}
// read the content of the file just written
content, _ := os.ReadFile("/tmp/example")
os.Remove("/tmp/example")
fmt.Print(string(content))
// Output: A simple line
// Trailing new lines are not needed
//
// You can use fmt.Printf arguments
}