Personal Git forge.

Code git clone ssh://git.poy.ooo:6969/~poyo/farga ZIP
lib/mime/mime_test.go / 1KiB #530beece
Raw
package mimeimport (	"strings"	"testing")func TestType(t *testing.T) {	if got := Type([]byte("hello world")); !strings.HasPrefix(got, "text/plain") {		t.Errorf("Type(text) = %q, want text/plain prefix", got)	}	if got := Type([]byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a}); !strings.HasPrefix(got, "image/png") {		t.Errorf("Type(png bytes) = %q, want image/png prefix", got)	}}func TestIsImage(t *testing.T) {	if !IsImage("image/png") {		t.Error("IsImage(image/png) = false, want true")	}	if !IsImage("image/svg+xml") {		t.Error("IsImage(image/svg+xml) = false, want true")	}	if IsImage("text/html") {		t.Error("IsImage(text/html) = true, want false")	}	if IsImage("") {		t.Error("IsImage(empty) = true, want false")	}}func TestIsVideo(t *testing.T) {	if !IsVideo("video/mp4") {		t.Error("IsVideo(video/mp4) = false, want true")	}	if IsVideo("image/png") {		t.Error("IsVideo(image/png) = true, want false")	}}func TestIsText(t *testing.T) {	if !IsText("text/html") {		t.Error("IsText(text/html) = false, want true")	}	if IsText("application/json") {		t.Error("IsText(application/json) = true, want false")	}}func TestDataURI(t *testing.T) {	got := DataURI([]byte("hi"), "text/plain")	if got != "data:text/plain;base64,aGk=" {		t.Errorf("DataURI = %q, want data:text/plain;base64,aGk=", got)	}}func TestSrc(t *testing.T) {	got := Src([]byte("hi"), "text/plain")	if string(got) != "data:text/plain;base64,aGk=" {		t.Errorf("Src = %q, want the data URI", got)	}}func TestToStr(t *testing.T) {	if ToStr([]byte("hi")) != "hi" {		t.Error("ToStr = not \"hi\"")	}}