Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy #287

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/file/tests/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn modified_since() {
file.last_modified_time()
.checked_sub(Duration::from_millis(1))
.unwrap()
< now.into()
< now
);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ async fn bytes_future() {
);
}

const PNG_FILE: &'static [u8] = &[
const PNG_FILE: &[u8] = &[
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x25, 0xdb, 0x56,
0xca, 0x00, 0x00, 0x00, 0x03, 0x50, 0x4c, 0x54, 0x45, 0xff, 0x4d, 0x00, 0x5c, 0x35, 0x38, 0x7f,
Expand All @@ -105,7 +105,7 @@ const PNG_FILE: &'static [u8] = &[
];

#[cfg(feature = "futures")]
const PNG_FILE_DATA: &'static str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAA\
const PNG_FILE_DATA: &str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAA\
Al21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=";

#[cfg(feature = "futures")]
Expand Down
16 changes: 8 additions & 8 deletions crates/history/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl History for HashHistory {
let url = Self::get_url();
url.set_hash(&route);

self.inner.push(&url.href());
self.inner.push(url.href());
}

fn replace<'a>(&self, route: impl Into<Cow<'a, str>>) {
Expand All @@ -62,7 +62,7 @@ impl History for HashHistory {
let url = Self::get_url();
url.set_hash(&route);

self.inner.replace(&url.href());
self.inner.replace(url.href());
}

fn push_with_state<'a, T>(&self, route: impl Into<Cow<'a, str>>, state: T)
Expand All @@ -77,7 +77,7 @@ impl History for HashHistory {
let url = Self::get_url();
url.set_hash(&route);

self.inner.push_with_state(&url.href(), state)
self.inner.push_with_state(url.href(), state)
}

fn replace_with_state<'a, T>(&self, route: impl Into<Cow<'a, str>>, state: T)
Expand All @@ -92,7 +92,7 @@ impl History for HashHistory {
let url = Self::get_url();
url.set_hash(&route);

self.inner.replace_with_state(&url.href(), state)
self.inner.replace_with_state(url.href(), state)
}

#[cfg(feature = "query")]
Expand All @@ -109,7 +109,7 @@ impl History for HashHistory {
let url = Self::get_url();
url.set_hash(&format!("{}?{}", route, query));

self.inner.push(&url.href());
self.inner.push(url.href());
Ok(())
}
#[cfg(feature = "query")]
Expand All @@ -130,7 +130,7 @@ impl History for HashHistory {
let url = Self::get_url();
url.set_hash(&format!("{}?{}", route, query));

self.inner.replace(&url.href());
self.inner.replace(url.href());
Ok(())
}

