aboutsummaryrefslogtreecommitdiffstats
path: root/tests/blogc-make/check_utils.c
blob: 68320eb48a1545d07a4d1c9fe656eadfce3299eb (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * blogc: A blog compiler.
 * Copyright (C) 2014-2018 Rafael G. Martins <rafael@rafaelmartins.eng.br>
 *
 * This program can be distributed under the terms of the BSD License.
 * See the file LICENSE.
 */

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

#include <stdlib.h>

#include "../../src/blogc-make/utils.h"
#include "../../src/common/utils.h"


static void
test_generate_filename(void **state)
{
    char *rv;

    assert_null(bm_generate_filename(NULL, NULL, NULL, NULL));
    assert_null(bm_generate_filename(NULL, "", "", ""));
    assert_null(bm_generate_filename("_build", NULL, NULL, NULL));
    assert_null(bm_generate_filename("_build", "", "", ""));

    rv = bm_generate_filename(NULL, NULL, NULL, ".html");
    assert_string_equal(rv, "/index.html");
    free(rv);

    rv = bm_generate_filename(NULL, NULL, NULL, "/index.html");
    assert_string_equal(rv, "/index.html");
    free(rv);

    rv = bm_generate_filename(NULL, "lol", NULL, ".html");
    assert_string_equal(rv, "/lol.html");
    free(rv);

    rv = bm_generate_filename(NULL, "lol", NULL, "/index.html");
    assert_string_equal(rv, "/lol/index.html");
    free(rv);

    rv = bm_generate_filename(NULL, NULL, "foo", ".html");
    assert_string_equal(rv, "/foo.html");
    free(rv);

    rv = bm_generate_filename(NULL, NULL, "foo", "/index.html");
    assert_string_equal(rv, "/foo/index.html");
    free(rv);

    rv = bm_generate_filename(NULL, NULL, "index", ".html");
    assert_string_equal(rv, "/index.html");
    free(rv);

    rv = bm_generate_filename(NULL, NULL, "index", "/index.html");
    assert_string_equal(rv, "/index.html");
    free(rv);

    rv = bm_generate_filename(NULL, "bar", "foo", ".html");
    assert_string_equal(rv, "/bar/foo.html");
    free(rv);

    rv = bm_generate_filename(NULL, "bar", "foo", "/index.html");
    assert_string_equal(rv, "/bar/foo/index.html");
    free(rv);

    rv = bm_generate_filename("_build", NULL, NULL, ".html");
    assert_string_equal(rv, "_build/index.html");
    free(rv);

    rv = bm_generate_filename("_build", NULL, NULL, "/index.html");
    assert_string_equal(rv, "_build/index.html");
    free(rv);

    rv = bm_generate_filename("_build", "lol", NULL, ".html");
    assert_string_equal(rv, "_build/lol.html");
    free(rv);

    rv = bm_generate_filename("_build", "lol", NULL, "/index.html");
    assert_string_equal(rv, "_build/lol/index.html");
    free(rv);

    rv = bm_generate_filename("_build", NULL, "foo", ".html");
    assert_string_equal(rv, "_build/foo.html");
    free(rv);

    rv = bm_generate_filename("_build", NULL, "foo", "/index.html");
    assert_string_equal(rv, "_build/foo/index.html");
    free(rv);

    rv = bm_generate_filename("_build", NULL, "index", ".html");
    assert_string_equal(rv, "_build/index.html");
    free(rv);

    rv = bm_generate_filename("_build", NULL, "index", "/index.html");
    assert_string_equal(rv, "_build/index.html");
    free(rv);

    rv = bm_generate_filename("_build", "bar", "foo", ".html");
    assert_string_equal(rv, "_build/bar/foo.html");
    free(rv);

    rv = bm_generate_filename("_build", "bar", "foo", "/index.html");
    assert_string_equal(rv, "_build/bar/foo/index.html");
    free(rv);
}


int
main(void)
{
    const UnitTest tests[] = {
        unit_test(test_generate_filename),
    };
    return run_tests(tests);
}