2018-05-07 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libgo / go / os / exec / internal_test.go
blob68d517ffb9b02dd51fb2e32da0744a74aee4939c
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package exec
7 import (
8 "io"
9 "testing"
12 func TestPrefixSuffixSaver(t *testing.T) {
13 tests := []struct {
14 N int
15 writes []string
16 want string
19 N: 2,
20 writes: nil,
21 want: "",
24 N: 2,
25 writes: []string{"a"},
26 want: "a",
29 N: 2,
30 writes: []string{"abc", "d"},
31 want: "abcd",
34 N: 2,
35 writes: []string{"abc", "d", "e"},
36 want: "ab\n... omitting 1 bytes ...\nde",
39 N: 2,
40 writes: []string{"ab______________________yz"},
41 want: "ab\n... omitting 22 bytes ...\nyz",
44 N: 2,
45 writes: []string{"ab_______________________y", "z"},
46 want: "ab\n... omitting 23 bytes ...\nyz",
49 for i, tt := range tests {
50 w := &prefixSuffixSaver{N: tt.N}
51 for _, s := range tt.writes {
52 n, err := io.WriteString(w, s)
53 if err != nil || n != len(s) {
54 t.Errorf("%d. WriteString(%q) = %v, %v; want %v, %v", i, s, n, err, len(s), nil)
57 if got := string(w.Bytes()); got != tt.want {
58 t.Errorf("%d. Bytes = %q; want %q", i, got, tt.want)