~dricottone/image2ascii

e6d60b6855fbcc079ef7fb6935b99e75fc4d3189 — qeesung 6 years ago 96504dd
add main test case
3 files changed, 45 insertions(+), 4 deletions(-)

M convert/convert.go
M image2ascii.go
A image2ascii_test.go
M convert/convert.go => convert/convert.go +1 -1
@@ 21,7 21,7 @@ type Options struct {
	Colored        bool
}

var defaultOptions = Options{
var DefaultOptions = Options{
	Ratio:          1,
	ExpectedWidth:  -1,
	ExpectedHeight: -1,

M image2ascii.go => image2ascii.go +10 -3
@@ 1,6 1,7 @@
package main

import (
	"errors"
	"flag"
	"fmt"
	"github.com/qeesung/image2ascii/convert"


@@ 28,10 29,16 @@ func init() {

func main() {
	flag.Parse()
	if convertOptions, err := parseOptions(); err == nil {
		fmt.Print(convert.ImageFile2ASCIIString(imageFilename, convertOptions))
	} else {
		usage()
	}
}

func parseOptions() (*convert.Options, error) {
	if imageFilename == "" {
		usage()
		return
		return nil, errors.New("image file should not be empty")
	}
	// config  the options
	convertOptions := &convert.Options{


@@ 41,7 48,7 @@ func main() {
		FitScreen:      fitScreen,
		Colored:        colored,
	}
	fmt.Print(convert.ImageFile2ASCIIString(imageFilename, convertOptions))
	return convertOptions, nil
}

func usage() {

A image2ascii_test.go => image2ascii_test.go +34 -0
@@ 0,0 1,34 @@
package main

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestParseEmptyFilenameOptions(t *testing.T) {
	assertions := assert.New(t)
	imageFilename = ""
	_, err :=parseOptions()
	assertions.True(err != nil)
}

func TestParseOptions(t *testing.T) {
	assertions := assert.New(t)
	imageFilename = "filename"
	ratio = 0.5
	fitScreen = false
	colored = false
	expectedHeight = 100
	expectedWidth = 100
	opt, err :=parseOptions()
	assertions.True(err == nil)
	assertions.Equal(ratio, opt.Ratio)
	assertions.False(fitScreen)
	assertions.False(colored)
	assertions.Equal(expectedWidth, opt.ExpectedWidth)
	assertions.Equal(expectedHeight, opt.ExpectedHeight)
}

func TestParseUsage(t *testing.T) {
	usage()
}