from std/string import split;
from test/more import *;
from text/lorem import lorem, lorem_text, lorem_html, lorem_markdown;

let plain := lorem_text( 2, false, false );
is(
	split( plain, "\n\n" ).length(),
	2,
	"plain text creates requested paragraphs",
);
like(
	plain,
	/^Lorem ipsum dolor sit amet /,
	"plain text begins with lorem ipsum",
);
unlike(
	plain,
	/<p>|<ul>|^## |^- /,
	"plain text has no HTML or Markdown markup",
);

let html := lorem_html( 2, false, false );
is( split( html, "<p>" ).length(), 3, "HTML creates requested paragraphs" );
like( html, /^<p>Lorem ipsum dolor sit amet /, "HTML wraps paragraphs" );
unlike(
	html,
	/<ul>|<h2>|^## /,
	"HTML without toggles has no lists or headings",
);

let markdown := lorem( {
	paragraphs: 1,
	format: "markdown",
	headings: true,
	lists: true,
} );
like( markdown, /^## [A-Z]/, "Markdown can include a heading" );
like( markdown, /\n\n- [A-Z]/, "Markdown can include a bullet list" );

let list := lorem_markdown( 1, false, true );
let list_lines := split( list, "\n" ).length();
ok(
	list_lines >= 4 and list_lines <= 8,
	"one list paragraph has four to eight items",
);

let html_list := lorem_html( 1, true, true );
like( html_list, /^<h2>[A-Z]/, "HTML can include a heading" );
like( html_list, /<ul>\n<li>[A-Z]/, "HTML can include a bullet list" );
unlike( html_list, /<p>/, "a list paragraph is not also a prose paragraph" );

is( lorem( { paragraphs: 0 } ), "", "zero paragraphs returns an empty string" );
like( exception( function() {
	lorem( { format: "rtf" } );
} ), /format must be text, html, or markdown/, "invalid format is rejected" );

done_testing();
