1// Copyright 2019 Graham Clark. All rights reserved. Use of this source 2// code is governed by the MIT license that can be found in the LICENSE 3// file. 4 5package fill 6 7import ( 8 "strings" 9 "testing" 10 11 "github.com/gcla/gowid" 12 "github.com/gcla/gowid/gwtest" 13 log "github.com/sirupsen/logrus" 14 "github.com/stretchr/testify/assert" 15) 16 17func TestSolidFill1(t *testing.T) { 18 w := New('G') 19 20 c1 := w.Render(gowid.RenderFlowWith{C: 5}, gowid.Focused, gwtest.D) 21 assert.Equal(t, c1.String(), "GGGGG") 22 23 c2 := w.Render(gowid.RenderBox{C: 3, R: 3}, gowid.Focused, gwtest.D) 24 assert.Equal(t, c2.String(), "GGG\nGGG\nGGG") 25 26 assert.Panics(t, func() { 27 w.Render(gowid.RenderFixed{}, gowid.Focused, gwtest.D) 28 }) 29 30 gwtest.RenderBoxManyTimes(t, w, 0, 10, 0, 10) 31} 32 33func TestCanvas21(t *testing.T) { 34 widget1 := New('x') 35 canvas1 := widget1.Render(gowid.RenderFlowWith{C: 6}, gowid.NotSelected, gwtest.D) 36 log.Infof("Widget is %v", widget1) 37 log.Infof("Canvas is %s", canvas1.String()) 38 res := strings.Join([]string{"xxxxxx"}, "\n") 39 if res != canvas1.String() { 40 t.Errorf("Failed") 41 } 42} 43 44func TestCanvas22(t *testing.T) { 45 widget1 := New('x') 46 canvas1 := widget1.Render(gowid.RenderBox{C: 6, R: 3}, gowid.NotSelected, gwtest.D) 47 log.Infof("Widget is %v", widget1) 48 log.Infof("Canvas is %s", canvas1.String()) 49 res := strings.Join([]string{"xxxxxx", "xxxxxx", "xxxxxx"}, "\n") 50 if res != canvas1.String() { 51 t.Errorf("Failed") 52 } 53} 54 55func TestCanvas29(t *testing.T) { 56 widget1 := New('x') 57 canvas1 := widget1.Render(gowid.RenderFlowWith{C: 6}, gowid.NotSelected, gwtest.D) 58 canvas2 := gowid.NewCanvasOfSize(6, 1) 59 canvas2.Lines[0][1] = canvas2.Lines[0][1].WithRune('#') 60 canvas1.MergeUnder(canvas2, 0, 0, false) 61 log.Infof("Widget is %v", widget1) 62 log.Infof("Canvas is %s", canvas1.String()) 63 res := strings.Join([]string{"x#xxxx"}, "\n") 64 if res != canvas1.String() { 65 t.Errorf("Failed") 66 } 67} 68 69//====================================================================== 70// Local Variables: 71// mode: Go 72// fill-column: 110 73// End: 74