github.com/searKing/golang/go@v1.2.117/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}{def}", 17 "{abc{def}hij}", 18 "sss{abc}", 19 "{abc}eee", 20 "sss{abc}eee", 21 "{a[b]c}", 22 "}{abc}", 23 } 24 var expectedPairTests = []string{ 25 "", 26 "{abc}", 27 "{abc}", 28 "{abc{def}hij}", 29 "{abc}", 30 "{abc}", 31 "{abc}", 32 "{a[b]c}", 33 "{abc}", 34 } 35 36 func TestPairScanner(t *testing.T) { 37 for i, test := range pairTests { 38 s := NewPairScanner(strings.NewReader(test)).SetDiscardLeading(true) 39 p, err := s.ScanDelimiters("{}") 40 if err != nil && i != 0 { 41 t.Errorf("#%d: Scan error:%v\n", i, err) 42 continue 43 } 44 45 if !bytes.Equal(p, []byte(expectedPairTests[i])) { 46 t.Errorf("#%d: expected %q got %q", i, test, string(p)) 47 } 48 } 49 }