github.com/searKing/golang/go@v1.2.74/bufio/pair_test.go (about) 1 // Copyright 2020 The searKing Author. 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 bufio 6 7 import ( 8 "bytes" 9 "strings" 10 "testing" 11 ) 12 13 var pairTests = []string{ 14 "", 15 "{abc}", 16 "{abc}sss", 17 "{a[b]c}", 18 "}{abc}", 19 } 20 var espectedpairTests = []string{ 21 "", 22 "{abc}", 23 "{abc}", 24 "{a[b]c}", 25 "{abc}", 26 } 27 28 func TestPairScanner(t *testing.T) { 29 30 for n, test := range pairTests { 31 buf := strings.NewReader(test) 32 s := NewPairScanner(buf).SetDiscardLeading(true) 33 p, err := s.ScanDelimiters("{}") 34 if err != nil && n != 0 { 35 t.Errorf("#%d: Scan error:%v\n", n, err) 36 continue 37 } 38 39 if !bytes.Equal(p, []byte(espectedpairTests[n])) { 40 t.Errorf("#%d: expected %q got %q", n, test, string(p)) 41 } 42 } 43 }