mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
host and port name lookup
R=r,presotto DELTA=1239 (935 added, 281 deleted, 23 changed) OCL=21041 CL=21539
This commit is contained in:
parent
e29ce175ed
commit
83348f956e
15 changed files with 886 additions and 244 deletions
46
src/lib/net/parse_test.go
Normal file
46
src/lib/net/parse_test.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
"bufio";
|
||||
"net";
|
||||
"os";
|
||||
"testing";
|
||||
)
|
||||
|
||||
export func TestReadLine(t *testing.T) {
|
||||
filename := "/etc/services"; // a nice big file
|
||||
|
||||
fd, err := os.Open(filename, os.O_RDONLY, 0);
|
||||
if err != nil {
|
||||
t.Fatalf("open %s: %v", filename, err);
|
||||
}
|
||||
br, err1 := bufio.NewBufRead(fd);
|
||||
if err1 != nil {
|
||||
t.Fatalf("bufio.NewBufRead: %v", err1);
|
||||
}
|
||||
|
||||
file := Open(filename);
|
||||
if file == nil {
|
||||
t.Fatalf("net.Open(%s) = nil", filename);
|
||||
}
|
||||
|
||||
lineno := 1;
|
||||
byteno := 0;
|
||||
for {
|
||||
bline, berr := br.ReadLineString('\n', false);
|
||||
line, ok := file.ReadLine();
|
||||
if (berr != nil) != !ok || bline != line {
|
||||
t.Fatalf("%s:%d (#%d)\nbufio => %q, %v\nnet => %q, %v",
|
||||
filename, lineno, byteno, bline, berr, line, ok);
|
||||
}
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
lineno++;
|
||||
byteno += len(line) + 1;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue