github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/test/stackrecurse.go (about) 1 // run 2 3 // Copyright 2016 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 package main 7 8 import ( 9 "fmt" 10 "regexp/syntax" 11 ) 12 13 // Verify that stack growth works as expected for heavily-recursive 14 // functions such as writeRegexp, the one triggered below, when printing a 15 // regex to a buffer. 16 func main() { 17 text := `^x{1,1000}y{1,1000}$` 18 re, err := syntax.Parse(text, syntax.Perl) 19 if err != nil { 20 panic(fmt.Sprintf("parse: %v", err)) 21 } 22 23 sre := re.Simplify() 24 buf := fmt.Sprintf(" %+v\n", sre) 25 if len(buf) != 11993 { 26 panic(fmt.Sprintf("simplified regex not expected length: %d", len(buf))) 27 } 28 }