Skip to content

Commit

Permalink
use the '/' character as the primary separator on Windows as well (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaa110 authored Jan 15, 2025
1 parent 3994459 commit 27304c1
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo test
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo test
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
name = "nomino"
readme = "README.md"
repository = "https://github.com/yaa110/nomino"
version = "1.5.0"
version = "1.5.1"

[dependencies]
anyhow = "1.0"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Options:
OUTPUT pattern accepts placeholders that have the format of '{I:P}' where 'I' is the index of captured group and 'P' is the padding of digits with `0`. Please refer to https://github.com/yaa110/nomino for more information.
```
### Windows
On Windows, `\\` must be used to separate path components in file paths because `\` is a special character in regular expressions.

## Map file format

```json
Expand Down
5 changes: 5 additions & 0 deletions src/input/separator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(not(target_os = "windows"))]
pub const MAIN_SEPARATOR: &str = "/";

#[cfg(target_os = "windows")]
pub const MAIN_SEPARATOR: &str = "\\\\";
5 changes: 3 additions & 2 deletions src/input/source.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::cli;
use crate::input::MAIN_SEPARATOR;
use anyhow::Result;
use regex::Regex;
use std::collections::HashMap;
use std::fs;
use std::path::{Path, MAIN_SEPARATOR};
use std::path::Path;

#[derive(PartialEq)]
pub enum SortOrder {
Expand All @@ -25,7 +26,7 @@ impl Source {
) -> Result<Self> {
Ok(Self::Regex(
Regex::new(pattern)?,
depth.unwrap_or(pattern.chars().filter(|c| *c == MAIN_SEPARATOR).count() + 1),
depth.unwrap_or(pattern.matches(MAIN_SEPARATOR).count() + 1),
max_depth,
))
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ pub mod cli;
pub mod input {
mod formatter;
mod iterator;
mod separator;
mod source;
pub use self::formatter::*;
pub use self::iterator::*;
pub use self::separator::*;
pub use self::source::*;
}

Expand Down
10 changes: 1 addition & 9 deletions tests/default_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use assert_cmd::Command;
use nomino::input::MAIN_SEPARATOR;
use std::fs::create_dir_all;
use std::fs::read_dir;
use std::fs::File;
use std::path::MAIN_SEPARATOR;

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -49,7 +48,6 @@ fn test_default() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_not_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -94,7 +92,6 @@ fn test_default_not_overwrite() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -140,7 +137,6 @@ fn test_default_overwrite() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_subdir() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -200,7 +196,6 @@ fn test_default_subdir() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_subdir_depth() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -262,7 +257,6 @@ fn test_default_subdir_depth() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_subdir_max_depth() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -326,7 +320,6 @@ fn test_default_subdir_max_depth() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_subdir_not_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -386,7 +379,6 @@ fn test_default_subdir_not_overwrite() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_default_subdir_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down
1 change: 0 additions & 1 deletion tests/map_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::fs::read_dir;
use std::fs::File;
use std::io::Write;

#[cfg(not(target_os = "windows"))]
#[test]
fn test_map() {
let dir = tempfile::tempdir().unwrap();
Expand Down
10 changes: 1 addition & 9 deletions tests/regex_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use assert_cmd::Command;
use nomino::input::MAIN_SEPARATOR;
use std::fs::create_dir_all;
use std::fs::read_dir;
use std::fs::File;
use std::path::MAIN_SEPARATOR;

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -50,7 +49,6 @@ fn test_regex() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_not_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -96,7 +94,6 @@ fn test_regex_not_overwrite() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -143,7 +140,6 @@ fn test_regex_overwrite() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_subdir() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -204,7 +200,6 @@ fn test_regex_subdir() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_subdir_depth() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -267,7 +262,6 @@ fn test_regex_subdir_depth() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_subdir_max_depth() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -332,7 +326,6 @@ fn test_regex_subdir_max_depth() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_subdir_not_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -393,7 +386,6 @@ fn test_regex_subdir_not_overwrite() {
dir.close().unwrap();
}

#[cfg(not(target_os = "windows"))]
#[test]
fn test_regex_subdir_overwrite() {
let dir = tempfile::tempdir().unwrap();
Expand Down
1 change: 0 additions & 1 deletion tests/sort_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use assert_cmd::Command;
use std::fs::read_dir;
use std::fs::File;

#[cfg(not(target_os = "windows"))]
#[test]
fn test_sort() {
let dir = tempfile::tempdir().unwrap();
Expand Down

0 comments on commit 27304c1

Please sign in to comment.