]> git.proxmox.com Git - libgit2.git/blob - tests/str/splice.c
14e844e2fc7c47aaaf48874a53787af936e39a82
[libgit2.git] / tests / str / splice.c
1 #include "clar_libgit2.h"
2
3 static git_str _buf;
4
5 void test_str_splice__initialize(void) {
6 git_str_init(&_buf, 16);
7 }
8
9 void test_str_splice__cleanup(void) {
10 git_str_dispose(&_buf);
11 }
12
13 void test_str_splice__preprend(void)
14 {
15 git_str_sets(&_buf, "world!");
16
17 cl_git_pass(git_str_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
18
19 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
20 }
21
22 void test_str_splice__append(void)
23 {
24 git_str_sets(&_buf, "Hello");
25
26 cl_git_pass(git_str_splice(&_buf, git_str_len(&_buf), 0, " world!", strlen(" world!")));
27
28 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
29 }
30
31 void test_str_splice__insert_at(void)
32 {
33 git_str_sets(&_buf, "Hell world!");
34
35 cl_git_pass(git_str_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
36
37 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
38 }
39
40 void test_str_splice__remove_at(void)
41 {
42 git_str_sets(&_buf, "Hello world of warcraft!");
43
44 cl_git_pass(git_str_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
45
46 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
47 }
48
49 void test_str_splice__replace(void)
50 {
51 git_str_sets(&_buf, "Hell0 w0rld!");
52
53 cl_git_pass(git_str_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
54
55 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
56 }
57
58 void test_str_splice__replace_with_longer(void)
59 {
60 git_str_sets(&_buf, "Hello you!");
61
62 cl_git_pass(git_str_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
63
64 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
65 }
66
67 void test_str_splice__replace_with_shorter(void)
68 {
69 git_str_sets(&_buf, "Brave new world!");
70
71 cl_git_pass(git_str_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
72
73 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
74 }
75
76 void test_str_splice__truncate(void)
77 {
78 git_str_sets(&_buf, "Hello world!!");
79
80 cl_git_pass(git_str_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
81
82 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
83 }
84
85 void test_str_splice__dont_do_anything(void)
86 {
87 git_str_sets(&_buf, "Hello world!");
88
89 cl_git_pass(git_str_splice(&_buf, 3, 0, "Hello", 0));
90
91 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf));
92 }