aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--build.rs22
-rw-r--r--build_tests.py27
-rw-r--r--src/renderer/html.rs2
-rw-r--r--src/renderer/html_tests.rs245
5 files changed, 245 insertions, 52 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 845b1fd..273a4b0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,7 +11,6 @@ homepage = 'https://github.com/flying-sheep/rust-rst'
repository = 'https://github.com/flying-sheep/rust-rst.git'
edition = '2018'
-build = 'build.rs'
[lib]
name = 'rst'
diff --git a/build.rs b/build.rs
deleted file mode 100644
index 88b6214..0000000
--- a/build.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-
-use std::env;
-use std::io::{self, Write};
-use std::path::Path;
-use std::process::Command;
-
-fn main() {
- let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
-
- let input = Path::new(&manifest_dir).join("build_tests.py");
- let output = Path::new(&env::var("OUT_DIR").unwrap()).join("html_tests.rs");
- println!("cargo:rerun-if-changed={}", input.display());
-
- let output = Command::new("python3")
- .arg("build_tests.py")
- .arg(format!("{}", output.display()))
- .output()
- .expect("failed to execute process");
- io::stdout().write_all(&output.stdout).unwrap();
- io::stderr().write_all(&output.stderr).unwrap();
- assert!(output.status.success());
-}
diff --git a/build_tests.py b/build_tests.py
deleted file mode 100644
index 3fe4e9a..0000000
--- a/build_tests.py
+++ /dev/null
@@ -1,27 +0,0 @@
-import sys
-import json
-from ast import literal_eval
-from urllib.request import urlopen
-
-out = sys.argv[1]
-url_base = 'https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils'
-
-with urlopen(f'{url_base}/test/test_writers/test_html5_polyglot_parts.py?format=raw') as con:
- code = con.read().decode()
-
-code = code[code.find('totest ='):code.find('if __name__')]
-exec(code)
-with open(out, 'w') as f:
- t = 0
- for k, (opts, tests) in totest.items():
- for rst, result_code in tests:
- result = literal_eval(result_code)['fragment']
- rst, result = (r.replace('"', r'\"') for r in (rst, result))
- f.write(f'''\
-#[test]
-fn test_{t:02}() {{
- check_renders_to("{rst}", "{result.strip()}");
-}}
-''')
- t += 1
-
diff --git a/src/renderer/html.rs b/src/renderer/html.rs
index 68b471c..b3ee343 100644
--- a/src/renderer/html.rs
+++ b/src/renderer/html.rs
@@ -227,7 +227,7 @@ impl HTMLRender for String {
impl HTMLRender for e::Reference {
fn render_html<W>(&self, stream: &mut W) -> Result<(), Error> where W: Write {
let extra = self.extra();
- write!(stream, "<a class=\"reference external\"")?;
+ write!(stream, "<a")?;
if let Some(ref target) = extra.refuri {
write!(stream, " href=\"{}\"", escape_html(target.as_str()))?;
}
diff --git a/src/renderer/html_tests.rs b/src/renderer/html_tests.rs
index a91dd80..c12890a 100644
--- a/src/renderer/html_tests.rs
+++ b/src/renderer/html_tests.rs
@@ -12,4 +12,247 @@ fn check_renders_to(rst: &str, expected: &str) {
assert_eq!(result.as_str().trim(), expected);
}
-include!(concat!(env!("OUT_DIR"), "/html_tests.rs"));
+#[test]
+fn test_simple_string() {
+ check_renders_to(
+ "Simple String",
+ "<p>Simple String</p>",
+ );
+}
+
+#[test]
+fn test_simple_string_with_markup() {
+ check_renders_to(
+ "Simple String with *markup*",
+ "<p>Simple String with <em>markup</em></p>",
+ );
+}
+
+#[test]
+fn test_check_inline_literal() {
+ check_renders_to(
+ "Simple String with an even simpler ``inline literal``",
+ "<p>Simple String with an even simpler <code>inline literal</code></p>",
+ );
+}
+
+#[test]
+fn test_reference_anonymous() {
+ check_renders_to("\
+A simple `anonymous reference`__
+
+__ http://www.test.com/test_url
+", "\
+<p>A simple <a href=\"http://www.test.com/test_url\">anonymous reference</a></p>\
+");
+}
+
+#[test]
+fn test_two_paragraphs() {
+ check_renders_to(
+ "One paragraph.\n\nTwo paragraphs.",
+ "<p>One paragraph.</p>\n<p>Two paragraphs.</p>",
+ );
+}
+
+#[test]
+fn test_named_reference() {
+ check_renders_to("\
+A simple `named reference`_ with stuff in between the
+reference and the target.
+
+.. _`named reference`: http://www.test.com/test_url
+", "\
+<p>A simple <a href=\"http://www.test.com/test_url\">named reference</a> with stuff in between the
+reference and the target.</p>\
+");
+}
+
+/*
+#[test]
+fn test_section_hierarchy() {
+ check_renders_to("\
++++++
+Title
++++++
+
+Subtitle
+========
+
+Some stuff
+
+Section
+-------
+
+Some more stuff
+
+Another Section
+...............
+
+And even more stuff
+", "\
+<p>Some stuff</p>
+<section id=\"section\">
+<h1>Section</h1>
+<p>Some more stuff</p>
+<section id=\"another-section\">
+<h2>Another Section</h2>
+<p>And even more stuff</p>
+</section>
+</section>\
+");
+}
+
+#[test]
+fn test_docinfo_title() {
+ check_renders_to("\
++++++
+Title
++++++
+
+:author: me
+
+Some stuff
+", "\
+<main id=\"title\">
+<h1 class=\"title\">Title</h1>
+<dl class=\"docinfo simple\">
+<dt class=\"author\">Author</dt>
+<dd class=\"author\"><p>me</p></dd>
+</dl>
+<p>Some stuff</p>
+</main>\
+");
+}
+*/
+
+#[test]
+fn test_section_hierarchy() {
+ check_renders_to("\
++++++
+Title
++++++
+
+Not A Subtitle
+==============
+
+Some stuff
+
+Section
+-------
+
+Some more stuff
+
+Another Section
+...............
+
+And even more stuff
+", "\
+<section id=\"title\">
+<h1>Title</h1>
+<section id=\"not-a-subtitle\">
+<h2>Not A Subtitle</h2>
+<p>Some stuff</p>
+<section id=\"section\">
+<h3>Section</h3>
+<p>Some more stuff</p>
+<section id=\"another-section\">
+<h4>Another Section</h4>
+<p>And even more stuff</p>
+</section>
+</section>
+</section>
+</section>\
+");
+}
+
+#[test]
+fn test_bullet_list() {
+ check_renders_to("\
+* bullet
+* list
+", "\
+<ul>
+<li><p>bullet</p></li>
+<li><p>list</p></li>
+</ul>\
+");
+}
+
+#[test]
+fn test_table() {
+ check_renders_to("\
+.. table::
+ :align: right
+
+ +-----+-----+
+ | 1 | 2 |
+ +-----+-----+
+ | 3 | 4 |
+ +-----+-----+
+", "\
+<table class=\"align-right\">
+<colgroup>
+<col style=\"width: 50%%\" />
+<col style=\"width: 50%%\" />
+</colgroup>
+<tbody>
+<tr><td><p>1</p></td>
+<td><p>2</p></td>
+</tr>
+<tr><td><p>3</p></td>
+<td><p>4</p></td>
+</tr>
+</tbody>
+</table>\
+");
+}
+
+#[test]
+fn test_field_list() {
+ check_renders_to("\
+Not a docinfo.
+
+:This: .. _target:
+
+ is
+:a:
+:simple:
+:field: list
+", "\
+<p>Not a docinfo.</p>
+<dl class=\"field-list\">
+<dt>This</dt>
+<dd><p id=\"target\">is</p>
+</dd>
+<dt>a</dt>
+<dd><p></p></dd>
+<dt>simple</dt>
+<dd><p></p></dd>
+<dt>field</dt>
+<dd><p>list</p>
+</dd>
+</dl>\
+");
+}
+
+#[test]
+fn test_field_list_long() {
+ check_renders_to("\
+Not a docinfo.
+
+:This is: a
+:simple field list with loooong field: names
+", "\
+<p>Not a docinfo.</p>
+<dl class=\"field-list\">
+<dt>This is</dt>
+<dd><p>a</p>
+</dd>
+<dt>simple field list with loooong field</dt>
+<dd><p>names</p>
+</dd>
+</dl>\
+");
+}
+