Skip to content

Commit

Permalink
Latest rustfmt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rouge8 committed Nov 25, 2023
1 parent 285633c commit 406d32c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 110 deletions.
11 changes: 6 additions & 5 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use crate::resources::STATIC_DIR;

pub static BS_PRIMARY_COLOR: Lazy<String> = Lazy::new(|| {
let re = Regex::new(r"--bs-primary:(#[a-f0-9]{6})").unwrap();
let css = STATIC_DIR
.get_file("bootstrap.pulse.min.css")
.unwrap()
.contents_utf8()
.unwrap();
let css =
STATIC_DIR
.get_file("bootstrap.pulse.min.css")
.unwrap()
.contents_utf8()
.unwrap();
let caps = re.captures(css).unwrap();
caps.get(1)
.expect("couldn't find --bs-primary color")
Expand Down
40 changes: 19 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ async fn login_post(

match api.username().await {
Ok(_) => {
let mut cookie = Cookie::build(COOKIE_NAME, api_key)
.secure(true)
.http_only(true)
.finish();
let mut cookie =
Cookie::build(COOKIE_NAME, api_key)
.secure(true)
.http_only(true)
.finish();
cookie.make_permanent();
let updated_jar = jar.add(cookie);
(updated_jar, Redirect::to("/assignments")).into_response()
Expand Down Expand Up @@ -202,12 +203,7 @@ async fn assignments(
TEMPLATES
.get_template("assignments.html")
.unwrap()
.render(AssignmentContext::new(
radicals,
kanji,
vocabulary,
kana_vocabulary,
))
.render(AssignmentContext::new(radicals, kanji, vocabulary, kana_vocabulary))
.unwrap(),
)
.into_response()
Expand Down Expand Up @@ -395,11 +391,12 @@ async fn main() -> reqwest::Result<()> {
.expect("invalid BIND_ADDRESS");

// Load the WaniKani data
let api = WaniKaniAPIClient::new(
&config.wanikani_api_key,
&config.wanikani_api_url,
&http_client,
);
let api =
WaniKaniAPIClient::new(
&config.wanikani_api_key,
&config.wanikani_api_url,
&http_client,
);
let mut db = Database::new();
db.populate(&api).await?;

Expand Down Expand Up @@ -684,12 +681,13 @@ mod tests {
async fn test_radical_svg(#[future] mockito_server: mockito::ServerGuard) {
let mut mockito_server = mockito_server.await;
let app = create_test_app(&mockito_server);
let _m = mockito_server
.mock("GET", "/foo")
.with_status(200)
.with_body("foo bar stroke:#000 other:#000")
.create_async()
.await;
let _m =
mockito_server
.mock("GET", "/foo")
.with_status(200)
.with_body("foo bar stroke:#000 other:#000")
.create_async()
.await;

let resp = app
.oneshot(
Expand Down
172 changes: 88 additions & 84 deletions src/wanikani.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ impl<'a> WaniKaniAPIClient<'a> {
let apprentice_srs_stages = APPRENTICE_SRS_STAGES
.map(|stage| stage.to_string())
.join(",");
let params = HashMap::from([
("srs_stages", apprentice_srs_stages.as_str()),
("hidden", "false"),
]);
let params =
HashMap::from([
("srs_stages", apprentice_srs_stages.as_str()),
("hidden", "false"),
]);
// TODO: Handle possible (but unlikely) pagination
let resp: Value = self
.request("assignments", Some(&params))
Expand Down Expand Up @@ -348,12 +349,13 @@ mod tests {
async fn test_username(#[future] mockito_server: mockito::ServerGuard) -> reqwest::Result<()> {
let mut mockito_server = mockito_server.await;
let client = test_client(&mockito_server);
let _m = mockito_server
.mock("GET", "/user")
.with_status(200)
.with_body(r#"{"data": {"username": "test-user"}}"#)
.create_async()
.await;
let _m =
mockito_server
.mock("GET", "/user")
.with_status(200)
.with_body(r#"{"data": {"username": "test-user"}}"#)
.create_async()
.await;

assert_eq!(client.username().await?, "test-user");

Expand Down Expand Up @@ -567,45 +569,46 @@ mod tests {
)
.create_async()
.await;
let _page2 = mockito_server
.mock("GET", "/subjects")
.match_query(Matcher::AllOf(vec![
Matcher::UrlEncoded("types".into(), "kanji".into()),
Matcher::UrlEncoded("hidden".into(), "false".into()),
Matcher::UrlEncoded("page_after_id".into(), "1".into()),
]))
.with_status(200)
.with_body(
json!({
"data": [
{
"id": 2,
"object": "kanji",
"data": {
"document_url": "https://www.wanikani.com/kanji/b",
"characters": "b",
"meanings": [
{"meaning": "b", "primary": true, "accepted_answer": true},
],
"readings": [
{
"type": "type1",
"primary": true,
"reading": "b",
"accepted_answer": true,
},
],
let _page2 =
mockito_server
.mock("GET", "/subjects")
.match_query(Matcher::AllOf(vec![
Matcher::UrlEncoded("types".into(), "kanji".into()),
Matcher::UrlEncoded("hidden".into(), "false".into()),
Matcher::UrlEncoded("page_after_id".into(), "1".into()),
]))
.with_status(200)
.with_body(
json!({
"data": [
{
"id": 2,
"object": "kanji",
"data": {
"document_url": "https://www.wanikani.com/kanji/b",
"characters": "b",
"meanings": [
{"meaning": "b", "primary": true, "accepted_answer": true},
],
"readings": [
{
"type": "type1",
"primary": true,
"reading": "b",
"accepted_answer": true,
},
],
},
},
],
"pages": {
"next_url": None::<String>,
},
],
"pages": {
"next_url": None::<String>,
},
})
.to_string(),
)
.create_async()
.await;
})
.to_string(),
)
.create_async()
.await;

assert_eq!(
client.kanji().await?,
Expand Down Expand Up @@ -694,45 +697,46 @@ mod tests {
)
.create_async()
.await;
let _page2 = mockito_server
.mock("GET", "/subjects")
.match_query(Matcher::AllOf(vec![
Matcher::UrlEncoded("types".into(), "vocabulary".into()),
Matcher::UrlEncoded("hidden".into(), "false".into()),
Matcher::UrlEncoded("page_after_id".into(), "1".into()),
]))
.with_status(200)
.with_body(
json!({
"data": [
{
"id": 2,
"object": "vocabulary",
"data": {
"document_url": "https://www.wanikani.com/vocabulary/b",
"characters": "b",
"meanings": [
{"meaning": "b", "primary": true, "accepted_answer": true},
],
"readings": [
{
"type": "type1",
"primary": true,
"reading": "b",
"accepted_answer": true,
},
],
let _page2 =
mockito_server
.mock("GET", "/subjects")
.match_query(Matcher::AllOf(vec![
Matcher::UrlEncoded("types".into(), "vocabulary".into()),
Matcher::UrlEncoded("hidden".into(), "false".into()),
Matcher::UrlEncoded("page_after_id".into(), "1".into()),
]))
.with_status(200)
.with_body(
json!({
"data": [
{
"id": 2,
"object": "vocabulary",
"data": {
"document_url": "https://www.wanikani.com/vocabulary/b",
"characters": "b",
"meanings": [
{"meaning": "b", "primary": true, "accepted_answer": true},
],
"readings": [
{
"type": "type1",
"primary": true,
"reading": "b",
"accepted_answer": true,
},
],
},
},
],
"pages": {
"next_url": None::<String>,
},
],
"pages": {
"next_url": None::<String>,
},
})
.to_string(),
)
.create_async()
.await;
})
.to_string(),
)
.create_async()
.await;

assert_eq!(
client.vocabulary().await?,
Expand Down

0 comments on commit 406d32c

Please sign in to comment.