]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgo/go/strconv/atob_test.go
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/gcc.git] / libgo / go / strconv / atob_test.go
1 // Copyright 2009 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.
4
5 package strconv_test
6
7 import (
8 "os"
9 . "strconv"
10 "testing"
11 )
12
13 type atobTest struct {
14 in string
15 out bool
16 err os.Error
17 }
18
19 var atobtests = []atobTest{
20 {"", false, os.EINVAL},
21 {"asdf", false, os.EINVAL},
22 {"0", false, nil},
23 {"f", false, nil},
24 {"F", false, nil},
25 {"FALSE", false, nil},
26 {"false", false, nil},
27 {"1", true, nil},
28 {"t", true, nil},
29 {"T", true, nil},
30 {"TRUE", true, nil},
31 {"true", true, nil},
32 }
33
34 func TestAtob(t *testing.T) {
35 for _, test := range atobtests {
36 b, e := Atob(test.in)
37 if test.err != nil {
38 // expect an error
39 if e == nil {
40 t.Errorf("%s: expected %s but got nil", test.in, test.err)
41 } else {
42 // NumError assertion must succeed; it's the only thing we return.
43 if test.err != e.(*NumError).Error {
44 t.Errorf("%s: expected %s but got %s", test.in, test.err, e)
45 }
46 }
47 } else {
48 if e != nil {
49 t.Errorf("%s: expected no error but got %s", test.in, test.err, e)
50 }
51 if b != test.out {
52 t.Errorf("%s: expected %t but got %t", test.in, test.out, b)
53 }
54 }
55 }
56 }