1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
package emoji
import (
"bytes"
"fmt"
"testing"
)
func TestSprint(t *testing.T) {
var (
input = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
expected = fmt.Sprintf("I am %v from %v. Tests are %v", ManTechnologist, FlagForTurkey, ThumbsUp)
)
got := Sprint(input)
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestSprintf(t *testing.T) {
var (
input = "I am :man_technologist:. Tests are :thumbs_up:. %v is formatted."
args = "this string"
expected = fmt.Sprintf("I am %v. Tests are %v. %v is formatted.", ManTechnologist, ThumbsUp, args)
)
got := Sprintf(input, args)
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestSprintln(t *testing.T) {
var (
input = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
expected = fmt.Sprintf("I am %v from %v. Tests are %v\n", ManTechnologist, FlagForTurkey, ThumbsUp)
)
got := Sprintln(input)
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestPrint(t *testing.T) {
var (
input = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
)
n, err := Print(input)
if err != nil || n == 0 {
t.Fatalf("test case fail n: %v: %v", n, err)
}
}
func TestPrintf(t *testing.T) {
var (
input = "I am :man_technologist:. Tests are :thumbs_up:. %v is formatted."
args = "this string"
)
n, err := Printf(input, args)
if err != nil || n == 0 {
t.Fatalf("test case fail n: %v: %v", n, err)
}
}
func TestPrintln(t *testing.T) {
var (
input = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
)
n, err := Println(input)
if err != nil || n == 0 {
t.Fatalf("test case fail n: %v: %v", n, err)
}
}
func TestFprint(t *testing.T) {
var (
input = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
expected = fmt.Sprintf("I am %v from %v. Tests are %v", ManTechnologist, FlagForTurkey, ThumbsUp)
)
var w bytes.Buffer
_, err := Fprint(&w, input)
if err != nil {
t.Fatalf("test case fail: %v", err)
}
got := w.String()
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestFprintf(t *testing.T) {
var (
input = "I am :man_technologist:. Tests are :thumbs_up:. %v is formatted."
args = "this string"
expected = fmt.Sprintf("I am %v. Tests are %v. %v is formatted.", ManTechnologist, ThumbsUp, args)
)
var w bytes.Buffer
_, err := Fprintf(&w, input, args)
if err != nil {
t.Fatalf("test case fail: %v", err)
}
got := w.String()
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestFprintln(t *testing.T) {
var (
input = "I am :man_technologist: from :flag_for_turkey:. Tests are :thumbs_up:"
expected = fmt.Sprintf("I am %v from %v. Tests are %v\n", ManTechnologist, FlagForTurkey, ThumbsUp)
)
var w bytes.Buffer
_, err := Fprintln(&w, input)
if err != nil {
t.Fatalf("test case fail: %v", err)
}
got := w.String()
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
func TestErrorf(t *testing.T) {
var (
input = "I am :man_technologist:. Tests are :thumbs_up:. %v is formatted."
args = "this string"
expected = fmt.Sprintf("I am %v. Tests are %v. %v is formatted.", ManTechnologist, ThumbsUp, args)
)
got := Errorf(input, args).Error()
if got != expected {
t.Fatalf("test case fail: got: %v, expected: %v", got, expected)
}
}
|