github.com/dolthub/go-mysql-server@v0.18.0/optgen/cmd/support/frame_gen_test.go (about) 1 package support 2 3 import ( 4 "bytes" 5 "fmt" 6 "strings" 7 "testing" 8 ) 9 10 func TestFrameGen(t *testing.T) { 11 test := struct { 12 expected string 13 }{ 14 expected: ` 15 import ( 16 "github.com/dolthub/go-mysql-server/sql" 17 agg "github.com/dolthub/go-mysql-server/sql/expression/function/aggregation" 18 ) 19 20 type RowsUnboundedPrecedingToNPrecedingFrame struct { 21 windowFrameBase 22 } 23 24 var _ sql.WindowFrame = (*RowsUnboundedPrecedingToNPrecedingFrame)(nil) 25 26 func NewRowsUnboundedPrecedingToNPrecedingFrame(endNPreceding sql.Expression) *RowsUnboundedPrecedingToNPrecedingFrame { 27 return &RowsUnboundedPrecedingToNPrecedingFrame{ 28 windowFrameBase{ 29 isRows: true, 30 unboundedPreceding: true, 31 endNPreceding: endNPreceding, 32 }, 33 } 34 } 35 36 func (f *RowsUnboundedPrecedingToNPrecedingFrame) UnboundedPreceding() bool { 37 return f.unboundedPreceding 38 } 39 40 func (f *RowsUnboundedPrecedingToNPrecedingFrame) StartNPreceding() sql.Expression { 41 return f.startNPreceding 42 } 43 44 func (f *RowsUnboundedPrecedingToNPrecedingFrame) StartCurrentRow() bool { 45 return f.startCurrentRow 46 } 47 48 func (f *RowsUnboundedPrecedingToNPrecedingFrame) StartNFollowing() sql.Expression { 49 return f.startNFollowing 50 } 51 52 func (f *RowsUnboundedPrecedingToNPrecedingFrame) EndNPreceding() sql.Expression { 53 return f.endNPreceding 54 } 55 56 func (f *RowsUnboundedPrecedingToNPrecedingFrame) EndCurrentRow() bool { 57 return f.endCurrentRow 58 } 59 60 func (f *RowsUnboundedPrecedingToNPrecedingFrame) EndNFollowing() sql.Expression { 61 return f.endNFollowing 62 } 63 64 func (f *RowsUnboundedPrecedingToNPrecedingFrame) UnboundedFollowing() bool { 65 return f.unboundedFollowing 66 } 67 68 func (f *RowsUnboundedPrecedingToNPrecedingFrame) NewFramer(w *sql.WindowDefinition) (sql.WindowFramer, error) { 69 return agg.NewRowsUnboundedPrecedingToNPrecedingFramer(f, w) 70 } 71 `, 72 } 73 74 gen := FrameGen{limit: 1} 75 var buf bytes.Buffer 76 gen.Generate(nil, &buf) 77 78 if testing.Verbose() { 79 fmt.Printf("\n=>\n\n%s\n", buf.String()) 80 } 81 82 if !strings.Contains(removeWhitespace(buf.String()), removeWhitespace(test.expected)) { 83 t.Fatalf("\nexpected:\n%s\nactual:\n%s", test.expected, buf.String()) 84 } 85 }