]>
git.proxmox.com Git - libgit2.git/blob - tests/str/splice.c
14e844e2fc7c47aaaf48874a53787af936e39a82
1 #include "clar_libgit2.h"
5 void test_str_splice__initialize(void) {
6 git_str_init(&_buf
, 16);
9 void test_str_splice__cleanup(void) {
10 git_str_dispose(&_buf
);
13 void test_str_splice__preprend(void)
15 git_str_sets(&_buf
, "world!");
17 cl_git_pass(git_str_splice(&_buf
, 0, 0, "Hello Dolly", strlen("Hello ")));
19 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
22 void test_str_splice__append(void)
24 git_str_sets(&_buf
, "Hello");
26 cl_git_pass(git_str_splice(&_buf
, git_str_len(&_buf
), 0, " world!", strlen(" world!")));
28 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
31 void test_str_splice__insert_at(void)
33 git_str_sets(&_buf
, "Hell world!");
35 cl_git_pass(git_str_splice(&_buf
, strlen("Hell"), 0, "o", strlen("o")));
37 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
40 void test_str_splice__remove_at(void)
42 git_str_sets(&_buf
, "Hello world of warcraft!");
44 cl_git_pass(git_str_splice(&_buf
, strlen("Hello world"), strlen(" of warcraft"), "", 0));
46 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
49 void test_str_splice__replace(void)
51 git_str_sets(&_buf
, "Hell0 w0rld!");
53 cl_git_pass(git_str_splice(&_buf
, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
55 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
58 void test_str_splice__replace_with_longer(void)
60 git_str_sets(&_buf
, "Hello you!");
62 cl_git_pass(git_str_splice(&_buf
, strlen("Hello "), strlen("you"), "world", strlen("world")));
64 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
67 void test_str_splice__replace_with_shorter(void)
69 git_str_sets(&_buf
, "Brave new world!");
71 cl_git_pass(git_str_splice(&_buf
, 0, strlen("Brave new"), "Hello", strlen("Hello")));
73 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
76 void test_str_splice__truncate(void)
78 git_str_sets(&_buf
, "Hello world!!");
80 cl_git_pass(git_str_splice(&_buf
, strlen("Hello world!"), strlen("!"), "", 0));
82 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));
85 void test_str_splice__dont_do_anything(void)
87 git_str_sets(&_buf
, "Hello world!");
89 cl_git_pass(git_str_splice(&_buf
, 3, 0, "Hello", 0));
91 cl_assert_equal_s("Hello world!", git_str_cstr(&_buf
));