cosmopolitan/test/tool/build/lib/javadown_test.c

231 lines
9.9 KiB
C
Raw Normal View History

2020-12-26 10:09:07 +00:00
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "tool/build/lib/javadown.h"
TEST(ParseJavadown, testOneLiner) {
const char *comment = "/** Parses javadown. */";
struct Javadown *jd;
jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2);
EXPECT_FALSE(jd->isfileoverview);
EXPECT_STREQ("Parses javadown.", jd->title);
EXPECT_STREQ("", jd->text);
EXPECT_EQ(0, jd->tags.n);
FreeJavadown(jd);
}
TEST(ParseJavadown, testShortAndTerse) {
const char *comment = "\
/**\n\
* Parses javadown.\n\
* @see love\n\
*/";
const char *title = "Parses javadown and that is the bottom line.";
struct Javadown *jd;
jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2);
EXPECT_FALSE(jd->isfileoverview);
EXPECT_STREQ("Parses javadown.", jd->title);
EXPECT_STREQ("", jd->text);
EXPECT_EQ(1, jd->tags.n);
EXPECT_STREQ("see", jd->tags.p[0].tag);
EXPECT_STREQ("love", jd->tags.p[0].text);
FreeJavadown(jd);
}
TEST(ParseJavadown, testBlankLineOmitted) {
const char *comment = "\
/**\n\
* Parses javadown.\n\
*\n\
* Description.\n\
* @see love\n\
*/";
const char *title = "Parses javadown and that is the bottom line.";
struct Javadown *jd;
jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2);
EXPECT_FALSE(jd->isfileoverview);
EXPECT_STREQ("Parses javadown.", jd->title);
EXPECT_STREQ("Description.", jd->text);
EXPECT_EQ(1, jd->tags.n);
EXPECT_STREQ("see", jd->tags.p[0].tag);
EXPECT_STREQ("love", jd->tags.p[0].text);
FreeJavadown(jd);
}
TEST(ParseJavadown, testContentInterpretation) {
const char *comment = "\
/**\n\
* Parses javadown \n\
* and that is the bottom line.\n\
*\n\
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n\
* eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim \n\
* ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\n\
* aliquip ex ea commodo consequat.\n\
*\n\
* Duis aute irure dolor in reprehenderit in voluptate velit esse cillum\n\
* dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n\
* non proident, sunt in culpa qui officia deserunt mollit anim id est\n\
* laborum\n\
*\n\
* @param data should point to text inside the slash star markers\n\
* lorem ipsum dolla dollaz yo\n\
* @param size is length of data in bytes\n\
* @return object that should be passed to FreeJavadown()\n\
* @asyncsignalsafe\n\
*/";
const char *title = "Parses javadown and that is the bottom line.";
const char *description = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n\
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim\n\
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\n\
aliquip ex ea commodo consequat.\n\
\n\
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum\n\
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n\
non proident, sunt in culpa qui officia deserunt mollit anim id est\n\
laborum\n";
struct Javadown *jd;
jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2);
EXPECT_FALSE(jd->isfileoverview);
EXPECT_STREQ(title, jd->title);
EXPECT_STREQ(description, jd->text);
EXPECT_EQ(4, jd->tags.n);
EXPECT_STREQ("param", jd->tags.p[0].tag);
EXPECT_STREQ("data should point to text inside the slash star markers\n"
"lorem ipsum dolla dollaz yo",
jd->tags.p[0].text);
EXPECT_STREQ("param", jd->tags.p[1].tag);
EXPECT_STREQ("size is length of data in bytes", jd->tags.p[1].text);
EXPECT_STREQ("return", jd->tags.p[2].tag);
EXPECT_STREQ("object that should be passed to FreeJavadown()",
jd->tags.p[2].text);
EXPECT_STREQ("asyncsignalsafe", jd->tags.p[3].tag);
FreeJavadown(jd);
}
TEST(ParseJavadown, testTabFormatting1) {
const char *comment = "\
/**\n\
\tParses javadown \n\
\tand that is the bottom line.\n\
\n\
\tLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n\
\teiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim \n\
\tad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\n\
\taliquip ex ea commodo consequat.\n\
\n\
\tDuis aute irure dolor in reprehenderit in voluptate velit esse cillum\n\
\tdolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n\
\tnon proident, sunt in culpa qui officia deserunt mollit anim id est\n\
\tlaborum\n\
\n\
\t@param data should point to text inside the slash star markers\n\
\t\tlorem ipsum dolla dollaz yo\n\
\t@param size is length of data in bytes\n\
\t@return object that should be passed to FreeJavadown()\n\
\t@asyncsignalsafe\n\
*/";
const char *title = "Parses javadown and that is the bottom line.";
const char *description = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n\
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim\n\
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\n\
aliquip ex ea commodo consequat.\n\
\n\
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum\n\
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n\
non proident, sunt in culpa qui officia deserunt mollit anim id est\n\
laborum\n";
struct Javadown *jd;
jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2);
EXPECT_FALSE(jd->isfileoverview);
EXPECT_STREQ(title, jd->title);
EXPECT_STREQ(description, jd->text);
EXPECT_EQ(4, jd->tags.n);
EXPECT_STREQ("param", jd->tags.p[0].tag);
EXPECT_STREQ("data should point to text inside the slash star markers\n"
"lorem ipsum dolla dollaz yo",
jd->tags.p[0].text);
EXPECT_STREQ("param", jd->tags.p[1].tag);
EXPECT_STREQ("size is length of data in bytes", jd->tags.p[1].text);
EXPECT_STREQ("return", jd->tags.p[2].tag);
EXPECT_STREQ("object that should be passed to FreeJavadown()",
jd->tags.p[2].text);
EXPECT_STREQ("asyncsignalsafe", jd->tags.p[3].tag);
FreeJavadown(jd);
}
TEST(ParseJavadown, testTabFormatting2) {
const char *comment = "\
/**\n\
\tParses javadown \n\
\tand that is the bottom line.\n\
\t\n\
\tLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n\
\t\teiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim \n\
\t\tad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\n\
\t\taliquip ex ea commodo consequat.\n\
\t\n\
\tDuis aute irure dolor in reprehenderit in voluptate velit esse cillum\n\
\tdolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n\
\tnon proident, sunt in culpa qui officia deserunt mollit anim id est\n\
\tlaborum\n\
\t\n\
\t@param data should point to text inside the slash star markers\n\
\t\tlorem ipsum dolla dollaz yo\n\
\t@param size is length of data in bytes\n\
\t@return object that should be passed to FreeJavadown()\n\
\t@asyncsignalsafe\n\
*/";
const char *title = "Parses javadown and that is the bottom line.";
const char *description = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do\n\
\teiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim\n\
\tad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\n\
\taliquip ex ea commodo consequat.\n\
\n\
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum\n\
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n\
non proident, sunt in culpa qui officia deserunt mollit anim id est\n\
laborum\n";
struct Javadown *jd;
jd = ParseJavadown(comment + 3, strlen(comment) - 3 - 2);
EXPECT_FALSE(jd->isfileoverview);
EXPECT_STREQ(title, jd->title);
EXPECT_STREQ(description, jd->text);
EXPECT_EQ(4, jd->tags.n);
EXPECT_STREQ("param", jd->tags.p[0].tag);
EXPECT_STREQ("data should point to text inside the slash star markers\n"
"lorem ipsum dolla dollaz yo",
jd->tags.p[0].text);
EXPECT_STREQ("param", jd->tags.p[1].tag);
EXPECT_STREQ("size is length of data in bytes", jd->tags.p[1].text);
EXPECT_STREQ("return", jd->tags.p[2].tag);
EXPECT_STREQ("object that should be passed to FreeJavadown()",
jd->tags.p[2].text);
EXPECT_STREQ("asyncsignalsafe", jd->tags.p[3].tag);
FreeJavadown(jd);
}