From ec53e5420b41725a14b9bf0fc5d89e90bcfb882d Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 7 Dec 2019 17:28:13 +0100 Subject: On second thought let’s not overcomplicate things --- Cargo.toml | 1 - build.rs | 22 ---- build_tests.py | 27 ----- src/renderer/html.rs | 2 +- src/renderer/html_tests.rs | 245 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 245 insertions(+), 52 deletions(-) delete mode 100644 build.rs delete mode 100644 build_tests.py 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(&self, stream: &mut W) -> Result<(), Error> where W: Write { let extra = self.extra(); - write!(stream, "Simple String

", + ); +} + +#[test] +fn test_simple_string_with_markup() { + check_renders_to( + "Simple String with *markup*", + "

Simple String with markup

", + ); +} + +#[test] +fn test_check_inline_literal() { + check_renders_to( + "Simple String with an even simpler ``inline literal``", + "

Simple String with an even simpler inline literal

", + ); +} + +#[test] +fn test_reference_anonymous() { + check_renders_to("\ +A simple `anonymous reference`__ + +__ http://www.test.com/test_url +", "\ +

A simple anonymous reference

\ +"); +} + +#[test] +fn test_two_paragraphs() { + check_renders_to( + "One paragraph.\n\nTwo paragraphs.", + "

One paragraph.

\n

Two paragraphs.

", + ); +} + +#[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 +", "\ +

A simple named reference with stuff in between the +reference and the target.

\ +"); +} + +/* +#[test] +fn test_section_hierarchy() { + check_renders_to("\ ++++++ +Title ++++++ + +Subtitle +======== + +Some stuff + +Section +------- + +Some more stuff + +Another Section +............... + +And even more stuff +", "\ +

Some stuff

+
+

Section

+

Some more stuff

+
+

Another Section

+

And even more stuff

+
+
\ +"); +} + +#[test] +fn test_docinfo_title() { + check_renders_to("\ ++++++ +Title ++++++ + +:author: me + +Some stuff +", "\ +
+

Title

+
+
Author
+

me

+
+

Some stuff

+
\ +"); +} +*/ + +#[test] +fn test_section_hierarchy() { + check_renders_to("\ ++++++ +Title ++++++ + +Not A Subtitle +============== + +Some stuff + +Section +------- + +Some more stuff + +Another Section +............... + +And even more stuff +", "\ +
+

Title

+
+

Not A Subtitle

+

Some stuff

+
+

Section

+

Some more stuff

+
+

Another Section

+

And even more stuff

+
+
+
+
\ +"); +} + +#[test] +fn test_bullet_list() { + check_renders_to("\ +* bullet +* list +", "\ +\ +"); +} + +#[test] +fn test_table() { + check_renders_to("\ +.. table:: + :align: right + + +-----+-----+ + | 1 | 2 | + +-----+-----+ + | 3 | 4 | + +-----+-----+ +", "\ + ++++ + + + + + + + + +

1

2

3

4

\ +"); +} + +#[test] +fn test_field_list() { + check_renders_to("\ +Not a docinfo. + +:This: .. _target: + + is +:a: +:simple: +:field: list +", "\ +

Not a docinfo.

+
+
This
+

is

+
+
a
+

+
simple
+

+
field
+

list

+
+
\ +"); +} + +#[test] +fn test_field_list_long() { + check_renders_to("\ +Not a docinfo. + +:This is: a +:simple field list with loooong field: names +", "\ +

Not a docinfo.

+
+
This is
+

a

+
+
simple field list with loooong field
+

names

+
+
\ +"); +} + -- cgit v1.2.3