static int n_tests = 0;
static int n_errors = 0;

int main (string[] args) {
	test_remove_extension ("", "");
	test_remove_extension ("abc", "abc");
	test_remove_extension ("abc.x", "abc");
	test_remove_extension ("abc.xyz", "abc");
	test_remove_extension ("abc.tar", "abc");
	test_remove_extension ("abc.tar.x", "abc");
	test_remove_extension ("abc.tar.xz", "abc");
	test_remove_extension (".hidden", ".hidden");

	test_get_extension ("", null);
	test_get_extension ("abc", null);
	test_get_extension ("abc.x", "x");
	test_get_extension ("abc.xyz", "xyz");
	test_get_extension ("abc.tar", "tar");
	test_get_extension ("abc.tar.x", "tar.x");
	test_get_extension ("abc.tar.xz", "tar.xz");
	test_get_extension (".hidden", null);

	test_get_digits (0, 1);
	test_get_digits (1, 1);
	test_get_digits (9, 1);
	test_get_digits (10, 2);
	test_get_digits (11, 2);
	test_get_digits (99, 2);
	test_get_digits (100, 3);
	test_get_digits (101, 3);
	test_get_digits (12345, 5);
	test_get_digits (-1, 2);
	test_get_digits (-9, 2);
	test_get_digits (-10, 3);
	test_get_digits (-11, 3);
	test_get_digits (-99, 3);
	test_get_digits (-50, 3);
	test_get_digits (-100, 4);
	test_get_digits (-101, 4);

	test_uri_from_path ("", "file://");
	test_uri_from_path ("/", "file:///");
	test_uri_from_path ("/a", "file:///a");
	test_uri_from_path ("/a/", "file:///a/");
	test_uri_from_path ("/a/b", "file:///a/b");
	test_uri_from_path ("/a/b c", "file:///a/b%20c");
	test_uri_from_path ("/a/b:c", "file:///a/b%3Ac");
	test_uri_from_path ("/日/本", "file:///日/本");

	test_get_duplicated ("file:///abc.txt", "file:///abc-2.txt");
	test_get_duplicated ("file:///abc-2.txt", "file:///abc-3.txt");
	test_get_duplicated ("file:///abc--2.txt", "file:///abc--3.txt");
	test_get_duplicated ("file:///abc-.txt", "file:///abc--2.txt");
	test_get_duplicated ("file:///abc-x.txt", "file:///abc-x-2.txt");
	test_get_duplicated ("file:///.txt", "file:///-2.txt");

	test_get_basename ("file.txt", "file.txt");
	test_get_basename ("/dir/file.txt", "file.txt");
	test_get_basename ("/dir/", "");
	test_get_basename ("/", "");
	test_get_basename ("", "");

	test_build_destination_dir ("file:///a.txt", "file:///", "file:///x", "file:///x/a.txt");
	test_build_destination_dir ("file:///a.txt", "file:///", "file:///x/y/z", "file:///x/y/z/a.txt");
	test_build_destination_dir ("file:///a/b/c.txt", "file:///", "file:///x", "file:///x/a/b/c.txt");
	test_build_destination_dir ("file:///a/b/c.txt", "file:///a", "file:///x", "file:///x/b/c.txt");
	test_build_destination_dir ("file:///a/b/c.txt", "file:///a/b", "file:///x", "file:///x/c.txt");

	print ("\n");
	print ("tests: %d\n", n_tests);
	print ("errors: %d\n", n_errors);
	return 0;
}

void test_build_destination_dir (string source_uri, string source_base_uri, string destination_base_uri, string? expected) {
	var source = File.new_for_uri (source_uri);
	var source_base_dir = File.new_for_uri (source_base_uri);
	var destination_base_dir = File.new_for_uri (destination_base_uri);
	var result = Gth.Util.build_destination_dir (source, source_base_dir, destination_base_dir);
	var result_uri = result.get_uri ();
	if (result_uri != expected) {
		stderr.printf ("> build_destination_dir ('%s', '%s', '%s')  expecting: '%s'  got: '%s'\n",
			source_uri, source_base_uri, destination_base_uri,
			expected, result_uri);
		n_errors++;
	}
	n_tests++;
}

void test_get_basename (string path, string? expected) {
	var result = Gth.Util.get_basename (path);
	if (result != expected) {
		stderr.printf ("> get_basename ('%s')  expecting: '%s'  got: '%s'\n", path, expected, result);
		n_errors++;
	}
	n_tests++;
}

void test_get_digits (int number, int expected) {
	var result = Gth.Util.get_digits (number);
	if (result != expected) {
		stderr.printf ("> get_digits (%d)  expecting: %d  got: %d\n", number, expected, result);
		n_errors++;
	}
	n_tests++;
}

void test_get_extension (string filename, string? expected) {
	var result = Gth.Util.get_extension (filename);
	if (result != expected) {
		stderr.printf ("> get_extension ('%s')  expecting: '%s'  got: '%s'\n", filename, expected, result);
		n_errors++;
	}
	n_tests++;
}

void test_remove_extension (string filename, string expected) {
	var result = Gth.Util.remove_extension (filename);
	if (result != expected) {
		stderr.printf ("> remove_extension ('%s')  expecting: '%s'  got: '%s'\n", filename, expected, result);
		n_errors++;
	}
	n_tests++;
}

void test_uri_from_path (string filename, string expected) {
	var result = Gth.Util.uri_from_path (filename);
	if (result != expected) {
		stderr.printf ("> uri_from_path ('%s')  expecting: '%s'  got: '%s'\n", filename, expected, result);
		n_errors++;
	}
	n_tests++;
}

void test_get_duplicated (string uri, string expected) {
	var file_result = Gth.Util.get_duplicated (File.new_for_uri (uri));
	var result = file_result.get_uri ();
	if (result != expected) {
		stderr.printf ("> get_duplicated ('%s')  expecting: '%s'  got: '%s'\n", uri, expected, result);
		n_errors++;
	}
	n_tests++;
}
