aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-17 06:57:19 +0000
committerFuwn <[email protected]>2023-04-17 06:57:19 +0000
commit3854c711b097b39e858d8ceabb4099a659f875a1 (patch)
treeeaeb6edb104306f17d2bbba3895ee9b93ec39036 /tests
parentchore(README): Update examples directory path (diff)
downloadgerm-3854c711b097b39e858d8ceabb4099a659f875a1.tar.xz
germ-3854c711b097b39e858d8ceabb4099a659f875a1.zip
refactor: remove seldom used procedural macros
Diffstat (limited to 'tests')
-rw-r--r--tests/ast.rs119
-rw-r--r--tests/convert.rs70
-rw-r--r--tests/meta.rs101
-rw-r--r--tests/quick.rs71
-rw-r--r--tests/status.rs32
5 files changed, 393 insertions, 0 deletions
diff --git a/tests/ast.rs b/tests/ast.rs
new file mode 100644
index 0000000..7c6dc36
--- /dev/null
+++ b/tests/ast.rs
@@ -0,0 +1,119 @@
+// This file is part of Germ <https://github.com/gemrest/germ>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// 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, version 3.
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+#[cfg(test)]
+mod test {
+ use germ::ast::{Ast, Node};
+
+ const EXAMPLE_GEMTEXT: &str = r#"```This is alt-text
+Here goes the pre-formatted text.
+
+This continues the pre-formatted text on a new line after a blank line.
+```
+
+# This is a heading
+
+This is some text.
+
+This is more text after a blank line.
+
+* This is a single list item.
+* This is the next list item.
+
+* This is a new list.
+* This is the next item on the new list.
+
+## This is a sub-heading
+
+> This is a blockquote.
+
+### This is a sub-sub-heading.
+
+=> gemini://gem.rest/ This is a link to GemRest
+=> /somewhere
+
+That was a link without text."#;
+
+ #[test]
+ fn build_multi_line_list_with_text() {
+ assert_eq!(
+ *Ast::from_string("* item1\n* 2\nhi text").inner(),
+ vec![
+ Node::List(vec!["item1".to_string(), "2".to_string()]),
+ Node::Text("hi text".to_string()),
+ ],
+ );
+ }
+
+ #[test]
+ fn build_multi_line_vec() {
+ assert_eq!(
+ *Ast::from_string("=> /test hi\nhi there\n> hi").inner(),
+ vec![
+ Node::Link {
+ to: "/test".to_string(),
+ text: Some("hi".to_string()),
+ },
+ Node::Text("hi there".to_string()),
+ Node::Blockquote("hi".to_string()),
+ ],
+ );
+ }
+
+ #[test]
+ fn build_single_0th_from_vec() {
+ assert_eq!(
+ Ast::from_string("=> /test hi").inner(),
+ &vec![Node::Link {
+ to: "/test".to_string(),
+ text: Some("hi".to_string()),
+ }],
+ );
+ }
+
+ #[test]
+ fn build_single_element() {
+ assert_eq!(
+ Ast::from_string("=> /test hi").inner().get(0).unwrap(),
+ &Node::Link {
+ to: "/test".to_string(),
+ text: Some("hi".to_string()),
+ },
+ );
+ }
+
+ #[test]
+ fn gemtext_to_ast_then_ast_to_gemtext() {
+ assert_eq!(
+ Ast::from_string(EXAMPLE_GEMTEXT).to_gemtext(),
+ // `to_gemtext` appends a newline to all responses, so let's make sure we
+ // account for that.
+ format!("{}\n", EXAMPLE_GEMTEXT),
+ );
+ }
+
+ #[test]
+ fn gemtext_to_ast_then_ast_to_gemtext_macro_expression() {
+ assert_eq!(
+ germ::gemini_to_ast!(EXAMPLE_GEMTEXT).to_gemtext(),
+ // `to_gemtext` appends a newline to all responses, so let's make sure we
+ // account for that.
+ format!("{}\n", EXAMPLE_GEMTEXT),
+ );
+ }
+}
diff --git a/tests/convert.rs b/tests/convert.rs
new file mode 100644
index 0000000..aad7ac4
--- /dev/null
+++ b/tests/convert.rs
@@ -0,0 +1,70 @@
+// This file is part of Germ <https://github.com/gemrest/germ>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// 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, version 3.
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+#[cfg(test)]
+mod test {
+ use germ::{
+ convert::{from_string, Target},
+ gemini_to_html,
+ gemini_to_md,
+ };
+
+ #[test]
+ fn convert_from_string_to_html_single_line() {
+ assert_eq!(from_string("hi", &Target::HTML), "<p>hi</p>",);
+ }
+
+ #[test]
+ fn convert_from_string_to_html_multi_line() {
+ assert_eq!(
+ from_string("hi\n# hi", &Target::HTML),
+ "<p>hi</p><h1>hi</h1>",
+ );
+ }
+
+ #[test]
+ fn convert_from_string_to_html_single_link_macro_expression() {
+ assert_eq!(
+ gemini_to_html!("=> /to hello !"),
+ "<a href=\"/to\">hello !</a><br>",
+ );
+ }
+
+ #[test]
+ fn convert_from_string_to_markdown_single_line() {
+ assert_eq!(from_string("hi", &Target::Markdown), "hi\n",);
+ }
+
+ #[test]
+ fn convert_from_string_to_markdown_multi_line() {
+ assert_eq!(from_string("hi\n# hi", &Target::Markdown), "hi\n# hi\n",);
+ }
+
+ #[test]
+ fn convert_from_string_to_markdown_single_link() {
+ assert_eq!(
+ from_string("=> /to hello !", &Target::Markdown),
+ "[hello !](/to)\n",
+ );
+ }
+
+ #[test]
+ fn convert_from_string_to_markdown_single_macro_expression() {
+ assert_eq!(gemini_to_md!("=> /to hello !"), "[hello !](/to)\n",);
+ }
+}
diff --git a/tests/meta.rs b/tests/meta.rs
new file mode 100644
index 0000000..70c8adc
--- /dev/null
+++ b/tests/meta.rs
@@ -0,0 +1,101 @@
+// This file is part of Germ <https://github.com/gemrest/germ>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// 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, version 3.
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+#[cfg(test)]
+mod test {
+ use germ::meta::Meta;
+
+ #[test]
+ fn construct_meta_with_mime() {
+ let mut meta = Meta::new();
+
+ *meta.mime_mut() = "text/gemini".to_string();
+
+ assert_eq!(meta.to_string(), "text/gemini");
+ }
+
+ #[test]
+ fn construct_meta_with_mime_and_parameters() {
+ let mut meta = Meta::new();
+ let mut parameters = std::collections::HashMap::new();
+
+ parameters.insert("hi".to_string(), "2".to_string());
+ parameters.insert("hi2".to_string(), "string=2".to_string());
+
+ *meta.mime_mut() = "text/gemini".to_string();
+ *meta.parameters_mut() = parameters;
+
+ assert_eq!(meta.to_string(), "text/gemini; hi=2; hi2=string=2");
+ }
+
+ #[test]
+ fn meta_to_string_without_parameters() {
+ let original_string = "text/gemini";
+
+ assert_eq!(
+ Meta::from_string(original_string).to_string(),
+ original_string
+ );
+ }
+
+ #[test]
+ fn meta_to_string_with_parameters() {
+ let original_string = "text/gemini; hi=2; hi2=string=2";
+
+ assert_eq!(
+ Meta::from_string(original_string).to_string(),
+ original_string
+ );
+ }
+
+ #[test]
+ fn meta_to_mime_without_parameters() {
+ let meta = Meta::from_string("text/gemini");
+
+ assert_eq!(meta.mime(), "text/gemini");
+ assert_eq!(meta.parameters().len(), 0);
+ }
+
+ #[test]
+ fn meta_to_map_mime() {
+ assert_eq!(
+ Meta::from_string("text/gemini; hi=2; hi2=string=2").mime(),
+ "text/gemini",
+ );
+ }
+
+ #[test]
+ fn meta_to_map_with_parameters() {
+ assert_eq!(
+ Meta::from_string("text/gemini; hi=2; hi2=string=2")
+ .parameters()
+ .get("hi2"),
+ Some(&"string=2".to_string()),
+ );
+ }
+
+ #[test]
+ fn meta_to_map_length() {
+ assert_eq!(
+ Meta::from_string("text/gemini; hi=2; hi2=string=2")
+ .parameters()
+ .len(),
+ 2,
+ );
+ }
+}
diff --git a/tests/quick.rs b/tests/quick.rs
new file mode 100644
index 0000000..255acd9
--- /dev/null
+++ b/tests/quick.rs
@@ -0,0 +1,71 @@
+// This file is part of Germ <https://github.com/gemrest/germ>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// 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, version 3.
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+#[cfg(test)]
+mod test {
+ use germ::quick::{self, heading};
+
+ #[test]
+ fn all_heading_levels() {
+ assert_eq!(heading("Soup", &germ::quick::HeadingLevel::One), "# Soup");
+ assert_eq!(
+ heading("Vegetables", &germ::quick::HeadingLevel::Two),
+ "## Vegetables"
+ );
+ assert_eq!(
+ heading("Fruits", &germ::quick::HeadingLevel::Three),
+ "### Fruits"
+ );
+ }
+
+ #[test]
+ fn list_item() {
+ assert_eq!(quick::list_item("Soup"), "* Soup");
+ }
+
+ #[test]
+ fn list_items() {
+ assert_eq!(
+ quick::list_items(&["Soup", "Vegetables", "Fruits"]),
+ "* Soup\n* Vegetables\n* Fruits"
+ );
+ }
+
+ #[test]
+ fn link_variants() {
+ assert_eq!(quick::link("Soup", None), "=> Soup");
+ assert_eq!(
+ quick::link("Soup", Some("gemini://soup.com")),
+ "=> Soup gemini://soup.com"
+ );
+ }
+
+ #[test]
+ fn block_quote() {
+ assert_eq!(quick::block_quote("Soup"), "> Soup");
+ }
+
+ #[test]
+ fn preformatted_text_variants() {
+ assert_eq!(quick::preformatted_text("Soup", None), "```\nSoup\n```");
+ assert_eq!(
+ quick::preformatted_text("Vegetables", Some("Fruits")),
+ "```Fruits\nVegetables\n```"
+ );
+ }
+}
diff --git a/tests/status.rs b/tests/status.rs
new file mode 100644
index 0000000..51f3f66
--- /dev/null
+++ b/tests/status.rs
@@ -0,0 +1,32 @@
+// This file is part of Germ <https://github.com/gemrest/germ>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// 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, version 3.
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+#[cfg(test)]
+mod test {
+ use germ::request::Status;
+
+ #[test]
+ fn status_from_i32() {
+ assert_eq!(Status::from(10), Status::Input);
+ }
+
+ #[test]
+ fn i32_from_status() {
+ assert_eq!(i32::from(Status::Input), 10);
+ }
+}