Skip to content

Commit

Permalink
Test and validate show sub command
Browse files Browse the repository at this point in the history
  • Loading branch information
chinarjoshi committed Sep 21, 2023
1 parent 645546d commit e06e50b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/toml/toml_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ char *toml_dumps(toml_table_t *table) {
if (!table)
return 0;

// First determine length of string, including ANSI escape codes
// First determine length of string, including ANSI escape color codes
int len = 0;
toml_table_t *tab;
for (int i = 0; i < table->ntab; i++) {
tab = table->tab[i];
len += strlen(tab->key) + 28; // \033[1;34m[\033[1;35m%s\033[1;34m]\033[0m\n
len += strlen(tab->key) + 22; // \033[34m[\033[35m%s\033[34m]\033[0m\n
for (int j = 0; j < tab->nkval; j++) {
// "%s = \"%s\"\n"
// %s \033[34m=\033[32m\"%s\"\033[0m\n
Expand All @@ -181,8 +181,8 @@ char *toml_dumps(toml_table_t *table) {
int pos = 0;
for (int i = 0; i < table->ntab; i++) {
tab = table->tab[i];
sprintf(toml_str + pos, "\033[1;34m[\033[1;35m%s\033[1;34m]\033[0m\n", tab->key);
pos += strlen(tab->key) + 28;
sprintf(toml_str + pos, "\033[34m[\033[35m%s\033[34m]\033[0m\n", tab->key);
pos += strlen(tab->key) + 22;
for (int j = 0; j < tab->nkval; j++) {
sprintf(toml_str + pos, "%s \033[34m= \033[32m\"%s\"\033[0m\n", tab->kval[j]->key, tab->kval[j]->val);
pos += strlen(tab->kval[j]->key) + strlen(tab->kval[j]->val) + 20;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_subcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ START_TEST(test_show_cmd_normal) {
END_TEST

START_TEST(test_show_cmd_all) {
const char *path = "/home/c/.aliases";
strncpy(ALIAS_FNAME, path, strlen(path));
Cli cli = {
.type = SHOW,
.verbosity = 1,
Expand Down

0 comments on commit e06e50b

Please sign in to comment.