gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/echo/echo_test.go (about)

     1  // Copyright 2015-2017 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  package main
     6  
     7  import (
     8  	"bytes"
     9  	"testing"
    10  )
    11  
    12  func TestEcho(t *testing.T) {
    13  	type test struct {
    14  		s string
    15  		r string
    16  		f flags
    17  	}
    18  	var buf bytes.Buffer
    19  	tests := []test{
    20  		{s: "simple test1", r: "simple test1", f: flags{noNewline: true}},
    21  		{s: "simple test2", r: "simple test2\n", f: flags{}},
    22  		{s: "simple\\ttest3", r: "simple\ttest3\n", f: flags{interpretEscapes: true}},
    23  		{s: "simple\\ttest4", r: "simple\ttest4\n", f: flags{interpretEscapes: true}},
    24  		{s: "simple\\tte\\cst5", r: "simple\tte\n", f: flags{interpretEscapes: true}},
    25  		{s: "simple\\tte\\cst6", r: "simple\tte", f: flags{true, true}},
    26  		{s: "simple\\x56 test7", r: "simpleV test7", f: flags{true, true}},
    27  		{s: "simple\\x56 \\0113test7", r: "simpleV Ktest7", f: flags{true, true}},
    28  		{s: "\\\\8", r: "\\8", f: flags{true, true}},
    29  	}
    30  
    31  	for _, v := range tests {
    32  		if err := echo(v.f, &buf, v.s); err != nil {
    33  			t.Errorf("%s", err)
    34  		}
    35  		if buf.String() != v.r {
    36  			t.Fatalf("Want \"%v\", got \"%v\"", v.r, buf.String())
    37  		}
    38  		buf.Reset()
    39  	}
    40  }