Skip to content

Commit

Permalink
config: admitir espacios (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaniAgus authored Dec 17, 2023
1 parent 0f66db9 commit 861c48e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/commons/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ t_config *config_create(char *path) {
void add_cofiguration(char *line) {
if (!string_is_empty(line) && !string_starts_with(line, "#")) {
char** keyAndValue = string_n_split(line, 2, "=");
string_trim(&keyAndValue[0]);
string_trim(&keyAndValue[1]);
dictionary_put(config->properties, keyAndValue[0], keyAndValue[1]);
free(keyAndValue[0]);
free(keyAndValue);
Expand Down
17 changes: 0 additions & 17 deletions tests/unit-tests/resources/config-double-newline.cfg

This file was deleted.

5 changes: 5 additions & 0 deletions tests/unit-tests/resources/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ IP=127.0.0.1
# This has an equals sign
WITH_EQUALS=this=value

# This has trailing whitespace characters
TRAILING_WHITESPACES = 42

PORT=8080

PROCESS_NAME=TEST
Expand All @@ -18,3 +21,5 @@ NUMBERS=[1, 2, 3, 4, 5]
NO_SPACES=[One,String,Next,to,another]

EMPTY_ARRAY=[]


9 changes: 7 additions & 2 deletions tests/unit-tests/test_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ context (test_config) {
} end

it("should return the keys count") {
should_int(config_keys_amount(config)) be equal to(8);
should_int(config_keys_amount(config)) be equal to(9);
} end

describe("Get") {
Expand Down Expand Up @@ -115,6 +115,11 @@ context (test_config) {
string_array_destroy(strings);
} end

it ("should get a value ignoring trailing spaces") {
should_string(config_get_string_value(config, "TRAILING_WHITESPACES")) be equal to("42");
should_int(config_get_int_value(config, "TRAILING_WHITESPACES")) be equal to(42);
} end

} end

} end
Expand All @@ -124,7 +129,7 @@ context (test_config) {
describe("Double newline") {

it ("should not fail when the config file ends with two newlines") {
t_config *config = config_create("resources/config-double-newline.cfg");
t_config *config = config_create("resources/config.cfg");
config_destroy(config);
} end
} end
Expand Down

0 comments on commit 861c48e

Please sign in to comment.