Gitfed
bastien-mrq/gitfed / cmd / gitfed-web / render_test.go
package main

import "testing"

func TestFileIcon(t *testing.T) {
	cases := []struct {
		name string
		want string
	}{
		{"main.go", "file-code"},
		{"index.tsx", "file-code"},
		{"script.sh", "file-code"},
		{"README.md", "file-doc"},
		{"README", "file-doc"},
		{"LICENSE", "file-doc"},
		{"notes.txt", "file-doc"},
		{"logo.png", "file-image"},
		{"photo.JPEG", "file-image"},
		{"config.yaml", "file-config"},
		{"package.json", "file-config"},
		{".gitignore", "file"},
		{"Makefile", "file"},
		{"data.bin", "file"},
	}
	for _, c := range cases {
		if got := fileIcon(c.name); got != c.want {
			t.Errorf("fileIcon(%q) = %q, want %q", c.name, got, c.want)
		}
	}
}

func TestHumanBytes(t *testing.T) {
	cases := []struct {
		n    int64
		want string
	}{
		{0, "0 B"},
		{1, "1 B"},
		{1023, "1023 B"},
		{1024, "1.0 KiB"},
		{1536, "1.5 KiB"},
		{1024 * 1024, "1.0 MiB"},
		{1024*1024*1024*3 + 1024*1024*512, "3.5 GiB"},
	}
	for _, c := range cases {
		if got := humanBytes(c.n); got != c.want {
			t.Errorf("humanBytes(%d) = %q, want %q", c.n, got, c.want)
		}
	}
}