package main

import (
	"testing"
)

func TestTrimAllNewlines(t *testing.T) {
	trimmed := trimAllNewlines("\nfoo\n")
	if trimmed != "foo" {
		t.Fatalf("failed to trimmed new line from '\\nfoo\\n'")
	}
}

func TestParseMtype(t *testing.T) {
	mtype := "os/directory"
	ftype, stype, err := parseMtype(mtype)
	if ftype != "os" || stype != "directory" {
		t.Fatalf("unable to parse %s", mtype)
	}

	mtype = "image/gif; charset=utf-8"
	ftype, stype, err = parseMtype(mtype)
	if err != nil {
		t.Fatalf("failed to parse %s", mtype)
	}
	if ftype != "image" || stype != "gif" {
		t.Fatalf("unable to parse %s", mtype)
	}

	mtype = "notamimetype"
	ftype, stype, err = parseMtype(mtype)
	if err == nil {
		t.Fatalf("failed to error out correctly parsing %s", mtype)
	}
}
