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.
14 func TestReadLine(t
*testing
.T
) {
15 // /etc/services file does not exist on android, plan9, windows.
17 case "android", "plan9", "windows":
18 t
.Skipf("not supported on %s", runtime
.GOOS
)
20 filename
:= "/etc/services" // a nice big file
22 fd
, err
:= os
.Open(filename
)
27 br
:= bufio
.NewReader(fd
)
29 file
, err
:= open(filename
)
38 bline
, berr
:= br
.ReadString('\n')
39 if n
:= len(bline
); n
> 0 {
40 bline
= bline
[0 : n
-1]
42 line
, ok
:= file
.readLine()
43 if (berr
!= nil) != !ok || bline
!= line
{
44 t
.Fatalf("%s:%d (#%d)\nbufio => %q, %v\nnet => %q, %v", filename
, lineno
, byteno
, bline
, berr
, line
, ok
)
50 byteno
+= len(line
) + 1
54 func TestGoDebugString(t
*testing
.T
) {
55 defer os
.Setenv("GODEBUG", os
.Getenv("GODEBUG"))
63 {"foo=bar", "foo", "bar"},
64 {"foo=bar,", "foo", "bar"},
65 {"foo,foo=bar,", "foo", "bar"},
66 {"foo1=bar,foo=bar,", "foo", "bar"},
67 {"foo=bar,foo=bar,", "foo", "bar"},
71 {"foo=bar,baz", "loooooooong", ""},
73 for _
, tt
:= range tests
{
74 os
.Setenv("GODEBUG", tt
.godebug
)
75 if got
:= goDebugString(tt
.key
); got
!= tt
.want
{
76 t
.Errorf("for %q, goDebugString(%q) = %q; want %q", tt
.godebug
, tt
.key
, got
, tt
.want
)
81 func TestDtoi(t
*testing
.T
) {
82 for _
, tt
:= range []struct {
90 {"65536", 65536, 5, true},
91 {"123456789", big
, 8, false},
93 {"-1234", 0, 0, false},
95 n
, i
, ok
:= dtoi(tt
.in
)
96 if n
!= tt
.out || i
!= tt
.off || ok
!= tt
.ok
{
97 t
.Errorf("got %d, %d, %v; want %d, %d, %v", n
, i
, ok
, tt
.out
, tt
.off
, tt
.ok
)