Improve documentation generator tests - Move tests from CFCTestCMan to CFCTestDocuComment. - Add tests for POD and HTML. - Add CFCCHtml_create_html_body to simplify testing.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/aa82267a Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/aa82267a Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/aa82267a Branch: refs/heads/master Commit: aa82267a9f85bd72c852e27ca094641f8add2d21 Parents: 73efb7c Author: Nick Wellnhofer <[email protected]> Authored: Sat Jan 10 23:35:39 2015 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Sun Jan 18 19:38:29 2015 +0100 ---------------------------------------------------------------------- compiler/src/CFCCHtml.c | 32 ++++-- compiler/src/CFCCHtml.h | 3 + compiler/src/CFCTest.c | 1 - compiler/src/CFCTest.h | 1 - compiler/src/CFCTestCMan.c | 107 ------------------ compiler/src/CFCTestDocuComment.c | 197 ++++++++++++++++++++++++++++++++- 6 files changed, 218 insertions(+), 123 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa82267a/compiler/src/CFCCHtml.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCCHtml.c b/compiler/src/CFCCHtml.c index 9252624..542a6ff 100644 --- a/compiler/src/CFCCHtml.c +++ b/compiler/src/CFCCHtml.c @@ -325,6 +325,22 @@ CFCCHtml_create_index_doc(CFCCHtml *self, CFCParcel *parcel, char* CFCCHtml_create_html_doc(CFCCHtml *self, CFCClass *klass) { + const char *class_name = CFCClass_get_class_name(klass); + char *title + = CFCUtil_sprintf("%s " UTF8_NDASH " C API Documentation", class_name); + char *header = CFCUtil_global_replace(self->header, "{title}", title); + char *body = CFCCHtml_create_html_body(klass); + + char *html_doc = CFCUtil_sprintf("%s%s%s", header, body, self->footer); + + FREEMEM(body); + FREEMEM(header); + FREEMEM(title); + return html_doc; +} + +char* +CFCCHtml_create_html_body(CFCClass *klass) { CFCParcel *parcel = CFCClass_get_parcel(klass); const char *parcel_name = CFCParcel_get_name(parcel); const char *class_name = CFCClass_get_class_name(klass); @@ -350,14 +366,10 @@ CFCCHtml_create_html_doc(CFCCHtml *self, CFCClass *klass) { // Build an INHERITANCE section describing class ancestry. char *inheritance = S_html_create_inheritance(klass); - char *title - = CFCUtil_sprintf("%s " UTF8_NDASH " C API Documentation", class_name); - char *header = CFCUtil_global_replace(self->header, "{title}", title); char *index_filename = S_index_filename(parcel); // Put it all together. const char pattern[] = - "%s" "<h1>%s</h1>\n" "<table>\n" "<tr>\n" @@ -386,18 +398,14 @@ CFCCHtml_create_html_doc(CFCCHtml *self, CFCClass *klass) { "%s" "%s" "%s" - "%s" "%s"; - char *html_doc - = CFCUtil_sprintf(pattern, header, class_name, index_filename, + char *html_body + = CFCUtil_sprintf(pattern, class_name, index_filename, parcel_name, class_name, class_nickname, class_var, struct_sym, name, synopsis, description, - functions_html, methods_html, inheritance, - self->footer); + functions_html, methods_html, inheritance); FREEMEM(index_filename); - FREEMEM(header); - FREEMEM(title); FREEMEM(name); FREEMEM(synopsis); FREEMEM(description); @@ -405,7 +413,7 @@ CFCCHtml_create_html_doc(CFCCHtml *self, CFCClass *klass) { FREEMEM(methods_html); FREEMEM(inheritance); - return html_doc; + return html_body; } static int http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa82267a/compiler/src/CFCCHtml.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCCHtml.h b/compiler/src/CFCCHtml.h index dc5a5f7..41f46fc 100644 --- a/compiler/src/CFCCHtml.h +++ b/compiler/src/CFCCHtml.h @@ -63,6 +63,9 @@ CFCCHtml_create_index_doc(CFCCHtml *self, struct CFCParcel *parcel, char* CFCCHtml_create_html_doc(CFCCHtml *self, struct CFCClass *klass); +char* +CFCCHtml_create_html_body(struct CFCClass *klass); + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa82267a/compiler/src/CFCTest.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTest.c b/compiler/src/CFCTest.c index 1692f58..21cff48 100644 --- a/compiler/src/CFCTest.c +++ b/compiler/src/CFCTest.c @@ -128,7 +128,6 @@ static const CFCTestBatch *const S_batches[] = { &CFCTEST_BATCH_FILE, &CFCTEST_BATCH_HIERARCHY, &CFCTEST_BATCH_PARSER, - &CFCTEST_BATCH_C_MAN, NULL }; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa82267a/compiler/src/CFCTest.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTest.h b/compiler/src/CFCTest.h index f78e07f..dbb3a17 100644 --- a/compiler/src/CFCTest.h +++ b/compiler/src/CFCTest.h @@ -155,7 +155,6 @@ CFCTest_set_file_times(const char *path, time_t time); extern const CFCTestBatch CFCTEST_BATCH_CLASS; extern const CFCTestBatch CFCTEST_BATCH_C_BLOCK; -extern const CFCTestBatch CFCTEST_BATCH_C_MAN; extern const CFCTestBatch CFCTEST_BATCH_DOCU_COMMENT; extern const CFCTestBatch CFCTEST_BATCH_FILE; extern const CFCTestBatch CFCTEST_BATCH_FILE_SPEC; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa82267a/compiler/src/CFCTestCMan.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestCMan.c b/compiler/src/CFCTestCMan.c deleted file mode 100644 index 6544d01..0000000 --- a/compiler/src/CFCTestCMan.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string.h> - -#define CFC_USE_TEST_MACROS -#include "CFCBase.h" -#include "CFCClass.h" -#include "CFCCMan.h" -#include "CFCDocuComment.h" -#include "CFCParcel.h" -#include "CFCTest.h" -#include "CFCUtil.h" - -#ifndef true - #define true 1 - #define false 0 -#endif - -static void -S_run_tests(CFCTest *test); - -const CFCTestBatch CFCTEST_BATCH_C_MAN = { - "Clownfish::CFC::Binding::C::Man", - 1, - S_run_tests -}; - -static void -S_run_tests(CFCTest *test) { - CFCParcel *parcel = CFCParcel_new("Neato", NULL, NULL, NULL); - CFCDocuComment *docu = CFCDocuComment_parse( - "/** Test man page creator.\n" - " * \n" - " * # Heading 1\n" - " * \n" - " * Paragraph: *emphasized*, **strong**, `code`.\n" - " * \n" - " * Paragraph: [link](http://example.com/).\n" - " * \n" - " * Code 1\n" - " * Code 2\n" - " * \n" - " * * List item 1\n" - " * * List item 1.1\n" - " * \n" - " * Paragraph in list\n" - " * \n" - " * Paragraph after list\n" - " */\n" - ); - CFCClass *klass - = CFCClass_create(parcel, "public", "Neato::Object", NULL, NULL, - docu, NULL, NULL, 0, 0); - char *man_page = CFCCMan_create_man_page(klass); - const char *expected_output = - ".TH Neato::Object 3\n" - ".SH NAME\n" - "Neato::Object \\- Test man page creator.\n" - ".SH DESCRIPTION\n" - ".SS\n" - "Heading 1\n" - "Paragraph: \\fIemphasized\\f[], \\fBstrong\\f[], \\FCcode\\F[]\\&.\n" - "\n" - "Paragraph: \n" - ".UR http://example.com/\n" - "link\n" - ".UE\n" - "\\&.\n" - ".IP\n" - ".nf\n" - ".fam C\n" - "Code 1\n" - "Code 2\n" - ".fam\n" - ".fi\n" - ".IP \\(bu\n" - "List item 1\n" - ".RS\n" - ".IP \\(bu\n" - "List item 1.1\n" - ".RE\n" - ".IP\n" - "Paragraph in list\n" - ".P\n" - "Paragraph after list\n"; - STR_EQ(test, man_page, expected_output, "create man page"); - - FREEMEM(man_page); - CFCBase_decref((CFCBase*)klass); - CFCBase_decref((CFCBase*)docu); - CFCBase_decref((CFCBase*)parcel); -} - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/aa82267a/compiler/src/CFCTestDocuComment.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestDocuComment.c b/compiler/src/CFCTestDocuComment.c index dba5f3c..3e78e38 100644 --- a/compiler/src/CFCTestDocuComment.c +++ b/compiler/src/CFCTestDocuComment.c @@ -17,21 +17,32 @@ #define CFC_USE_TEST_MACROS #include "CFCBase.h" #include "CFCDocuComment.h" +#include "CFCCHtml.h" +#include "CFCCMan.h" +#include "CFCClass.h" +#include "CFCParcel.h" #include "CFCParser.h" +#include "CFCPerlClass.h" +#include "CFCPerlPod.h" #include "CFCTest.h" #include "CFCUtil.h" +#ifndef true + #define true 1 + #define false 0 +#endif + static void S_run_tests(CFCTest *test); const CFCTestBatch CFCTEST_BATCH_DOCU_COMMENT = { "Clownfish::CFC::Model::DocuComment", - 15, + 18, S_run_tests }; static void -S_run_tests(CFCTest *test) { +S_test_parser(CFCTest *test) { CFCDocuComment *docucomment; docucomment = CFCDocuComment_parse("/** foo. */"); @@ -105,3 +116,185 @@ S_run_tests(CFCTest *test) { CFCBase_decref((CFCBase*)parser); } +static void +S_test_generator(CFCTest *test) { + CFCParcel *parcel = CFCParcel_new("Neato", NULL, NULL, NULL); + CFCDocuComment *docu = CFCDocuComment_parse( + "/** Test documentation generator.\n" + " * \n" + " * # Heading 1\n" + " * \n" + " * Paragraph: *emphasized*, **strong**, `code`.\n" + " * \n" + " * Paragraph: [link](http://example.com/).\n" + " * \n" + " * Code 1\n" + " * Code 2\n" + " * \n" + " * * List item 1\n" + " * * List item 1.1\n" + " * > Blockquote\n" + " * \n" + " * Paragraph in list\n" + " * \n" + " * Paragraph after list\n" + " */\n" + ); + CFCClass *klass + = CFCClass_create(parcel, "public", "Neato::Object", NULL, NULL, + docu, NULL, NULL, 0, 0); + + char *man_page = CFCCMan_create_man_page(klass); + const char *expected_man = + ".TH Neato::Object 3\n" + ".SH NAME\n" + "Neato::Object \\- Test documentation generator.\n" + ".SH DESCRIPTION\n" + ".SS\n" + "Heading 1\n" + "Paragraph: \\fIemphasized\\f[], \\fBstrong\\f[], \\FCcode\\F[]\\&.\n" + "\n" + "Paragraph: \n" + ".UR http://example.com/\n" + "link\n" + ".UE\n" + "\\&.\n" + ".IP\n" + ".nf\n" + ".fam C\n" + "Code 1\n" + "Code 2\n" + ".fam\n" + ".fi\n" + ".IP \\(bu\n" + "List item 1\n" + ".RS\n" + ".IP \\(bu\n" + "List item 1.1\n" + ".RS\n" + ".IP\n" + "Blockquote\n" + ".RE\n" + ".RE\n" + ".IP\n" + "Paragraph in list\n" + ".P\n" + "Paragraph after list\n"; + STR_EQ(test, man_page, expected_man, "create man page"); + + char *html = CFCCHtml_create_html_body(klass); + const char *expected_html = + "<h1>Neato::Object</h1>\n" + "<table>\n" + "<tr>\n" + "<td class=\"label\">parcel</td>\n" + "<td><a href=\"neato.html\">Neato</a></td>\n" + "</tr>\n" + "<tr>\n" + "<td class=\"label\">class name</td>\n" + "<td>Neato::Object</td>\n" + "</tr>\n" + "<tr>\n" + "<td class=\"label\">class nickname</td>\n" + "<td>Object</td>\n" + "</tr>\n" + "<tr>\n" + "<td class=\"label\">class variable</td>\n" + "<td><code>NEATO_OBJECT</code></td>\n" + "</tr>\n" + "<tr>\n" + "<td class=\"label\">struct symbol</td>\n" + "<td><code>neato_Object</code></td>\n" + "</tr>\n" + "</table>\n" + "<h2>Name</h2>\n" + "<p>Neato::Object â Test documentation generator.</p>\n" + "<h2>Description</h2>\n" + "<h1>Heading 1</h1>\n" + "<p>Paragraph: <em>emphasized</em>, <strong>strong</strong>, <code>code</code>.</p>\n" + "<p>Paragraph: <a href=\"http://example.com/\">link</a>.</p>\n" + "<pre><code>Code 1\n" + "Code 2\n" + "</code></pre>\n" + "<ul>\n" + "<li>\n" + "<p>List item 1</p>\n" + "<ul>\n" + "<li>List item 1.1\n" + "<blockquote>\n" + "<p>Blockquote</p>\n" + "</blockquote>\n" + "</li>\n" + "</ul>\n" + "<p>Paragraph in list</p>\n" + "</li>\n" + "</ul>\n" + "<p>Paragraph after list</p>\n"; + STR_EQ(test, html, expected_html, "create HTML"); + + CFCPerlClass *perl_class = CFCPerlClass_new(parcel, "Neato::Object"); + CFCPerlPod *perl_pod = CFCPerlPod_new(); + CFCPerlClass_set_pod_spec(perl_class, perl_pod); + char *pod = CFCPerlClass_create_pod(perl_class); + const char *expected_pod = + "=head1 NAME\n" + "\n" + "Neato::Object - Test documentation generator.\n" + "\n" + "=head1 DESCRIPTION\n" + "\n" + "=head3 Heading 1\n" + "\n" + "Paragraph: I<emphasized>, B<strong>, C<code>.\n" + "\n" + "Paragraph: L<link|http://example.com/>.\n" + "\n" + " Code 1\n" + " Code 2\n" + "\n" + "=over\n" + "\n" + "=item *\n" + "\n" + "List item 1\n" + "\n" + "=over\n" + "\n" + "=item *\n" + "\n" + "List item 1.1\n" + "\n" + "=over\n" + "\n" + "Blockquote\n" + "\n" + "=back\n" + "\n" + "=back\n" + "\n" + "Paragraph in list\n" + "\n" + "=back\n" + "\n" + "Paragraph after list\n" + "\n" + "=cut\n" + "\n"; + STR_EQ(test, pod, expected_pod, "create POD"); + + FREEMEM(pod); + CFCBase_decref((CFCBase*)perl_pod); + CFCBase_decref((CFCBase*)perl_class); + FREEMEM(html); + FREEMEM(man_page); + CFCBase_decref((CFCBase*)klass); + CFCBase_decref((CFCBase*)docu); + CFCBase_decref((CFCBase*)parcel); +} + +static void +S_run_tests(CFCTest *test) { + S_test_parser(test); + S_test_generator(test); +} +
