| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 2 | // Copyright (C) 2020 Omar Castro | ||
| 3 | #include "simple_tap_test_util.h" | ||
| 4 | #include "../../src/string_utils.h" | ||
| 5 | #include "../../src/page_data.h" | ||
| 6 | |||
| 7 | |||
| 8 | 1 | void page_data_unit_tests(void) | |
| 9 | { | ||
| 10 | 1 | PageData * page_data = page_data_new(); | |
| 11 | |||
| 12 | 1 | test_true(page_data != NULL); | |
| 13 | 1 | test_true(page_data->markup_default == false); | |
| 14 | |||
| 15 | 1 | test_uint_equals(.result = page_data_get_number_of_lines(page_data), .expected = 0); | |
| 16 | |||
| 17 | |||
| 18 | 1 | page_data_add_line(page_data, "aaa", "any-icon", "any-data", true, true, true, true); | |
| 19 | 1 | test_string_equals(.result = page_data_get_line_by_index_or_else(page_data, 0, NULL)->text, .expected= "aaa"); | |
| 20 | 1 | test_true(page_data_get_line_by_index_or_else(page_data, -1, NULL) == NULL); | |
| 21 | 1 | test_true(page_data_get_line_by_index_or_else(NULL, 0, NULL) == NULL); | |
| 22 | 1 | test_uint_equals(.result = page_data_get_number_of_lines(page_data), .expected = 1); | |
| 23 | |||
| 24 | 1 | page_data_destroy(page_data); | |
| 25 | 1 | } | |
| 26 | |||
| 27 | |||
| 28 | 1 | void string_utils_unit_tests(void) | |
| 29 | { | ||
| 30 | char * result; | ||
| 31 | 1 | test_true(str_replace(NULL, NULL, NULL) == NULL); | |
| 32 | 1 | test_true(str_replace("aaaa", NULL, NULL) == NULL); | |
| 33 | 1 | test_true(str_replace("aaaa", "", "bbb") == NULL); | |
| 34 | |||
| 35 | 1 | test_autofree_string_equals(.result = str_replace("a{{aa}}a", "{{aa}}", "bb"), .expected = "abba"); | |
| 36 | |||
| 37 | 1 | test_autofree_string_equals(.result = str_replace("a{{aa}}a", "{{aa}}", NULL), .expected = "aa"); | |
| 38 | |||
| 39 | |||
| 40 | 1 | result = str_replace("a {{aa}} {{bb}} c", "{{aa}}", "lorem"); | |
| 41 | 1 | test_string_equals(.result = result, .expected = "a lorem {{bb}} c"); | |
| 42 | 1 | test_string_equals(.result = str_replace_in(&result, "{{bb}}", "ipsum"), .expected = "a lorem ipsum c"); | |
| 43 | 1 | free(result); | |
| 44 | |||
| 45 | 1 | result = str_replace("a {{aa}} {{bb}} c", "{{aa}}", "lorem"); | |
| 46 | 1 | test_string_equals( | |
| 47 | .result = result, | ||
| 48 | .expected = "a lorem {{bb}} c", | ||
| 49 | ); | ||
| 50 | 1 | test_string_equals( | |
| 51 | .result = str_replace_in_escaped(&result, "{{bb}}", "\\ \" \t \f \b \r\n a b"), | ||
| 52 | .expected = "a lorem \\\\ \\\" \\t \\f \\b \\r\\n a b c", | ||
| 53 | ); | ||
| 54 | 1 | free(result); | |
| 55 | |||
| 56 | 1 | } | |
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | 1 | int main(void) | |
| 61 | { | ||
| 62 | 1 | page_data_unit_tests(); | |
| 63 | 1 | string_utils_unit_tests(); | |
| 64 | 1 | return test_finish(); | |
| 65 | } | ||
| 66 |