gemrendr 0.3.1

Turns Gemtext into idiomatic HTML
Documentation
//! gemrendr   Turns Gemtext into idiomatic HTML.
//! Copyright (C) 2025  AverageHelper
//!
//! This program is free software: you can redistribute it and/or modify
//! it under the terms of the GNU General Public License as published by
//! the Free Software Foundation, either version 3 of the License, or
//! (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program.  If not, see <https://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin_cmd;
use pretty_assertions::assert_eq;

#[test]
fn test_stdout_has_html() {
	// Try the command with our args and input
	let stdout = cargo_bin_cmd!()
		.args(["-O", "-", "-"]) // stdin->stdout
		.write_stdin(include_bytes!("samples/sample.gmi"))
		.unwrap()
		.stdout;

	let expected = include_bytes!("samples/sample.br.html").trim_ascii_end(); // sans pesky trailing newline

	assert_eq!(
		String::from_utf8(stdout).unwrap(),
		String::from_utf8(expected.to_vec()).unwrap()
	);
}

#[test]
fn test_stdout_has_html_with_paragraph_breaks() {
	let stdout = cargo_bin_cmd!()
		.args(["-e", "p", "-O", "-", "-"]) // stdin->stdout
		.write_stdin(include_bytes!("samples/sample.gmi"))
		.unwrap()
		.stdout;

	let expected = include_bytes!("samples/sample.p.html").trim_ascii_end(); // sans pesky trailing newline

	assert_eq!(
		String::from_utf8(stdout).unwrap(),
		String::from_utf8(expected.to_vec()).unwrap()
	);
}

#[test]
fn test_stdout_has_pre_blocks() {
	let stdout = cargo_bin_cmd!()
		.args(["-O", "-", "-"]) // stdin->stdout
		.write_stdin(include_bytes!("samples/pre_blocks.gmi"))
		.unwrap()
		.stdout;

	let expected = include_bytes!("samples/pre_blocks.none.html").trim_ascii_end(); // sans pesky trailing newline

	assert_eq!(
		String::from_utf8(stdout).unwrap(),
		String::from_utf8(expected.to_vec()).unwrap()
	);
}

#[test]
fn test_stdout_has_html_with_closed_pre_blocks() {
	let stdout = cargo_bin_cmd!()
		.args(["-O", "-", "-"]) // stdin->stdout
		.write_stdin(include_bytes!("samples/no_close_pre.gmi"))
		.unwrap()
		.stdout;

	let expected = include_bytes!("samples/no_close_pre.html").trim_ascii_end(); // sans pesky trailing newline

	assert_eq!(
		String::from_utf8(stdout).unwrap(),
		String::from_utf8(expected.to_vec()).unwrap()
	);
}

#[test]
fn test_stdout_has_pre_blocks_with_forgejo_copy_button() {
	let stdout = cargo_bin_cmd!()
		.args(["-c", "forgejo", "-O", "-", "-"]) // stdin->stdout
		.write_stdin(include_bytes!("samples/pre_blocks.gmi"))
		.unwrap()
		.stdout;

	let expected = include_bytes!("samples/pre_blocks.forgejo.html").trim_ascii_end(); // sans pesky trailing newline

	assert_eq!(
		String::from_utf8(stdout).unwrap(),
		String::from_utf8(expected.to_vec()).unwrap()
	);
}

#[test]
fn test_omits_preamble_on_request() {
	let stdout = cargo_bin_cmd!()
		.args(["-nO", "-", "-"]) // stdin->stdout
		.write_stdin(include_bytes!("samples/no_preamble.gmi"))
		.unwrap()
		.stdout;

	let expected = include_bytes!("samples/no_preamble.html").trim_ascii_end(); // sans pesky trailing newline

	assert_eq!(
		String::from_utf8(stdout).unwrap(),
		String::from_utf8(expected.to_vec()).unwrap()
	);
}

#[test]
fn test_prints_license() {
	// "type `{PKG_NAME} --license' for details" should always work
	let stdout = cargo_bin_cmd!().arg("--license").unwrap().stdout;
	let expected = include_str!("../LICENSE");
	assert_eq!(expected, String::from_utf8(stdout).unwrap());
}