-- Leo's gemini proxy

-- Connecting to typed-hole.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

commit eec55853caf93866a6a65d0a0b9c5bdeaf682a04

Author: Julien Blanchard <julien@sideburns.eu>

Date: Sat Apr 18 18:03:42 2020 +0200


Add a task to run tests


diff --git a/Makefile b/Makefile

index 1b39fa8..0b00624 100644

--- a/Makefile

+++ b/Makefile

@@ -19,6 +19,9 @@ sharedir=$(DESTDIR)$(PREFIX)/share

target/release/castor : src

cargo build --release


+test :

+ cargo test -- --test-threads=1

+

install : target/release/castor install-data

Install binary

$(INSTALL_PROGRAM) target/release/castor $(bindir)/castor

diff --git a/src/absolute_url.rs b/src/absolute_url.rs

index 7be9e27..775683f 100644

--- a/src/absolute_url.rs

+++ b/src/absolute_url.rs

@@ -37,7 +37,7 @@ impl AbsoluteUrl for Gemini {

} else if url.starts_with("//") {

Url::parse(&format!("gemini:{}", url))

} else {

- Url::parse(&format!("gemini://{}", url))

+ Url::parse(url)

}

}

}

@@ -75,7 +75,25 @@ impl AbsoluteUrl for Gopher {

}


+fn test_make_absolute_slash_path_no_current_host() {

+ crate::history::clear();

+

+ let url = "/foo";

+ let absolute_url = Gemini { source: String::from(url) }.to_absolute_url();

+ assert_eq!(absolute_url, Err(url::ParseError::RelativeUrlWithoutBase));

+}

+#[test]

+fn test_make_absolute_just_path_no_current_host() {

+ crate::history::clear();

+

+ let url = "foo";

+ let absolute_url = Gemini { source: String::from(url) }.to_absolute_url();

+ assert_eq!(absolute_url, Err(url::ParseError::RelativeUrlWithoutBase));

+}

+#[test]

fn test_make_absolute_full_url() {

+ crate::history::clear();

+

crate::history::append("gemini://typed-hole.org");

let url = "gemini://typed-hole.org/foo";

let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

@@ -84,6 +102,8 @@ fn test_make_absolute_full_url() {

}

fn test_make_absolute_full_url_no_protocol() {

+ crate::history::clear();

+

crate::history::append("gemini://typed-hole.org");

let url = "//typed-hole.org/foo";

let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

@@ -92,6 +112,8 @@ fn test_make_absolute_full_url_no_protocol() {

}

fn test_make_absolute_slash_path() {

+ crate::history::clear();

+

crate::history::append("gemini://typed-hole.org");

let url = "/foo";

let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

@@ -100,6 +122,8 @@ fn test_make_absolute_slash_path() {

}

fn test_make_absolute_just_path() {

+ crate::history::clear();

+

crate::history::append("gemini://typed-hole.org");

let url = "foo";

let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

@@ -108,6 +132,8 @@ fn test_make_absolute_just_path() {

}

fn test_make_absolute_full_url_no_current_host() {

+ crate::history::clear();

+

let url = "gemini://typed-hole.org/foo";

let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

let absolute_url = Gemini { source: String::from(url) }.to_absolute_url().unwrap();

@@ -115,22 +141,10 @@ fn test_make_absolute_full_url_no_current_host() {

}

fn test_make_absolute_full_url_no_protocol_no_current_host() {

+ crate::history::clear();

+

let url = "//typed-hole.org/foo";

let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

let absolute_url = Gemini { source: String::from(url) }.to_absolute_url().unwrap();

assert_eq!(expected_url, absolute_url);

}

-#[test]

-fn test_make_absolute_slash_path_no_current_host() {

- let url = "/foo";

- let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

- let absolute_url = Gemini { source: String::from(url) }.to_absolute_url().unwrap();

- assert_eq!(expected_url, absolute_url);

-}

-#[test]

-fn test_make_absolute_just_path_no_current_host() {

- let url = "foo";

- let expected_url = Url::parse("gemini://typed-hole.org/foo").unwrap();

- let absolute_url = Gemini { source: String::from(url) }.to_absolute_url().unwrap();

- assert_eq!(expected_url, absolute_url);

-}

diff --git a/src/history.rs b/src/history.rs

index 8b89f83..b8d4d4b 100644

--- a/src/history.rs

+++ b/src/history.rs

@@ -50,3 +50,8 @@ pub fn get_previous_url() -> Option<Url> {

None

}

}

+

+#[cfg(test)]

+pub(crate) fn clear() -> () {

+ HISTORY.lock().unwrap().clear();

+}



---

Served by Pollux Gemini Server.

-- Response ended

-- Page fetched on Sun May 19 04:52:17 2024