completion: fix __git_complete_worktree_paths
[alt-git.git] / reftable / refname_test.c
blobb9cc62554ea1569a66e8fc08be40e04452e3032c
1 /*
2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
7 */
9 #include "basics.h"
10 #include "block.h"
11 #include "blocksource.h"
12 #include "reader.h"
13 #include "record.h"
14 #include "refname.h"
15 #include "reftable-error.h"
16 #include "reftable-writer.h"
17 #include "system.h"
19 #include "test_framework.h"
20 #include "reftable-tests.h"
22 struct testcase {
23 char *add;
24 char *del;
25 int error_code;
28 static void test_conflict(void)
30 struct reftable_write_options opts = { 0 };
31 struct strbuf buf = STRBUF_INIT;
32 struct reftable_writer *w =
33 reftable_new_writer(&strbuf_add_void, &noop_flush, &buf, &opts);
34 struct reftable_ref_record rec = {
35 .refname = "a/b",
36 .value_type = REFTABLE_REF_SYMREF,
37 .value.symref = "destination", /* make sure it's not a symref.
39 .update_index = 1,
41 int err;
42 int i;
43 struct reftable_block_source source = { NULL };
44 struct reftable_reader *rd = NULL;
45 struct reftable_table tab = { NULL };
46 struct testcase cases[] = {
47 { "a/b/c", NULL, REFTABLE_NAME_CONFLICT },
48 { "b", NULL, 0 },
49 { "a", NULL, REFTABLE_NAME_CONFLICT },
50 { "a", "a/b", 0 },
52 { "p/", NULL, REFTABLE_REFNAME_ERROR },
53 { "p//q", NULL, REFTABLE_REFNAME_ERROR },
54 { "p/./q", NULL, REFTABLE_REFNAME_ERROR },
55 { "p/../q", NULL, REFTABLE_REFNAME_ERROR },
57 { "a/b/c", "a/b", 0 },
58 { NULL, "a//b", 0 },
60 reftable_writer_set_limits(w, 1, 1);
62 err = reftable_writer_add_ref(w, &rec);
63 EXPECT_ERR(err);
65 err = reftable_writer_close(w);
66 EXPECT_ERR(err);
67 reftable_writer_free(w);
69 block_source_from_strbuf(&source, &buf);
70 err = reftable_new_reader(&rd, &source, "filename");
71 EXPECT_ERR(err);
73 reftable_table_from_reader(&tab, rd);
75 for (i = 0; i < ARRAY_SIZE(cases); i++) {
76 struct modification mod = {
77 .tab = tab,
80 if (cases[i].add) {
81 mod.add = &cases[i].add;
82 mod.add_len = 1;
84 if (cases[i].del) {
85 mod.del = &cases[i].del;
86 mod.del_len = 1;
89 err = modification_validate(&mod);
90 EXPECT(err == cases[i].error_code);
93 reftable_reader_free(rd);
94 strbuf_release(&buf);
97 int refname_test_main(int argc, const char *argv[])
99 RUN_TEST(test_conflict);
100 return 0;