File: remove_last_path_component.c

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (71 lines) | stat: -rw-r--r-- 1,472 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stic.h>

#include <test-utils.h>

#include "../../src/compat/fs_limits.h"
#include "../../src/utils/path.h"

TEST(empty_path)
{
	char path[PATH_MAX + 1] = "";
	remove_last_path_component(path);
	assert_string_equal("", path);
}

TEST(root_path)
{
	/* XXX: is this behaviour we want for root? */
	char path[PATH_MAX + 1] = "/";
	remove_last_path_component(path);
	assert_string_equal("", path);
}

TEST(dir_in_root)
{
	char path[PATH_MAX + 1] = "/bin";
	remove_last_path_component(path);
	assert_string_equal("/", path);
}

TEST(path_does_not_end_with_slash)
{
	char path[PATH_MAX + 1] = "/a/b/c";
	remove_last_path_component(path);
	assert_string_equal("/a/b", path);
}

TEST(path_ends_with_slash)
{
	char path[PATH_MAX + 1] = "/a/b/c/";
	remove_last_path_component(path);
	assert_string_equal("/a/b", path);
}

TEST(path_ends_with_multiple_slashes)
{
	char path[PATH_MAX + 1] = "/a/b/c///";
	remove_last_path_component(path);
	assert_string_equal("/a/b", path);
}

TEST(can_remove_path_completely)
{
	char path[PATH_MAX + 1] = "name";

	remove_last_path_component(path);
	assert_true(path[0] == '\0');
}

TEST(can_remove_path_completely_on_windows, IF(windows))
{
	char path[PATH_MAX + 1] = "c:/a";

	remove_last_path_component(path);
	assert_false(path[0] == '\0');

	remove_last_path_component(path);
	assert_true(path[0] == '\0');
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */