package main

import "testing"

func TestDebPackageName(t *testing.T) {
	tests := map[string]string{
		"firefox_120.0_arm64.deb":      "firefox",
		"libgtk-3-0_3.22.30_arm64.deb": "libgtk-3-0",
		"firefox.deb":                  "firefox",
		"plain-package":                "plain-package",
	}

	for input, want := range tests {
		if got := debPackageName(input); got != want {
			t.Fatalf("debPackageName(%q) = %q, want %q", input, got, want)
		}
	}
}

func TestUnsafeFirefoxDebPackages(t *testing.T) {
	packages := []string{
		"firefox",
		"libgtk-3-0",
		"dpkg",
		"coreutils",
		"libc6",
		"tar",
		"dpkg",
	}
	want := []string{"coreutils", "dpkg", "libc6", "tar"}

	got := unsafeFirefoxDebPackages(packages)
	if !stringSlicesEqual(got, want) {
		t.Fatalf("unsafeFirefoxDebPackages() = %v, want %v", got, want)
	}
}

func stringSlicesEqual(left []string, right []string) bool {
	if len(left) != len(right) {
		return false
	}
	for i := range left {
		if left[i] != right[i] {
			return false
		}
	}
	return true
}
