* gcc-interface/decl.c (warn_on_field_placement): Issue the warning
[official-gcc.git] / libgo / go / net / parse_test.go
blobc5f8bfd198ce4f519beae58f25407ffe747b44cb
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.
5 package net
7 import (
8 "bufio"
9 "os"
10 "runtime"
11 "testing"
14 func TestReadLine(t *testing.T) {
15 // /etc/services file does not exist on android, plan9, windows.
16 switch runtime.GOOS {
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)
23 if err != nil {
24 t.Fatal(err)
26 defer fd.Close()
27 br := bufio.NewReader(fd)
29 file, err := open(filename)
30 if file == nil {
31 t.Fatal(err)
33 defer file.close()
35 lineno := 1
36 byteno := 0
37 for {
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)
46 if !ok {
47 break
49 lineno++
50 byteno += len(line) + 1
54 func TestGoDebugString(t *testing.T) {
55 defer os.Setenv("GODEBUG", os.Getenv("GODEBUG"))
56 tests := []struct {
57 godebug string
58 key string
59 want string
61 {"", "foo", ""},
62 {"foo=", "foo", ""},
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"},
68 {"foo=", "foo", ""},
69 {"foo", "foo", ""},
70 {",foo", "foo", ""},
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 {
83 in string
84 out int
85 off int
86 ok bool
88 {"", 0, 0, false},
89 {"0", 0, 1, true},
90 {"65536", 65536, 5, true},
91 {"123456789", big, 8, false},
92 {"-0", 0, 0, false},
93 {"-1234", 0, 0, false},
94 } {
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)