MCPcopy
hub / github.com/mum4k/termdash / TestCell

Function TestCell

private/canvas/canvas_test.go:906–973  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

904}
905
906func TestCell(t *testing.T) {
907 tests := []struct {
908 desc string
909 cvs func() (*Canvas, error)
910 point image.Point
911 want *buffer.Cell
912 wantErr bool
913 }{
914 {
915 desc: "requested point falls outside of the canvas",
916 cvs: func() (*Canvas, error) {
917 cvs, err := New(image.Rect(0, 0, 1, 1))
918 if err != nil {
919 return nil, err
920 }
921 return cvs, nil
922 },
923 point: image.Point{1, 1},
924 wantErr: true,
925 },
926 {
927 desc: "returns the cell",
928 cvs: func() (*Canvas, error) {
929 cvs, err := New(image.Rect(0, 0, 2, 2))
930 if err != nil {
931 return nil, err
932 }
933 if _, err := cvs.SetCell(
934 image.Point{1, 1}, 'A',
935 cell.FgColor(cell.ColorRed),
936 cell.BgColor(cell.ColorBlue),
937 ); err != nil {
938 return nil, err
939 }
940 return cvs, nil
941 },
942 point: image.Point{1, 1},
943 want: &buffer.Cell{
944 Rune: 'A',
945 Opts: cell.NewOptions(
946 cell.FgColor(cell.ColorRed),
947 cell.BgColor(cell.ColorBlue),
948 ),
949 },
950 },
951 }
952
953 for _, tc := range tests {
954 t.Run(tc.desc, func(t *testing.T) {
955 cvs, err := tc.cvs()
956 if err != nil {
957 t.Fatalf("tc.cvs => unexpected error: %v", err)
958 }
959
960 got, err := cvs.Cell(tc.point)
961 if (err != nil) != tc.wantErr {
962 t.Errorf("Cell => unexpected error: %v, wantErr: %v", err, tc.wantErr)
963 }

Callers

nothing calls this directly

Calls 7

FgColorFunction · 0.92
BgColorFunction · 0.92
NewOptionsFunction · 0.92
RunMethod · 0.80
CellMethod · 0.80
NewFunction · 0.70
SetCellMethod · 0.65

Tested by

no test coverage detected