/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file. You can obtain one at https://mozilla.org/MPL/2.0/. */ use tnipv_lint::lints::markdown::RelativeLinks; use tnipv_lint::reporters::Text; use tnipv_lint::Linter; #[tokio::test] async fn inline_link_to_consensus_specs() { let src = r#"--- header: value1 --- [hi](https://github.com/telcoin-association/consensus-specs/blob/6c2b46ae3248760e0f6e52d61077d8b31e43ad1d/specs/tnip4844/validator.md#compute_aggregated_poly_and_commitment) "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: vec![ "^https://(www\\.)?github\\.com/telcoin-association/consensus-specs/blob/[a-f0-9]{40}/.+$", ], }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!(reports, ""); } #[tokio::test] async fn inline_link_with_scheme() { let src = r#"--- header: value1 --- [hi](https://example.com/) "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | [hi](https://example.com/) | "# ); } #[tokio::test] async fn inline_link_with_scheme_to_tnips_telcoin_association_org() { let src = r#"--- header: value1 --- [hello](https://tnips.telcoin-association.org/TNIPS/tnip-1234) "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | [hello](https://tnips.telcoin-association.org/TNIPS/tnip-1234) | = help: use `./tnip-1234.md` instead "# ); } #[tokio::test] async fn inline_link_with_scheme_to_creativecommons_copyright() { let src = r#"--- header: value1 --- [copyright](https://creativecommons.org/publicdomain/zero/1.0/) "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | [copyright](https://creativecommons.org/publicdomain/zero/1.0/) | = help: use `../LICENSE.md` instead "# ); } #[tokio::test] async fn inline_link_with_scheme_and_numbers() { let src = r#"--- header: value1 --- [hi](https://example.com/4444) "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | [hi](https://example.com/4444) | "# ); } #[tokio::test] async fn inline_link_protocol_relative() { let src = r#"--- header: value1 --- [hi](//example.com/) "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | [hi](//example.com/) | "# ); } #[tokio::test] async fn inline_link_root_relative() { let src = r#"--- header: value1 --- Hello [hi](/foo)! "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | Hello [hi](/foo)! | "# ); } #[tokio::test] async fn inline_link_relative() { let src = r#"--- header: value1 --- Hello [hi](./foo/bar)! "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!(reports, ""); } #[tokio::test] async fn reference_link_with_scheme() { let src = r#"--- header: value1 --- Hello [hi][hello]! [hello]: https://example.com "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | Hello [hi][hello]! | "# ); } #[tokio::test] async fn reference_link_relative() { let src = r#"--- header: value1 --- Hello [hi][hello]! [hello]: ./hello-world "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!(reports, ""); } #[tokio::test] async fn reference_link_with_scheme_to_tnips_telcoin_association_org() { let src = r#"--- header: value1 --- Hello [hi][hello]! [hello]: https://tnips.telcoin-association.org/TNIPS/tnip-1234 "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | Hello [hi][hello]! | = help: use `./tnip-1234.md` instead "# ); } #[tokio::test] async fn inline_autolink() { let src = r#"--- header: value1 --- https://example.com/ hello world "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | https://example.com/ | "# ); } #[tokio::test] async fn anchor_link() { let src = r#"--- header: value1 --- example "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | example | "# ); } #[tokio::test] async fn anchor_link_protocol_relative() { let src = r#"--- header: value1 --- example "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | example | "# ); } #[tokio::test] async fn anchor_link_protocol_relative_to_tnips_telcoin_association_org() { let src = r#"--- header: value1 --- example "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | example | = help: use `./tnip-1234.md` instead "# ); } #[tokio::test] async fn anchor_link_relative_double_slash() { let src = r#"--- header: value1 --- example "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!(reports, ""); } #[tokio::test] async fn anchor_link_protocol_relative_to_creativecommons_copyright() { let src = r#"--- header: value1 --- copyright "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | copyright | = help: use `../LICENSE.md` instead "# ); } #[tokio::test] async fn img_relative_double_slash() { let src = r#"--- header: value1 --- "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!(reports, ""); } #[tokio::test] async fn img_protocol_relative() { let src = r#"--- header: value1 --- "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | | "# ); } #[tokio::test] async fn img_protocol_relative_to_tnips_telcoin_association_org() { let src = r#"--- header: value1 --- "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | | = help: use `../assets/tnip-712/eth_sign.png` instead "# ); } #[tokio::test] async fn img_with_scheme_to_tnips_telcoin_association_org() { let src = r#"--- header: value1 --- "#; let reports = Linter::>::default() .clear_lints() .deny( "markdown-rel", RelativeLinks { exceptions: Vec::<&str>::new(), }, ) .check_slice(None, src) .run() .await .unwrap() .into_inner(); assert_eq!( reports, r#"error[markdown-rel]: non-relative link or image | 5 | | = help: use `../assets/tnip-712/eth_sign.png` instead "# ); }