summaryrefslogtreecommitdiffstats
path: root/src/tidy-html5-test.c
diff options
context:
space:
mode:
authorBoris Pek <tehnick-8@yandex.ru>2017-03-30 00:41:24 (GMT)
committerBoris Pek <tehnick-8@yandex.ru>2017-04-01 14:26:38 (GMT)
commitcf340543f0e200c980d15d2e2b0f82d558b4771b (patch)
treec17fd4fc4691bf195af416e54db7775f05cd7c1b /src/tidy-html5-test.c
parent87bf1b36be008bb7b595c3c919fbf5e6557084c6 (diff)
downloadmxe-cf340543f0e200c980d15d2e2b0f82d558b4771b.zip
mxe-cf340543f0e200c980d15d2e2b0f82d558b4771b.tar.gz
mxe-cf340543f0e200c980d15d2e2b0f82d558b4771b.tar.bz2
tidy-html5: add test
Diffstat (limited to 'src/tidy-html5-test.c')
-rw-r--r--src/tidy-html5-test.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tidy-html5-test.c b/src/tidy-html5-test.c
new file mode 100644
index 0000000..81b6d57
--- /dev/null
+++ b/src/tidy-html5-test.c
@@ -0,0 +1,50 @@
+// This file is part of MXE. See LICENSE.md for licensing information.
+
+#include <tidy.h>
+#include <tidybuffio.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+
+
+int main()
+{
+ const char *input = "<h1>Blah</h1><p><b>Blah-blah-blah!</b>";
+ printf("Input (HTML fragment):\n%s\n\n", input);
+ fflush(stdout);
+
+ TidyDoc tDoc = tidyCreate();
+ TidyBuffer output = {0};
+ TidyBuffer errBuf = {0};
+ int rc = -1;
+
+ const bool ok = tidyOptSetBool(tDoc, TidyXhtmlOut, yes);
+
+ if (ok)
+ rc = tidySetErrorBuffer(tDoc, &errBuf);
+ if (rc >= 0)
+ rc = tidyParseString(tDoc, input);
+ if (rc >= 0)
+ rc = tidyCleanAndRepair(tDoc);
+ if (rc >= 0)
+ rc = tidyRunDiagnostics(tDoc);
+ if (rc > 1)
+ rc = (tidyOptSetBool(tDoc, TidyForceOutput, yes) ? rc : -1);
+ if (rc >= 0)
+ rc = tidySaveBuffer(tDoc, &output);
+
+ if (rc > 0)
+ printf("Diagnostics:\n%s\n\n", errBuf.bp);
+ if (rc >= 0)
+ printf("Output (valid HTML document):\n%s\n\n", output.bp);
+ else
+ printf("Unknown error: %d.\n\n", rc);
+ fflush(stdout);
+
+ tidyBufFree(&errBuf);
+ tidyBufFree(&output);
+ tidyRelease(tDoc);
+
+ return rc;
+}
+