gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/parser/line-parser_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"os"
     7  	"testing"
     8  )
     9  
    10  func TestLineParser(t *testing.T) {
    11  	lp := &LineParser{
    12  		MaxLineSize: 1300,
    13  	}
    14  	file, err := os.Open("parser.go")
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	defer file.Close()
    19  
    20  	var chunks [][]byte
    21  	for {
    22  		buf := make([]byte, 1)
    23  		n, err := file.Read(buf)
    24  		if err != nil {
    25  			if err == io.EOF {
    26  				break
    27  			}
    28  			t.Fatal(err)
    29  		}
    30  		chunks = append(chunks, buf[:n])
    31  	}
    32  
    33  	var okCount int
    34  	var errCount int
    35  	for i := 0; i < 200000; i++ {
    36  		for _, chunk := range chunks {
    37  			for len(chunk) > 0 {
    38  				ok, err := lp.ParseP(chunk, &chunk)
    39  				if ok {
    40  					okCount++
    41  				}
    42  				if err != nil {
    43  					errCount++
    44  				}
    45  			}
    46  		}
    47  	}
    48  	fmt.Println(okCount)
    49  	fmt.Println(errCount)
    50  }