OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [parse_test.go] - Blame information for rev 858

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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 net
6
 
7
import (
8
        "bufio"
9
        "os"
10
        "runtime"
11
        "testing"
12
)
13
 
14
func TestReadLine(t *testing.T) {
15
        // /etc/services file does not exist on windows and Plan 9.
16
        if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
17
                return
18
        }
19
        filename := "/etc/services" // a nice big file
20
 
21
        fd, err := os.Open(filename)
22
        if err != nil {
23
                t.Fatalf("open %s: %v", filename, err)
24
        }
25
        br := bufio.NewReader(fd)
26
 
27
        file, err := open(filename)
28
        if file == nil {
29
                t.Fatalf("net.open(%s) = nil", filename)
30
        }
31
 
32
        lineno := 1
33
        byteno := 0
34
        for {
35
                bline, berr := br.ReadString('\n')
36
                if n := len(bline); n > 0 {
37
                        bline = bline[0 : n-1]
38
                }
39
                line, ok := file.readLine()
40
                if (berr != nil) != !ok || bline != line {
41
                        t.Fatalf("%s:%d (#%d)\nbufio => %q, %v\nnet => %q, %v",
42
                                filename, lineno, byteno, bline, berr, line, ok)
43
                }
44
                if !ok {
45
                        break
46
                }
47
                lineno++
48
                byteno += len(line) + 1
49
        }
50
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.