Skip to content

Commit 0dc779e

Browse files
committed
use the '\\' as the primary separator on Windows
1 parent 3994459 commit 0dc779e

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ jobs:
2323
- uses: actions/checkout@v4
2424
- uses: actions-rust-lang/setup-rust-toolchain@v1
2525
- run: cargo test
26+
windows:
27+
runs-on: windows-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: actions-rust-lang/setup-rust-toolchain@v1
31+
- run: cargo test

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
88
name = "nomino"
99
readme = "README.md"
1010
repository = "https://github.com/yaa110/nomino"
11-
version = "1.5.0"
11+
version = "1.5.2"
1212

1313
[dependencies]
1414
anyhow = "1.0"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Options:
5959
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.
6060
```
6161
62+
### Windows
63+
64+
On Windows, `\\` must be used to separate path components in file paths because `\` is a special character in regular expressions.
65+
6266
## Map file format
6367

6468
```json

src/input/separator.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[cfg(not(target_os = "windows"))]
2+
pub const MAIN_SEPARATOR: &str = "/";
3+
4+
#[cfg(target_os = "windows")]
5+
pub const MAIN_SEPARATOR: &str = "\\\\";

src/input/source.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::cli;
2+
use crate::input::MAIN_SEPARATOR;
23
use anyhow::Result;
34
use regex::Regex;
45
use std::collections::HashMap;
56
use std::fs;
6-
use std::path::{Path, MAIN_SEPARATOR};
7+
use std::path::Path;
78

