summaryrefslogtreecommitdiff
path: root/test/test-eel-string-rtrim-punctuation.c
blob: 3dc1f947f53ccabe6232a14321276f7a7772c925 (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
120
121
#include <glib.h>

#include "eel/eel-string.h"


static void
test_single_punctuation_character_removed ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Yossarian-");
        g_assert_cmpstr ("Yossarian", ==, actual);
        g_free (actual);
}

static void
test_tailing_space_is_removed ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Yossarian ");
        g_assert_cmpstr ("Yossarian", ==, actual);
        g_free (actual);
}

static void
test_multiple_punctuation_characters_removed ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Yossarian-$$!£");
        g_assert_cmpstr ("Yossarian", ==, actual);
        g_free (actual);
}

static void
test_multiple_punctuation_characters_removed_try_all_punctuation_characters ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Yossarian-`¬!\"£$%^&*()_+-= {}[]:@~;'#<>?,./\\");
        g_assert_cmpstr ("Yossarian", ==, actual);
        g_free (actual);
}

static void
test_punctuation_characters_removed_when_punctuation_in_middle_of_string ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Yoss,,arian-$$!£");
        g_assert_cmpstr ("Yoss,,arian", ==, actual);
        g_free (actual);
}

static void
test_punctuation_characters_removed_when_prefix_is_single_character ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Y-$$  !£");
        g_assert_cmpstr ("Y", ==, actual);
        g_free (actual);
}

static void
test_punctuation_characters_removed_when_unicode_characters_are_used ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Y✺ǨǨǨ-$$  !£");
        g_assert_cmpstr ("Y✺ǨǨǨ", ==, actual);
        g_free (actual);
}

static void
test_when_no_trailing_punctuation ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("Yoss,,arian");
        g_assert_cmpstr ("Yoss,,arian", ==, actual);
        g_free (actual);
}

static void
test_when_single_character_and_no_trailing_punctuation ()
{
        char *actual;
        actual = eel_str_rtrim_punctuation ("t");
        g_assert_cmpstr ("t", ==, actual);
        g_free (actual);
}

static void
setup_test_suite ()
{
        g_test_add_func ("/rtrim-punctuation/1.0",
                         test_single_punctuation_character_removed);
        g_test_add_func ("/rtrim-punctuation/1.1",
                         test_tailing_space_is_removed);
        g_test_add_func ("/rtrim-punctuation/1.2",
                         test_multiple_punctuation_characters_removed);
        g_test_add_func ("/rtrim-punctuation/1.3",
                         test_multiple_punctuation_characters_removed_try_all_punctuation_characters);
        g_test_add_func ("/rtrim-punctuation/1.4",
                         test_punctuation_characters_removed_when_punctuation_in_middle_of_string);
        g_test_add_func ("/rtrim-punctuation/1.5",
                         test_punctuation_characters_removed_when_prefix_is_single_character);
        g_test_add_func ("/rtrim-punctuation/1.6",
                         test_punctuation_characters_removed_when_unicode_characters_are_used);

        g_test_add_func ("/rtrim-punctuation/2.0",
                         test_when_no_trailing_punctuation);
        g_test_add_func ("/rtrim-punctuation/2.1",
                         test_when_single_character_and_no_trailing_punctuation);
}

int
main (int argc, char *argv[])
{
        g_test_init (&argc, &argv, NULL);
        g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
        g_test_set_nonfatal_assertions ();

        setup_test_suite ();

        return g_test_run ();
}