Expand All @@ -155,7 +155,7 @@ impl History for HashHistory {
let query = serde_urlencoded::to_string(query)?;
url.set_hash(&format!("{}?{}", route, query));

self.inner.push_with_state(&url.href(), state);
self.inner.push_with_state(url.href(), state);

Ok(())
}
Expand All @@ -181,7 +181,7 @@ impl History for HashHistory {
let query = serde_urlencoded::to_string(query)?;
url.set_hash(&format!("{}?{}", route, query));

self.inner.replace_with_state(&url.href(), state);
self.inner.replace_with_state(url.href(), state);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions crates/net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ wasm-bindgen-test = "0.3"
futures = "0.3"
serde = { version = "1.0", features = ["derive"] }

once_cell = "1"

[features]
default = ["json", "websocket", "http", "eventsource"]

Expand Down
7 changes: 4 additions & 3 deletions crates/net/src/eventsource/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ mod tests {

wasm_bindgen_test_configure!(run_in_browser);

const SSE_ECHO_SERVER_URL: &str = env!("SSE_ECHO_SERVER_URL");

#[wasm_bindgen_test]
fn eventsource_works() {
let mut es = EventSource::new(SSE_ECHO_SERVER_URL).unwrap();
let sse_echo_server_url =
option_env!("SSE_ECHO_SERVER_URL").expect("Did you set SSE_ECHO_SERVER_URL?");

let mut es = EventSource::new(sse_echo_server_url).unwrap();
let mut servers = es.subscribe("server").unwrap();
let mut requests = es.subscribe("request").unwrap();

Expand Down
12 changes: 6 additions & 6 deletions crates/net/src/websocket/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl WebSocket {
.map_err(js_to_js_error)?;

let close_callback: Closure<dyn FnMut(web_sys::CloseEvent)> = {
let sender = sender.clone();
Closure::wrap(Box::new(move |e: web_sys::CloseEvent| {
let close_event = CloseEvent {
code: e.code(),
Expand Down Expand Up @@ -314,8 +313,8 @@ impl PinnedDrop for WebSocket {

for (ty, cb) in [
("open", self.closures.0.as_ref()),
("message", &self.closures.1.as_ref()),
("error", &self.closures.2.as_ref()),
("message", self.closures.1.as_ref()),
("error", self.closures.2.as_ref()),
] {
let _ = self
.ws
Expand All @@ -342,11 +341,12 @@ mod tests {

wasm_bindgen_test_configure!(run_in_browser);

const WS_ECHO_SERVER_URL: &str = env!("WS_ECHO_SERVER_URL");

#[wasm_bindgen_test]
fn websocket_works() {
let ws = WebSocket::open(WS_ECHO_SERVER_URL).unwrap();
let ws_echo_server_url =
option_env!("WS_ECHO_SERVER_URL").expect("Did you set WS_ECHO_SERVER_URL?");

let ws = WebSocket::open(ws_echo_server_url).unwrap();
let (mut sender, mut receiver) = ws.split();

spawn_local(async move {
Expand Down
28 changes: 15 additions & 13 deletions crates/net/tests/http.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use gloo_net::http::*;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

const HTTPBIN_URL: &str = env!("HTTPBIN_URL");
static HTTPBIN_URL: Lazy<&'static str> =
Lazy::new(|| option_env!("HTTPBIN_URL").expect("Did you set HTTPBIN_URL?"));

#[wasm_bindgen_test]
async fn fetch() {
let resp = Request::get(&format!("{}/get", HTTPBIN_URL))
let resp = Request::get(&format!("{}/get", *HTTPBIN_URL))
.send()
.await
.unwrap();
Expand All @@ -22,7 +24,7 @@ async fn fetch_json() {
url: String,
}

let url = format!("{}/get", HTTPBIN_URL);
let url = format!("{}/get", *HTTPBIN_URL);
let resp = Request::get(&url).send().await.unwrap();
let json: HttpBin = resp.json().await.unwrap();
assert_eq!(resp.status(), 200);
Expand All @@ -31,7 +33,7 @@ async fn fetch_json() {

#[wasm_bindgen_test]
async fn auth_valid_bearer() {
let resp = Request::get(&format!("{}/get", HTTPBIN_URL))
let resp = Request::get(&format!("{}/get", *HTTPBIN_URL))
.header("Authorization", "Bearer token")
.send()
.await
Expand All @@ -47,13 +49,13 @@ async fn gzip_response() {
gzipped: bool,
}

let resp = Request::get(&format!("{}/gzip", HTTPBIN_URL))
let resp = Request::get(&format!("{}/gzip", *HTTPBIN_URL))
.send()
.await
.unwrap();
let json: HttpBin = resp.json().await.unwrap();
assert_eq!(resp.status(), 200);
assert_eq!(json.gzipped, true);
assert!(json.gzipped);
}

#[wasm_bindgen_test]
Expand All @@ -64,7 +66,7 @@ async fn json_body() {
num: i16,
}

let result = Request::post(&format!("{}/anything", HTTPBIN_URL)).json(&Payload {
let result = Request::post(&format!("{}/anything", *HTTPBIN_URL)).json(&Payload {
data: "data".to_string(),
num: 42,
});
Expand All @@ -84,7 +86,7 @@ async fn post_json() {
json: Payload,
}

let req = Request::post(&format!("{}/anything", HTTPBIN_URL))
let req = Request::post(&format!("{}/anything", *HTTPBIN_URL))
.json(&Payload {
data: "data".to_string(),
num: 42,
Expand All @@ -106,7 +108,7 @@ async fn fetch_binary() {
data: String,
}

let resp = Request::post(&format!("{}/post", HTTPBIN_URL))
let resp = Request::post(&format!("{}/post", *HTTPBIN_URL))
.send()
.await
.unwrap();
Expand All @@ -118,20 +120,20 @@ async fn fetch_binary() {

#[wasm_bindgen_test]
async fn query_preserve_initial() {
let resp = Request::get(&format!("{}/get?key=value", HTTPBIN_URL))
let resp = Request::get(&format!("{}/get?key=value", *HTTPBIN_URL))
.query([("q", "val")])
.send()
.await
.unwrap();
assert_eq!(resp.url(), format!("{}/get?key=value&q=val", HTTPBIN_URL));
assert_eq!(resp.url(), format!("{}/get?key=value&q=val", *HTTPBIN_URL));
}

#[wasm_bindgen_test]
async fn query_preserve_duplicate_params() {
let resp = Request::get(&format!("{}/get", HTTPBIN_URL))
let resp = Request::get(&format!("{}/get", *HTTPBIN_URL))
.query([("q", "1"), ("q", "2")])
.send()
.await
.unwrap();
assert_eq!(resp.url(), format!("{}/get?q=1&q=2", HTTPBIN_URL));
assert_eq!(resp.url(), format!("{}/get?q=1&q=2", *HTTPBIN_URL));
}