From b534d457c3813c4c2d905a04f6183e7317d66720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 18 Oct 2016 18:04:35 +0200 Subject: Fix the AST and add tests for formatting Also opened the way to making configurable quoted text elements, like the original Asciidoc allows. We could potentially end up allowing users to define different types of quotes producing custom AST. --- test/parser_SUITE.erl | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'test/parser_SUITE.erl') diff --git a/test/parser_SUITE.erl b/test/parser_SUITE.erl index 8869ec1..eca21a3 100644 --- a/test/parser_SUITE.erl +++ b/test/parser_SUITE.erl @@ -39,6 +39,46 @@ empty_line_spaces(_) -> [] = parse(" \n \n \n \n \n"), ok. +%% Text formatting. + +quoted_text_strong(_) -> + doc("Strong text formatting. (10.1)"), + [{p, _, [{strong, _, <<"Hello beautiful world!">>, _}], _}] = + parse("*Hello beautiful world!*"), + [{p, _, [{strong, _, <<"Hello">>, _}, <<" beautiful world!">>], _}] = + parse("*Hello* beautiful world!"), + [{p, _, [<<"Hello ">>, {strong, _, <<"beautiful">>, _}, <<" world!">>], _}] = + parse("Hello *beautiful* world!"), + [{p, _, [<<"Hello beautiful ">>, {strong, _, <<"world!">>, _}], _}] = + parse("Hello beautiful *world!*"), + [{p, _, [<<"Hello beautiful ">>, {strong, _, <<"multiline world!">>, _}, <<" lol">>], _}] = + parse("Hello beautiful *multiline\nworld!* lol"), + %% Nested formatting. + [{p, _, [{strong, _, [ + <<"Hello ">>, + {rel_link, #{target := <<"downloads/cowboy-2.0.tgz">>}, <<"2.0">>, _}, + <<" world!">> + ], _}], _}] = + parse("*Hello link:downloads/cowboy-2.0.tgz[2.0] world!*"), + ok. + +quoted_text_literal_mono(_) -> + doc("Literal monospace text formatting. (10.1)"), + [{p, _, [{mono, _, <<"Hello beautiful world!">>, _}], _}] = + parse("`Hello beautiful world!`"), + [{p, _, [{mono, _, <<"Hello">>, _}, <<" beautiful world!">>], _}] = + parse("`Hello` beautiful world!"), + [{p, _, [<<"Hello ">>, {mono, _, <<"beautiful">>, _}, <<" world!">>], _}] = + parse("Hello `beautiful` world!"), + [{p, _, [<<"Hello beautiful ">>, {mono, _, <<"world!">>, _}], _}] = + parse("Hello beautiful `world!`"), + [{p, _, [<<"Hello beautiful ">>, {mono, _, <<"multiline world!">>, _}, <<" lol">>], _}] = + parse("Hello beautiful `multiline\nworld!` lol"), + %% No text formatting must occur inside backticks. + [{p, _, [{mono, _, <<"Hello *beautiful* world!">>, _}], _}] = + parse("`Hello *beautiful* world!`"), + ok. + %% Title. %% @todo Long titles. (11.1) @@ -275,6 +315,18 @@ labeled_list(_) -> %% Macros. +rel_link(_) -> + doc("Relative links are built using the link:[] macro. (21.1.3)"), + [{p, _, [ + {rel_link, #{target := <<"downloads/cowboy-2.0.tgz">>}, <<"2.0">>, _} + ], _}] = parse("link:downloads/cowboy-2.0.tgz[2.0]"), + [{p, _, [ + <<"Download ">>, + {rel_link, #{target := <<"downloads/cowboy-2.0.zip">>}, <<"Cowboy 2.0">>, _}, + <<" as zip">> + ], _}] = parse("Download link:downloads/cowboy-2.0.zip[Cowboy 2.0] as zip"), + ok. + comment_line(_) -> doc("Lines starting with two slashes are treated as comments. (21.2.3)"), [{comment, _, <<"This is a comment.">>, _}] = parse("// This is a comment."), -- cgit v1.2.3