diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2020-10-13 00:04:14 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2020-10-13 00:04:14 +0200 |
commit | 39986b29f34795d346b8feb10ce4fe9caac8878e (patch) | |
tree | 07f7d4332b0766133040198ca68aa997c1080146 | |
parent | a18fa78b7574c0d165ff3e3c09b8f2c67b1901ac (diff) | |
download | blogc-39986b29f34795d346b8feb10ce4fe9caac8878e.tar.gz blogc-39986b29f34795d346b8feb10ce4fe9caac8878e.tar.bz2 blogc-39986b29f34795d346b8feb10ce4fe9caac8878e.zip |
blogc: fix post sorting when mixing posts before and after `Sun Sep 9 01:46:40 AM UTC 2001`
-rw-r--r-- | src/blogc/loader.c | 5 | ||||
-rw-r--r-- | tests/blogc/check_loader.c | 8 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/blogc/loader.c b/src/blogc/loader.c index 4e03ec3..af30a1b 100644 --- a/src/blogc/loader.c +++ b/src/blogc/loader.c @@ -121,7 +121,10 @@ sort_source(const void *a, const void *b) return 0; // wat } - return strcmp(cb, ca); + unsigned long la = strtoul(ca, NULL, 10); + unsigned long lb = strtoul(cb, NULL, 10); + + return (int) (lb - la); } diff --git a/tests/blogc/check_loader.c b/tests/blogc/check_loader.c index cded0ae..8c9c292 100644 --- a/tests/blogc/check_loader.c +++ b/tests/blogc/check_loader.c @@ -266,7 +266,7 @@ test_source_parse_from_files_filter_sort(void **state) will_return(__wrap_bc_file_get_contents, "bola3.txt"); will_return(__wrap_bc_file_get_contents, bc_strdup( "ASD: 789\n" - "DATE: 2001-02-03 04:05:06\n" + "DATE: 2011-02-03 04:05:06\n" "--------\n" "bola")); bc_error_t *err = NULL; @@ -284,7 +284,7 @@ test_source_parse_from_files_filter_sort(void **state) assert_string_equal(bc_trie_lookup(c, "FILTER_SORT"), "1"); assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola3"); assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola2"); - assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-03 04:05:06"); + assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2011-02-03 04:05:06"); assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-01 04:05:06"); bc_trie_free(c); bc_slist_free_full(s, free); @@ -356,7 +356,7 @@ test_source_parse_from_files_filter_sort_reverse(void **state) will_return(__wrap_bc_file_get_contents, "bola3.txt"); will_return(__wrap_bc_file_get_contents, bc_strdup( "ASD: 789\n" - "DATE: 2001-02-03 04:05:06\n" + "DATE: 2011-02-03 04:05:06\n" "--------\n" "bola")); bc_error_t *err = NULL; @@ -377,7 +377,7 @@ test_source_parse_from_files_filter_sort_reverse(void **state) assert_string_equal(bc_trie_lookup(c, "FILENAME_FIRST"), "bola2"); assert_string_equal(bc_trie_lookup(c, "FILENAME_LAST"), "bola3"); assert_string_equal(bc_trie_lookup(c, "DATE_FIRST"), "2001-02-01 04:05:06"); - assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2001-02-03 04:05:06"); + assert_string_equal(bc_trie_lookup(c, "DATE_LAST"), "2011-02-03 04:05:06"); bc_trie_free(c); bc_slist_free_full(s, free); bc_slist_free_full(t, (bc_free_func_t) bc_trie_free); |