all repos — emoji @ v0.0.5

A minimalistic emoji package for Go (golang)

fmt_test.go (view raw)

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