From 40b16ebf81b4679c98c96740525835ed3fe4e18c Mon Sep 17 00:00:00 2001 From: Equim Date: Fri, 2 Feb 2024 21:12:35 +0800 Subject: [PATCH] ci: add typos and fix clippy --- .github/workflows/build.yml | 3 ++ convlog/src/tenhou/log.rs | 6 ++-- convlog/src/tile.rs | 60 ++++++++++++++++++------------------- mjsoul.adoc | 2 +- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61c2da9..b5cca10 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: typos-action + uses: crate-ci/typos@v1.18.0 + - name: Install Rust stable run: | set -x diff --git a/convlog/src/tenhou/log.rs b/convlog/src/tenhou/log.rs index aac1961..e6447bd 100644 --- a/convlog/src/tenhou/log.rs +++ b/convlog/src/tenhou/log.rs @@ -33,7 +33,7 @@ pub enum GameLength { Tonpuu = 4, } -/// Contains infomation about a kyoku. +/// Contains information about a kyoku. #[derive(Debug, Clone)] pub struct Kyoku { pub meta: KyokuMeta, @@ -133,14 +133,14 @@ impl TryFrom for Log { }, }; - if let Some(ResultItem::Status(status_text)) = log.results.get(0) { + if let Some(ResultItem::Status(status_text)) = log.results.first() { if status_text == "和了" { let mut details = vec![]; for detail_tuple in log.results[1..].chunks_exact(2) { if let [ResultItem::ScoreDeltas(score_deltas), ResultItem::HoraDetail(who_target_tuple)] = detail_tuple { - let who = if let Some(Value::Number(n)) = who_target_tuple.get(0) { + let who = if let Some(Value::Number(n)) = who_target_tuple.first() { n.as_u64().unwrap_or(0) as u8 } else { return Err(ParseError::InvalidHoraDetail); diff --git a/convlog/src/tile.rs b/convlog/src/tile.rs index a90d518..6a83e32 100644 --- a/convlog/src/tile.rs +++ b/convlog/src/tile.rs @@ -250,36 +250,6 @@ impl fmt::Display for InvalidTile { impl Error for InvalidTile {} -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn convert() { - "E".parse::().unwrap(); - "5mr".parse::().unwrap(); - "?".parse::().unwrap(); - Tile::try_from(0_u8).unwrap(); - Tile::try_from(36_u8).unwrap(); - Tile::try_from(37_u8).unwrap(); - - "".parse::().unwrap_err(); - "0s".parse::().unwrap_err(); - "!".parse::().unwrap_err(); - Tile::try_from(38_u8).unwrap_err(); - Tile::try_from(u8::MAX).unwrap_err(); - } - - #[test] - fn next_prev() { - MJAI_PAI_STRINGS.iter().take(37).for_each(|&s| { - let tile: Tile = s.parse().unwrap(); - assert_eq!(tile.prev().next(), tile.deaka()); - assert_eq!(tile.next().prev(), tile.deaka()); - }); - } -} - /** * Added in mjai-reviewer */ @@ -336,3 +306,33 @@ pub fn tile_set_eq(a: &[Tile], b: &[Tile], ignore_aka: bool) -> bool { a_bits == b_bits } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn convert() { + "E".parse::().unwrap(); + "5mr".parse::().unwrap(); + "?".parse::().unwrap(); + Tile::try_from(0_u8).unwrap(); + Tile::try_from(36_u8).unwrap(); + Tile::try_from(37_u8).unwrap(); + + "".parse::().unwrap_err(); + "0s".parse::().unwrap_err(); + "!".parse::().unwrap_err(); + Tile::try_from(38_u8).unwrap_err(); + Tile::try_from(u8::MAX).unwrap_err(); + } + + #[test] + fn next_prev() { + MJAI_PAI_STRINGS.iter().take(37).for_each(|&s| { + let tile: Tile = s.parse().unwrap(); + assert_eq!(tile.prev().next(), tile.deaka()); + assert_eq!(tile.next().prev(), tile.deaka()); + }); + } +} diff --git a/mjsoul.adoc b/mjsoul.adoc index b72cce5..42b28ce 100644 --- a/mjsoul.adoc +++ b/mjsoul.adoc @@ -4,7 +4,7 @@ == Background (back in 2021) Downloading logs from mjsoul is more difficult than from tenhou because it requires a login and the log formats are different. -For a long time, the reviewer had been able to retrieve mjsoul logs via https://github.com/Equim-chan/tensoul[tensoul,window=_blank], a tool I wrote to automate the process of login to mjsoul with an account, download of the logs and convertions to tenhou format. I created a dummy account and deployed a tensoul on heroku to provide a more accessible service, then the reviewer could retrieve logs in tenhou format directly by accessing the tensoul instance's API. This was once https://github.com/Equim-chan/mjai-reviewer/blob/b815e32e58414361de5b4af5748cabeb6085e9cb/src/download.rs#L5[hard coded,window=_blank] in akochan-reviewer. +For a long time, the reviewer had been able to retrieve mjsoul logs via https://github.com/Equim-chan/tensoul[tensoul,window=_blank], a tool I wrote to automate the process of login to mjsoul with an account, download of the logs and conversions to tenhou format. I created a dummy account and deployed a tensoul on heroku to provide a more accessible service, then the reviewer could retrieve logs in tenhou format directly by accessing the tensoul instance's API. This was once https://github.com/Equim-chan/mjai-reviewer/blob/b815e32e58414361de5b4af5748cabeb6085e9cb/src/download.rs#L5[hard coded,window=_blank] in akochan-reviewer. However, the heroku instance where tensoul is deployed (`\https://tensoul.herokuapp.com`) seems to be banned by mjsoul recently as the login command keeps getting error code 151. Migrating the instance to another region could mitigate the problem, but I have already done it once. Currently both of the two regions heroku provides are banned and I have no choice.