-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
54 lines (44 loc) · 818 Bytes
/
main_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 main
import (
"bufio"
"fmt"
"sort"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestProcess(t *testing.T) {
input := `2001:678:1e0:0::/64
2001:678:1e0::1
2001:678:1e0:100::/56
2001:678:1e0:110::1/128
2001:678:1e0:200::2/128
172.24.0.1
192.168.2.0/24
192.168.0.0/16
`
expected := `172.24.0.1/32
192.168.0.0/16
2001:678:1e0:100::/56
2001:678:1e0:200::2/128
2001:678:1e0::/64
`
r := strings.NewReader(input)
out := process(r)
out = sortLines(out)
assert.Equal(t, expected, out)
}
func sortLines(s string) string {
r := strings.NewReader(s)
sc := bufio.NewScanner(r)
lines := []string{}
for sc.Scan() {
lines = append(lines, sc.Text())
}
sort.Strings(lines)
sb := &strings.Builder{}
for _, l := range lines {
fmt.Fprintf(sb, "%s\n", l)
}
return sb.String()
}