]> git.proxmox.com Git - libgit2.git/blame - tests/buf/splice.c
New upstream version 1.3.0+dfsg.1
[libgit2.git] / tests / buf / splice.c
CommitLineData
3a14d3e2 1#include "clar_libgit2.h"
2#include "buffer.h"
3
4static git_buf _buf;
5
6void test_buf_splice__initialize(void) {
7 git_buf_init(&_buf, 16);
8}
9
10void test_buf_splice__cleanup(void) {
ac3d33df 11 git_buf_dispose(&_buf);
3a14d3e2 12}
13
14void test_buf_splice__preprend(void)
15{
16 git_buf_sets(&_buf, "world!");
17
18 cl_git_pass(git_buf_splice(&_buf, 0, 0, "Hello Dolly", strlen("Hello ")));
19
20 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
21}
22
23void test_buf_splice__append(void)
24{
25 git_buf_sets(&_buf, "Hello");
26
27 cl_git_pass(git_buf_splice(&_buf, git_buf_len(&_buf), 0, " world!", strlen(" world!")));
28
29 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
30}
31
32void test_buf_splice__insert_at(void)
33{
34 git_buf_sets(&_buf, "Hell world!");
35
36 cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), 0, "o", strlen("o")));
37
38 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
39}
40
41void test_buf_splice__remove_at(void)
42{
43 git_buf_sets(&_buf, "Hello world of warcraft!");
44
45 cl_git_pass(git_buf_splice(&_buf, strlen("Hello world"), strlen(" of warcraft"), "", 0));
46
47 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
48}
49
50void test_buf_splice__replace(void)
51{
52 git_buf_sets(&_buf, "Hell0 w0rld!");
53
54 cl_git_pass(git_buf_splice(&_buf, strlen("Hell"), strlen("0 w0"), "o wo", strlen("o wo")));
55
56 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
57}
58
59void test_buf_splice__replace_with_longer(void)
60{
61 git_buf_sets(&_buf, "Hello you!");
62
63 cl_git_pass(git_buf_splice(&_buf, strlen("Hello "), strlen("you"), "world", strlen("world")));
64
65 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
66}
67
68void test_buf_splice__replace_with_shorter(void)
69{
70 git_buf_sets(&_buf, "Brave new world!");
71
72 cl_git_pass(git_buf_splice(&_buf, 0, strlen("Brave new"), "Hello", strlen("Hello")));
73
74 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
75}
76
77void test_buf_splice__truncate(void)
78{
79 git_buf_sets(&_buf, "Hello world!!");
80
81 cl_git_pass(git_buf_splice(&_buf, strlen("Hello world!"), strlen("!"), "", 0));
82
83 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
84}
85
86void test_buf_splice__dont_do_anything(void)
87{
88 git_buf_sets(&_buf, "Hello world!");
89
90 cl_git_pass(git_buf_splice(&_buf, 3, 0, "Hello", 0));
91
92 cl_assert_equal_s("Hello world!", git_buf_cstr(&_buf));
93}