diff --git a/.github/workflows/action-rs/grcov.yml b/.github/workflows/action-rs/grcov.yml new file mode 100644 index 0000000..07c7795 --- /dev/null +++ b/.github/workflows/action-rs/grcov.yml @@ -0,0 +1,7 @@ +branch: true +ignore-not-existing: true +llvm: true +filter: covered +output-type: lcov +output-path: ./lcov.info +prefix-dir: /home/user/build \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..d3a9bfd --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,109 @@ +name: Rust + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: Build and Test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - name: Run tests + uses: actions-rs/cargo@v1 + with: + command: test + env: + CARGO_INCREMENTAL: '0' + RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + - name: Run grcov + id: coverage + uses: actions-rs/grcov@v0.1 + - name: Coveralls upload + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ${{ steps.coverage.outputs.report }} + - name: Run clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --verbose + - name: Run formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --check + - name: Build release + uses: actions-rs/cargo@v1 + with: + command: build + args: --release + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: uuid-remapper-x86_64-linux + path: target/release/uuid-remapper + + windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - name: Test + uses: actions-rs/cargo@v1 + with: + command: test + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: uuid-remapper-x86_64-windows.exe + path: target/release/uuid-remapper.exe + + macos: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + - name: Test + uses: actions-rs/cargo@v1 + with: + command: test + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: uuid-remapper-x86_64-macos + path: target/release/uuid-remapper \ No newline at end of file diff --git a/src/anvil.rs b/src/anvil.rs index 1d4c404..d92c970 100644 --- a/src/anvil.rs +++ b/src/anvil.rs @@ -159,9 +159,11 @@ impl Anvil { .next() .and_then(|s| s.parse::().ok()) .context("Invalid z coordinate")?; - Ok(self - .path - .with_file_name(format!("c.{}.{}.mcc", x * 32 + local.0 as i64, z * 32 + local.1 as i64))) + Ok(self.path.with_file_name(format!( + "c.{}.{}.mcc", + x * 32 + local.0 as i64, + z * 32 + local.1 as i64 + ))) } /// Open an anvil file @@ -317,12 +319,14 @@ fn test() { assert_eq!(chunk.timestamp, chunk_read.timestamp); assert_eq!(chunk.uncompressed, chunk_read.uncompressed); assert_eq!(true, chunk_read.external); - anvil.write(&Chunk { - external: true, - location: (0, 0), - timestamp: 0, - uncompressed: vec![0; 1024], - }).unwrap(); + anvil + .write(&Chunk { + external: true, + location: (0, 0), + timestamp: 0, + uncompressed: vec![0; 1024], + }) + .unwrap(); assert!(!Path::new("c.-32.-32.mcc").exists()); // TODO: Poor test coverage diff --git a/src/main.rs b/src/main.rs index 98d06ba..b645b7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,11 +46,15 @@ fn main() { .unwrap(); if std::mem::size_of::() < 8 { - log::error!("usize is less than 64-bit, you may encounter integer overflow when \ - dealing with some malformed NBT"); + log::error!( + "usize is less than 64-bit, you may encounter integer overflow when \ + dealing with some malformed NBT" + ); log::error!("Do not report this issue to the author, as it is not worth fixing"); - log::error!("Since Minecraft almost can't run on 32-bit devices, \ - running this program, which is designed to work with Minecraft, is meaningless"); + log::error!( + "Since Minecraft almost can't run on 32-bit devices, \ + running this program, which is designed to work with Minecraft, is meaningless" + ); } let path = cli.path; diff --git a/src/mapping.rs b/src/mapping.rs index f4047ab..134fd6e 100644 --- a/src/mapping.rs +++ b/src/mapping.rs @@ -155,35 +155,35 @@ pub fn get_mapping(kind: MappingKind, path: &Path) -> anyhow::Result { let map = std::fs::read_to_string(path)?; Ok(serde_json::from_str(&map)?) - }, + } MappingKind::ListToOffline => { let names = load_name_list(path)?; Ok(a_compose_b_inverse( &online_uuids(&names), &offline_uuids(&names), )) - }, + } MappingKind::ListToOnline => { let names = load_name_list(path)?; Ok(a_compose_b_inverse( &offline_uuids(&names), &online_uuids(&names), )) - }, + } MappingKind::UsercacheToOffline => { let names = load_name_list_from_usercache(path)?; Ok(a_compose_b_inverse( &online_uuids(&names), &offline_uuids(&names), )) - }, + } MappingKind::UsercacheToOnline => { let names = load_name_list_from_usercache(path)?; Ok(a_compose_b_inverse( &offline_uuids(&names), &online_uuids(&names), )) - }, + } MappingKind::OfflineRenameCsv => load_offline_rename(path), } } @@ -199,8 +199,14 @@ fn test() { assert_eq!( get_mapping(MappingKind::Csv, &csv_path).unwrap(), vec![ - (Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap()), - (Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap()), + ( + Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(), + Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap() + ), + ( + Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(), + Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap() + ), ] .into_iter() .collect() @@ -216,8 +222,14 @@ fn test() { assert_eq!( get_mapping(MappingKind::Json, &json_path).unwrap(), vec![ - (Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap()), - (Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap()), + ( + Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(), + Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap() + ), + ( + Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(), + Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap() + ), ] .into_iter() .collect() @@ -229,11 +241,7 @@ fn test() { std::fs::write(&list_path, list_file).unwrap(); assert_eq!( load_name_list(&list_path).unwrap(), - vec![ - "a".to_string(), - "b".to_string(), - "c".to_string(), - ] + vec!["a".to_string(), "b".to_string(), "c".to_string(),] ); std::fs::remove_file(list_path).unwrap(); @@ -242,11 +250,7 @@ fn test() { std::fs::write(&usercache_path, usercache_file).unwrap(); assert_eq!( load_name_list_from_usercache(&usercache_path).unwrap(), - vec![ - "a".to_string(), - "b".to_string(), - "c".to_string(), - ] + vec!["a".to_string(), "b".to_string(), "c".to_string(),] ); std::fs::remove_file(usercache_path).unwrap(); @@ -264,6 +268,9 @@ fn test() { ); std::fs::remove_file(offline_rename_path).unwrap(); - assert_eq!(offline_uuid("CaveNightingale"), Uuid::from_str("2d318504-1a7b-39dc-8c18-44df798a5c06").unwrap()); + assert_eq!( + offline_uuid("CaveNightingale"), + Uuid::from_str("2d318504-1a7b-39dc-8c18-44df798a5c06").unwrap() + ); // Online UUIDs are not tested because it requires network access } diff --git a/src/nbt.rs b/src/nbt.rs index f8a2915..3192319 100644 --- a/src/nbt.rs +++ b/src/nbt.rs @@ -371,7 +371,7 @@ fn test_visit_nbt() { de.get("yyUUIDLeast"), Some(&Value::Long(FROM.as_u64_pair().1 as i64)) ); // Should not be replaced - // No root tag + // No root tag let mut nbt = vec![]; assert!(visit_nbt(&mut nbt, &mut |_| None).is_err()); // Non-long UUIDMost/UUIDLeast diff --git a/src/remap.rs b/src/remap.rs index 068eee2..1d296cf 100644 --- a/src/remap.rs +++ b/src/remap.rs @@ -151,5 +151,6 @@ fn test() { None } }, - ).unwrap(); + ) + .unwrap(); } diff --git a/src/text.rs b/src/text.rs index 4ae4d78..fe86a4a 100644 --- a/src/text.rs +++ b/src/text.rs @@ -47,7 +47,7 @@ pub fn visit_text(text: &mut [u8], cb: &impl Fn(Uuid) -> Option) { macro_rules! dfa_trans_table { {$( $current:pat => $next:expr; $other:expr; )*} => { matched = match matched { - $($current => if text[i] == b'_' { + $($current => if text[i] == b'-' { $next } else { $other