Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: admitir espacios #175

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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