Пример #1
0
func BenchmarkParser(b *testing.B) {
	l := new(js.Lexer)
	p := new(js.Parser)
	onError := func(line, offset, len int, msg string) {
		b.Errorf("%d, %d: %s", line, offset, msg)
	}

	p.Init(onError, func(t js.NodeType, offset, endoffset int) {})
	for i := 0; i < b.N; i++ {
		l.Init(jsBenchmarkCode, onError)
		p.Parse(l)
	}
	b.SetBytes(int64(len(jsBenchmarkCode)))
}
Пример #2
0
func TestParser(t *testing.T) {
	l := new(js.Lexer)
	p := new(js.Parser)

	seen := map[js.NodeType]bool{}
	for _, tc := range parseTests {
		seen[tc.nt] = true
		for _, input := range tc.inputs {
			test := pt.NewParserTest(tc.nt.String(), input, t)
			l.Init(test.Source(), test.Error)
			p.Init(test.Error, func(t js.NodeType, offset, endoffset int) {
				if t == tc.nt {
					test.Consume(offset, endoffset)
				}
			})
			test.Done(p.Parse(l))
		}
	}
	for n := js.NodeType(1); n < js.NodeTypeMax; n++ {
		if !seen[n] {
			t.Errorf("%v is not tested", n)
		}
	}
}