dos2unix - example_test.go
1 package dos2unix_test
2
3 import (
4 "fmt"
5 "io"
6 "strings"
7
8 "vimagination.zapto.org/dos2unix"
9 )
10
11 // ExampleDOS2Unix converts CRLF line terminations to LF.
12 func ExampleDOS2Unix() {
13 input := strings.NewReader("hello\r\nworld\r\n")
14 r := dos2unix.DOS2Unix(input)
15 out, _ := io.ReadAll(r)
16
17 fmt.Printf("%q\n", out)
18 // Output: "hello\nworld\n"
19 }
20
21 // ExampleUnix2DOS converts LF line terminations to CRLF.
22 func ExampleUnix2DOS() {
23 input := strings.NewReader("hello\nworld\n")
24 r := dos2unix.Unix2DOS(input)
25 out, _ := io.ReadAll(r)
26
27 fmt.Printf("%q\n", out)
28 // Output: "hello\r\nworld\r\n"
29 }
30