// Verify that calling Scan() provides the correct results.

Verify that calling Scan() provides the correct results.
// Verify that calling Scan () provides the correct results .
func TestScan(t *testing.T) {
	var src string
	for _, e := range tokens {
		src += e.lit + whitespace
	}
	src_linecount := newlineCount(src)
	whitespace_linecount := newlineCount(whitespace)
	var s Scanner
	s.Init(fset.AddFile("", fset.Base(), len(src)), []byte(src), &testErrorHandler{t}, ScanComments)
	index := 0
	epos := token.Position{"", 0, 1, 1} 
	for {
		pos, tok, lit := s.Scan()
		e := elt{token.EOF, "", special}
		if index < len(tokens) {
			e = tokens[index]
		}
		if tok == token.EOF {
			lit = "<EOF>"
			epos.Line = src_linecount
			epos.Column = 2
		}
		checkPos(t, lit, pos, epos)
		if tok != e.tok {
			t.Errorf("bad token for %q: got %s, expected %s", lit, tok.String(), e.tok.String())
		}
		if e.tok.IsLiteral() && lit != e.lit {
			t.Errorf("bad literal for %q: got %q, expected %q", lit, lit, e.lit)
		}
		if tokenclass(tok) != e.class {
			t.Errorf("bad class for %q: got %d, expected %d", lit, tokenclass(tok), e.class)
		}
		epos.Offset += len(lit) + len(whitespace)
		epos.Line += newlineCount(lit) + whitespace_linecount
		if tok == token.COMMENT && lit[1] == '/' {
			epos.Offset++
			epos.Line++
		}
		index++
		if tok == token.EOF {
			break
		}
	}
	if s.ErrorCount != 0 {
		t.Errorf("found %d errors", s.ErrorCount)
	}
}
func TestScan ( t * testing . T ) { var src string for _ , e := range tokens { src += e . lit + whitespace } src_linecount := newlineCount ( src ) whitespace_linecount := newlineCount ( whitespace ) var s Scanner s . Init ( fset . AddFile ( " " , fset . Base ( ) , len ( src ) ) , [ ] byte ( src ) , & testErrorHandler { t } , ScanComments ) index := 0 epos := token . Position { " " , 0 , 1 , 1 } for { pos , tok , lit := s . Scan ( ) e := elt { token . EOF , " " , special } if index < len ( tokens ) { e = tokens [ index ] } if tok == token . EOF { lit = " " epos . Line = src_linecount epos . Column = 2 } checkPos ( t , lit , pos , epos ) if tok != e . tok { t . Errorf ( " " , lit , tok . String ( ) , e . tok . String ( ) ) } if e . tok . IsLiteral ( ) && lit != e . lit { t . Errorf ( " " , lit , lit , e . lit ) } if tokenclass ( tok ) != e . class { t . Errorf ( " " , lit , tokenclass ( tok ) , e . class ) } epos . Offset += len ( lit ) + len ( whitespace ) epos . Line += newlineCount ( lit ) + whitespace_linecount if tok == token . COMMENT && lit [ 1 ] == '/' { epos . Offset ++ epos . Line ++ } index ++ if tok == token . EOF { break } } if s . ErrorCount != 0 { t . Errorf ( " " , s . ErrorCount ) } }
Verify that calling Scan() provides the correct results.
Verify that calling Scan () provides the correct results .
// make source
 // verify scan
 // expected position
 // correct for unaccounted '/n' in //-style comment
