fml 0.5.0

Friendly Markup Language
Documentation
use proc_macros::make_delimits_tests;

use crate::ast::{
	Content,
	FmlValue::{self, *},
	Section,
};

#[test]
fn nonesc_backslash() {
	let txt = r"sample \x text";
	let fml = crate::parse(txt).expect("failed to parse");

	assert_eq!(
		fml,
		Content(vec![Section(vec![Text(r"sample \x text".into())].into())])
	)
}

make_delimits_tests! {
	mod @{Name} {
		use crate::ast::{
			Content,
			FmlValue::{self, *},
			Section,
		};

		#[test]
		fn normal() {
			let txt = "@{Delim}sample text@{Delim}";
			let fml = crate::parse(txt).expect("failed to parse");

			assert_eq!(
				fml,
				Content(vec![Section(
					vec![@{ConstrStart}Text("sample text".into())@{ConstrEnd}].into()
				)])
			)
		}

		#[test]
		fn whitespace() {
			let txt = "@{Delim}	sample text @{Delim}";
			let fml = crate::parse(txt).expect("failed to parse");

			assert_eq!(
				fml,
				Content(vec![Section(
					vec![@{ConstrStart}Text("	sample text ".into())@{ConstrEnd}].into()
				)])
			)
		}

		#[test]
		fn multiline() {
			let txt = r"@{Delim}
sample text
@{Delim}";
			let fml = crate::parse(txt).expect("failed to parse");

			assert_eq!(
				fml,
				Content(vec![Section(
					vec![@{ConstrStart}Linebreak, Text("sample text".into()), Linebreak@{ConstrEnd}].into()
				)])
			)
		}

		#[test]
		fn uses_nearest() {
			let txt = r"@{Delim}@{Delim}sample text@{Delim}@{Delim}";
			let fml = crate::parse(txt).expect("failed to parse");

			assert_eq!(
				fml,
				Content(vec![Section(
					vec![Text("@{Delim}".into()), @{ConstrStart}Text("sample text".into())@{ConstrEnd}, Text("@{Delim}".into())].into()
				)])
			)
		}

		mod esc {
			use super::*;

			#[test]
			fn start() {
				let txt = r"\@{Delim}sample text@{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![Text("@{Delim}sample text@{Delim}".into())].into()
					)])
				)
			}

			#[test]
			fn end() {
				let txt = r"@{Delim}sample text\@{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![Text("@{Delim}sample text@{Delim}".into())].into()
					)])
				)
			}

			#[test]
			fn double_start() {
				let txt = r"\\@{Delim}sample text@{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![Text(r"\".into()), @{ConstrStart}Text("sample text".into())@{ConstrEnd}].into()
					)])
				)
			}

			#[test]
			fn double_end() {
				let txt = r"@{Delim}sample text\\@{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![@{ConstrStart}Text(r"sample text\".into())@{ConstrEnd}].into()
					)])
				)
			}
		}

		mod empty {
			use super::*;

			#[test]
			fn touching() {
				let txt = r"@{Delim}@{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![Text(r"@{Delim}@{Delim}".into())].into()
					)])
				)
			}

			#[test]
			fn whitespace() {
				let txt = r"@{Delim}	 @{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![Text(r"@{Delim}	 @{Delim}".into())].into()
					)])
				)
			}

			#[test]
			fn multiline() {
				let txt = r"@{Delim}
@{Delim}";
				let fml = crate::parse(txt).expect("failed to parse");

				assert_eq!(
					fml,
					Content(vec![Section(
						vec![Text(r"@{Delim}".into()), Linebreak, Text("@{Delim}".into())].into()
					)])
				)
			}
		}
	}
}