summaryrefslogtreecommitdiff
path: root/go/series/asktoomuch_test.go
blob: e29703a2ef27ab5ad8836e6d9c76e489ff661e8c (plain)
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
// +build asktoomuch

package slice

import "testing"

func TestAskTooMuch(t *testing.T) {
	test := allTests[0]
	defer func() {
		if recover() != nil {
			t.Fatalf("Yikes, UnsafeFirst(%d, %s) panicked!", test.n, test.s)
		}
	}()
	for _, test = range allTests {
		switch res := UnsafeFirst(test.n, test.s); {
		case len(test.out) > 0: // well, this should work
			if res != test.out[0] {
				t.Fatalf("Yikes, UnsafeFirst(%d, %s) = %q, want %q.",
					test.n, test.s, res, test.out[0])
			}
		case len(res) != test.n:
			t.Fatalf("Yikes, UnsafeFirst(%d, %s) = %q, but %q doesn't have %d characters.",
				test.n, test.s, res, res, test.n)
		default:
			t.Fatalf("Yikes, UnsafeFirst(%d, %s) = %q, but %q isn't in %q",
				test.n, test.s, res, res, test.s)
		}
	}
}