// Verify that initializing the same scanner more then once works correctly.

Verify that initializing the same scanner more then once works correctly.
// Verify that initializing the same scanner more then once works correctly .
func TestInit(t *testing.T) {
	var s Scanner
	src1 := "if true { }"
	f1 := fset.AddFile("src1", fset.Base(), len(src1))
	s.Init(f1, []byte(src1), nil, 0)
	if f1.Size() != len(src1) {
		t.Errorf("bad file size: got %d, expected %d", f1.Size(), len(src1))
	}
	s.Scan()              
	s.Scan()              
	_, tok, _ := s.Scan() 
	if tok != token.LBRACE {
		t.Errorf("bad token: got %s, expected %s", tok.String(), token.LBRACE)
	}
	src2 := "go true { ]"
	f2 := fset.AddFile("src2", fset.Base(), len(src2))
	s.Init(f2, []byte(src2), nil, 0)
	if f2.Size() != len(src2) {
		t.Errorf("bad file size: got %d, expected %d", f2.Size(), len(src2))
	}
	_, tok, _ = s.Scan() 
	if tok != token.GO {
		t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO)
	}
	if s.ErrorCount != 0 {
		t.Errorf("found %d errors", s.ErrorCount)
	}
}
func TestInit ( t * testing . T ) { var s Scanner src1 := " " f1 := fset . AddFile ( " " , fset . Base ( ) , len ( src1 ) ) s . Init ( f1 , [ ] byte ( src1 ) , nil , 0 ) if f1 . Size ( ) != len ( src1 ) { t . Errorf ( " " , f1 . Size ( ) , len ( src1 ) ) } s . Scan ( ) s . Scan ( ) _ , tok , _ := s . Scan ( ) if tok != token . LBRACE { t . Errorf ( " " , tok . String ( ) , token . LBRACE ) } src2 := " " f2 := fset . AddFile ( " " , fset . Base ( ) , len ( src2 ) ) s . Init ( f2 , [ ] byte ( src2 ) , nil , 0 ) if f2 . Size ( ) != len ( src2 ) { t . Errorf ( " " , f2 . Size ( ) , len ( src2 ) ) } _ , tok , _ = s . Scan ( ) if tok != token . GO { t . Errorf ( " " , tok . String ( ) , token . GO ) } if s . ErrorCount != 0 { t . Errorf ( " " , s . ErrorCount ) } }
Verify that initializing the same scanner more then once works correctly.
Verify that initializing the same scanner more then once works correctly .
// 1st init
 // if
 // true
 // {
 // 2nd init
 // go
