From 701ffe18c2f256245b4d016daafca208839a8f63 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 12 Oct 2015 02:31:02 -0300 Subject: content-parser: added id attributes to headers the id is a slugified version of the (unparsed) header content. --- tests/check_content_parser.c | 62 ++++++++++++++++++++++++++++++++------------ tests/check_source_parser.c | 12 ++++----- 2 files changed, 51 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index b9f83b0..f1430ac 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -19,6 +19,33 @@ #include "../src/utils/utils.h" +static void +test_slugify(void **state) +{ + char *s = blogc_slugify("bola"); + assert_string_equal(s, "bola"); + free(s); + s = blogc_slugify("bola o"); + assert_string_equal(s, "bola-o"); + free(s); + s = blogc_slugify("Bola O"); + assert_string_equal(s, "bola-o"); + free(s); + s = blogc_slugify("bola 0"); + assert_string_equal(s, "bola-0"); + free(s); + s = blogc_slugify("bola () o"); + assert_string_equal(s, "bola-----o"); + free(s); + s = blogc_slugify("Bola O"); + assert_string_equal(s, "bola-o"); + free(s); + s = blogc_slugify("bolaço"); + assert_string_equal(s, "bola--o"); + free(s); +} + + static void test_is_ordered_list_item(void **state) { @@ -80,12 +107,12 @@ test_content_parse(void **state) assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, - "

um

\n" - "

dois

\n" - "

tres

\n" - "

quatro

\n" - "
cinco
\n" - "
seis
\n" + "

um

\n" + "

dois

\n" + "

tres

\n" + "

quatro

\n" + "
cinco
\n" + "
seis
\n" "

bola\n" "chunda

\n" "

bola
\n" @@ -129,9 +156,9 @@ test_content_parse_with_excerpt(void **state) "guda\n" "lol", &l); assert_non_null(html); - assert_int_equal(l, 28); + assert_int_equal(l, 38); assert_string_equal(html, - "

test

\n" + "

test

\n" "

chunda

\n" "

guda\n" "lol

\n"); @@ -147,9 +174,9 @@ test_content_parse_with_excerpt(void **state) "guda\n" "lol", &l); assert_non_null(html); - assert_int_equal(l, 28); + assert_int_equal(l, 38); assert_string_equal(html, - "

test

\n" + "

test

\n" "

chunda

\n" "

guda\n" "lol

\n"); @@ -162,11 +189,11 @@ test_content_parse_header(void **state) { char *html = blogc_content_parse("## bola", NULL); assert_non_null(html); - assert_string_equal(html, "

bola

\n"); + assert_string_equal(html, "

bola

\n"); free(html); html = blogc_content_parse("## bola\n", NULL); assert_non_null(html); - assert_string_equal(html, "

bola

\n"); + assert_string_equal(html, "

bola

\n"); free(html); html = blogc_content_parse( "bola\n" @@ -177,7 +204,7 @@ test_content_parse_header(void **state) assert_non_null(html); assert_string_equal(html, "

bola

\n" - "

bola

\n" + "

bola

\n" "

guda

\n"); free(html); } @@ -526,7 +553,7 @@ test_content_parse_invalid_excerpt(void **state) assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, - "

test

\n" + "

test

\n" "

chunda\n" "..

\n" "

guda\n" @@ -544,7 +571,7 @@ test_content_parse_invalid_excerpt(void **state) assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, - "

test

\n" + "

test

\n" "

chunda

\n" "

...\n" "guda\n" @@ -561,7 +588,7 @@ test_content_parse_invalid_excerpt(void **state) assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, - "

test

\n" + "

test

\n" "

chunda..

\n" "

guda\n" "lol

\n"); @@ -577,7 +604,7 @@ test_content_parse_invalid_excerpt(void **state) assert_non_null(html); assert_int_equal(l, 0); assert_string_equal(html, - "

test

\n" + "

test

\n" "

chunda

\n" "

...guda\n" "lol

\n"); @@ -1119,6 +1146,7 @@ int main(void) { const UnitTest tests[] = { + unit_test(test_slugify), unit_test(test_is_ordered_list_item), unit_test(test_content_parse), unit_test(test_content_parse_with_excerpt), diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 94f75c9..145ba30 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -38,10 +38,10 @@ test_source_parse(void **state) assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd"); assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); assert_string_equal(b_trie_lookup(source, "EXCERPT"), - "

This is a test

\n" + "

This is a test

\n" "

bola

\n"); assert_string_equal(b_trie_lookup(source, "CONTENT"), - "

This is a test

\n" + "

This is a test

\n" "

bola

\n"); assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), "# This is a test\n" @@ -71,10 +71,10 @@ test_source_parse_with_spaces(void **state) assert_string_equal(b_trie_lookup(source, "VAR1"), "chunda"); assert_string_equal(b_trie_lookup(source, "BOLA"), "guda"); assert_string_equal(b_trie_lookup(source, "EXCERPT"), - "

This is a test

\n" + "

This is a test

\n" "

bola

\n"); assert_string_equal(b_trie_lookup(source, "CONTENT"), - "

This is a test

\n" + "

This is a test

\n" "

bola

\n"); assert_string_equal(b_trie_lookup(source, "RAW_CONTENT"), "# This is a test\n" @@ -107,10 +107,10 @@ test_source_parse_with_excerpt(void **state) assert_string_equal(b_trie_lookup(source, "VAR1"), "asd asd"); assert_string_equal(b_trie_lookup(source, "VAR2"), "123chunda"); assert_string_equal(b_trie_lookup(source, "EXCERPT"), - "

This is a test

\n" + "

This is a test

\n" "

bola

\n"); assert_string_equal(b_trie_lookup(source, "CONTENT"), - "

This is a test

\n" + "

This is a test

\n" "

bola

\n" "

guda\n" "yay

\n"); -- cgit v1.2.3-18-g5258