1// Copyright 2018 Google Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Package testdraw provides helpers for tests that use the draw package. 16package testdraw 17 18import ( 19 "fmt" 20 "image" 21 22 "github.com/mum4k/termdash/private/canvas" 23 "github.com/mum4k/termdash/private/canvas/braille" 24 "github.com/mum4k/termdash/private/draw" 25) 26 27// MustBorder draws border on the canvas or panics. 28func MustBorder(c *canvas.Canvas, border image.Rectangle, opts ...draw.BorderOption) { 29 if err := draw.Border(c, border, opts...); err != nil { 30 panic(fmt.Sprintf("draw.Border => unexpected error: %v", err)) 31 } 32} 33 34// MustText draws the text on the canvas or panics. 35func MustText(c *canvas.Canvas, text string, start image.Point, opts ...draw.TextOption) { 36 if err := draw.Text(c, text, start, opts...); err != nil { 37 panic(fmt.Sprintf("draw.Text => unexpected error: %v", err)) 38 } 39} 40 41// MustVerticalText draws the vertical text on the canvas or panics. 42func MustVerticalText(c *canvas.Canvas, text string, start image.Point, opts ...draw.VerticalTextOption) { 43 if err := draw.VerticalText(c, text, start, opts...); err != nil { 44 panic(fmt.Sprintf("draw.VerticalText => unexpected error: %v", err)) 45 } 46} 47 48// MustRectangle draws the rectangle on the canvas or panics. 49func MustRectangle(c *canvas.Canvas, r image.Rectangle, opts ...draw.RectangleOption) { 50 if err := draw.Rectangle(c, r, opts...); err != nil { 51 panic(fmt.Sprintf("draw.Rectangle => unexpected error: %v", err)) 52 } 53} 54 55// MustHVLines draws the vertical / horizontal lines or panics. 56func MustHVLines(c *canvas.Canvas, lines []draw.HVLine, opts ...draw.HVLineOption) { 57 if err := draw.HVLines(c, lines, opts...); err != nil { 58 panic(fmt.Sprintf("draw.HVLines => unexpected error: %v", err)) 59 } 60} 61 62// MustBrailleLine draws the braille line or panics. 63func MustBrailleLine(bc *braille.Canvas, start, end image.Point, opts ...draw.BrailleLineOption) { 64 if err := draw.BrailleLine(bc, start, end, opts...); err != nil { 65 panic(fmt.Sprintf("draw.BrailleLine => unexpected error: %v", err)) 66 } 67} 68 69// MustBrailleCircle draws the braille circle or panics. 70func MustBrailleCircle(bc *braille.Canvas, mid image.Point, radius int, opts ...draw.BrailleCircleOption) { 71 if err := draw.BrailleCircle(bc, mid, radius, opts...); err != nil { 72 panic(fmt.Sprintf("draw.BrailleCircle => unexpected error: %v", err)) 73 } 74} 75 76// MustResizeNeeded draws the character or panics. 77func MustResizeNeeded(cvs *canvas.Canvas) { 78 if err := draw.ResizeNeeded(cvs); err != nil { 79 panic(fmt.Sprintf("draw.ResizeNeeded => unexpected error: %v", err)) 80 } 81} 82