2018-04-15 06:06:57 +08:00
|
|
|
// Copyright 2018 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-04-07 20:24:55 +08:00
|
|
|
// Package testdraw provides helpers for tests that use the draw package.
|
|
|
|
package testdraw
|
|
|
|
|
|
|
|
import (
|
2018-05-07 02:28:52 +08:00
|
|
|
"fmt"
|
2018-04-07 20:24:55 +08:00
|
|
|
"image"
|
|
|
|
|
|
|
|
"github.com/mum4k/termdash/canvas"
|
|
|
|
"github.com/mum4k/termdash/cell"
|
|
|
|
"github.com/mum4k/termdash/draw"
|
|
|
|
)
|
|
|
|
|
2018-05-07 20:33:18 +08:00
|
|
|
// MustBorder draws border on the canvas or panics.
|
|
|
|
func MustBorder(c *canvas.Canvas, border image.Rectangle, opts ...draw.BorderOption) {
|
|
|
|
if err := draw.Border(c, border, opts...); err != nil {
|
|
|
|
panic(fmt.Sprintf("draw.Border => unexpected error: %v", err))
|
2018-04-07 20:24:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MustText draws the text on the canvas or panics.
|
|
|
|
func MustText(c *canvas.Canvas, text string, tb draw.TextBounds, opts ...cell.Option) {
|
|
|
|
if err := draw.Text(c, text, tb, opts...); err != nil {
|
2018-05-07 02:28:52 +08:00
|
|
|
panic(fmt.Sprintf("draw.Text => unexpected error: %v", err))
|
2018-04-07 20:24:55 +08:00
|
|
|
}
|
|
|
|
}
|
2018-05-07 19:41:45 +08:00
|
|
|
|
|
|
|
// MustRectangle draws the rectangle on the canvas or panics.
|
|
|
|
func MustRectangle(c *canvas.Canvas, r image.Rectangle, opts ...draw.RectangleOption) {
|
|
|
|
if err := draw.Rectangle(c, r, opts...); err != nil {
|
|
|
|
panic(fmt.Sprintf("draw.Rectangle => unexpected error: %v", err))
|
|
|
|
}
|
|
|
|
}
|