gopkg.in/hugelgupf/u-root.v2@v2.0.0-20180831055005-3f8fdb0ce09d/cmds/ansi/ansi_test.go (about) 1 // Copyright 2016 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // By Manoel Vilela <manoel_vilela@engineer.com> 6 7 package main 8 9 import ( 10 "bytes" 11 "io" 12 "reflect" 13 "testing" 14 ) 15 16 // table of tests for each ansi command 17 // add here more command when needs 18 // {command, expected_escape} 19 var tsts = [][]string{ 20 {"clear", "\033[1;1H\033[2J"}, 21 } 22 23 // Test for each ansi command 24 func TestAnsiCommands(t *testing.T) { 25 for _, tst := range tsts { 26 cmd, wants := tst[0], []byte(tst[1]) 27 b := &bytes.Buffer{} 28 w := io.Writer(b) 29 if err := ansi(w, []string{cmd}); err != nil { 30 t.Error(err) 31 } 32 33 out := b.Bytes() 34 if !reflect.DeepEqual(out, wants) { 35 t.Fatalf("'%v' escape code mismatch; got %v, wants %v", cmd, out, wants) 36 } 37 } 38 }