github.com/dolthub/go-mysql-server@v0.18.0/optgen/cmd/support/framer_gen_test.go (about) 1 package support 2 3 import ( 4 "bytes" 5 "fmt" 6 "strings" 7 "testing" 8 ) 9 10 func TestFramerGen(t *testing.T) { 11 test := struct { 12 expected string 13 }{ 14 expected: ` 15 import ( 16 "github.com/dolthub/go-mysql-server/sql" 17 "github.com/dolthub/go-mysql-server/sql/expression" 18 ) 19 20 type RowsUnboundedPrecedingToNPrecedingFramer struct { 21 rowFramerBase 22 } 23 24 var _ sql.WindowFramer = (*RowsUnboundedPrecedingToNPrecedingFramer)(nil) 25 26 func NewRowsUnboundedPrecedingToNPrecedingFramer(frame sql.WindowFrame, window *sql.WindowDefinition) (sql.WindowFramer, error) { 27 unboundedPreceding := true 28 endNPreceding, err := expression.LiteralToInt(frame.EndNPreceding()) 29 if err != nil { 30 return nil, err 31 } 32 return &RowsUnboundedPrecedingToNPrecedingFramer{ 33 rowFramerBase{ 34 unboundedPreceding: unboundedPreceding, 35 endNPreceding: endNPreceding, 36 }, 37 }, nil 38 } 39 `, 40 } 41 42 gen := FramerGen{limit: 1} 43 var buf bytes.Buffer 44 gen.Generate(nil, &buf) 45 46 if testing.Verbose() { 47 fmt.Printf("\n=>\n\n%s\n", buf.String()) 48 } 49 50 if !strings.Contains(removeWhitespace(buf.String()), removeWhitespace(test.expected)) { 51 t.Fatalf("\nexpected:\n%s\nactual:\n%s", test.expected, buf.String()) 52 } 53 }