89
#[derive(PartialEq)]
910
pub enum SortOrder {
@@ -25,7 +26,7 @@ impl Source {
2526
) -> Result<Self> {
2627
Ok(Self::Regex(
2728
Regex::new(pattern)?,
28-
depth.unwrap_or(pattern.chars().filter(|c| *c == MAIN_SEPARATOR).count() + 1),
29+
depth.unwrap_or(pattern.matches(MAIN_SEPARATOR).count() + 1),
2930
max_depth,
3031
))
3132
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ pub mod cli;
33
pub mod input {
44
mod formatter;
55
mod iterator;
6+
mod separator;
67
mod source;
78
pub use self::formatter::*;
89
pub use self::iterator::*;
10+
pub use self::separator::*;
911
pub use self::source::*;
1012
}
1113

tests/default_test.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use assert_cmd::Command;
2+
use nomino::input::MAIN_SEPARATOR;
23
use std::fs::create_dir_all;
34
use std::fs::read_dir;
45
use std::fs::File;
5-
use std::path::MAIN_SEPARATOR;
66

7-
#[cfg(not(target_os = "windows"))]
87
#[test]
98
fn test_default() {
109
let dir = tempfile::tempdir().unwrap();
@@ -49,7 +48,6 @@ fn test_default() {
4948
dir.close().unwrap();
5049
}
5150

52-
#[cfg(not(target_os = "windows"))]
5351
#[test]
5452
fn test_default_not_overwrite() {
5553
let dir = tempfile::tempdir().unwrap();
@@ -94,7 +92,6 @@ fn test_default_not_overwrite() {
9492
dir.close().unwrap();
9593
}
9694

97-
#[cfg(not(target_os = "windows"))]
9895
#[test]
9996
fn test_default_overwrite() {
10097
let dir = tempfile::tempdir().unwrap();
@@ -140,7 +137,6 @@ fn test_default_overwrite() {
140137
dir.close().unwrap();
141138
}
142139

143-
#[cfg(not(target_os = "windows"))]
144140
#[test]
145141
fn test_default_subdir() {
146142
let dir = tempfile::tempdir().unwrap();
@@ -200,7 +196,6 @@ fn test_default_subdir() {
200196
dir.close().unwrap();
201197
}
202198

203-
#[cfg(not(target_os = "windows"))]
204199
#[test]
205200
fn test_default_subdir_depth() {
206201
let dir = tempfile::tempdir().unwrap();
@@ -262,7 +257,6 @@ fn test_default_subdir_depth() {
262257
dir.close().unwrap();
263258
}
264259

265-
#[cfg(not(target_os = "windows"))]
266260
#[test]
267261
fn test_default_subdir_max_depth() {
268262
let dir = tempfile::tempdir().unwrap();
@@ -326,7 +320,6 @@ fn test_default_subdir_max_depth() {
326320
dir.close().unwrap();
327321
}
328322

329-
#[cfg(not(target_os = "windows"))]
330323
#[test]
331324
fn test_default_subdir_not_overwrite() {
332325
let dir = tempfile::tempdir().unwrap();
@@ -386,7 +379,6 @@ fn test_default_subdir_not_overwrite() {
386379
dir.close().unwrap();
387380
}
388381

389-
#[cfg(not(target_os = "windows"))]
390382
#[test]
391383
fn test_default_subdir_overwrite() {
392384
let dir = tempfile::tempdir().unwrap();

tests/map_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fs::read_dir;
33
use std::fs::File;
44
use std::io::Write;
55

6-
#[cfg(not(target_os = "windows"))]
76
#[test]
87
fn test_map() {
98
let dir = tempfile::tempdir().unwrap();

tests/regex_test.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use assert_cmd::Command;
2+
use nomino::input::MAIN_SEPARATOR;
23
use std::fs::create_dir_all;
34
use std::fs::read_dir;
45
use std::fs::File;
5-
use std::path::MAIN_SEPARATOR;
66

7-
#[cfg(not(target_os = "windows"))]
87
#[test]
98
fn test_regex() {
109
let dir = tempfile::tempdir().unwrap();
@@ -50,7 +49,6 @@ fn test_regex() {
5049
dir.close().unwrap();
5150
}
5251

53-
#[cfg(not(target_os = "windows"))]
5452
#[test]
5553
fn test_regex_not_overwrite() {
5654
let dir = tempfile::tempdir().unwrap();
@@ -96,7 +94,6 @@ fn test_regex_not_overwrite() {
9694
dir.close().unwrap();
9795
}
9896

99-
#[cfg(not(target_os = "windows"))]
10097
#[test]
10198
fn test_regex_overwrite() {
10299
let dir = tempfile::tempdir().unwrap();
@@ -143,7 +140,6 @@ fn test_regex_overwrite() {
143140
dir.close().unwrap();
144141
}
145142

146-
#[cfg(not(target_os = "windows"))]
147143
#[test]
148144
fn test_regex_subdir() {
149145
let dir = tempfile::tempdir().unwrap();
@@ -204,7 +200,6 @@ fn test_regex_subdir() {
204200
dir.close().unwrap();
205201
}
206202

207-
#[cfg(not(target_os = "windows"))]
208203
#[test]
209204
fn test_regex_subdir_depth() {
210205
let dir = tempfile::tempdir().unwrap();
@@ -267,7 +262,6 @@ fn test_regex_subdir_depth() {
267262
dir.close().unwrap();
268263
}
269264

270-
#[cfg(not(target_os = "windows"))]
271265
#[test]
272266
fn test_regex_subdir_max_depth() {
273267
let dir = tempfile::tempdir().unwrap();
@@ -332,7 +326,6 @@ fn test_regex_subdir_max_depth() {
332326
dir.close().unwrap();
333327
}
334328

335-
#[cfg(not(target_os = "windows"))]
336329
#[test]
337330
fn test_regex_subdir_not_overwrite() {
338331
let dir = tempfile::tempdir().unwrap();
@@ -393,7 +386,6 @@ fn test_regex_subdir_not_overwrite() {
393386
dir.close().unwrap();
394387
}
395388

396-
#[cfg(not(target_os = "windows"))]
397389
#[test]
398390
fn test_regex_subdir_overwrite() {
399391
let dir = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)