Skip to content

Commit

Permalink
ci: add typos and fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Equim-chan committed Feb 2, 2024
1 parent 5d939d5 commit 40b16eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions convlog/src/tenhou/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -133,14 +133,14 @@ impl TryFrom<RawLog> 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);
Expand Down
60 changes: 30 additions & 30 deletions convlog/src/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,36 +250,6 @@ impl fmt::Display for InvalidTile {

impl Error for InvalidTile {}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn convert() {
"E".parse::<Tile>().unwrap();
"5mr".parse::<Tile>().unwrap();
"?".parse::<Tile>().unwrap();
Tile::try_from(0_u8).unwrap();
Tile::try_from(36_u8).unwrap();
Tile::try_from(37_u8).unwrap();

"".parse::<Tile>().unwrap_err();
"0s".parse::<Tile>().unwrap_err();
"!".parse::<Tile>().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
*/
Expand Down Expand Up @@ -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::<Tile>().unwrap();
"5mr".parse::<Tile>().unwrap();
"?".parse::<Tile>().unwrap();
Tile::try_from(0_u8).unwrap();
Tile::try_from(36_u8).unwrap();
Tile::try_from(37_u8).unwrap();

"".parse::<Tile>().unwrap_err();
"0s".parse::<Tile>().unwrap_err();
"!".parse::<Tile>().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());
});
}
}
2 changes: 1 addition & 1 deletion mjsoul.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 40b16eb

Please sign in to comment.