use std::path::PathBuf; use dupnamegen::{namegen, Naming}; struct TestCase { input: &'static str, winlike: [&'static str; 2], firefoxlike: [&'static str; 2], dashnum: [&'static str; 2] } const TESTCASE: [TestCase; 8] = [ TestCase { input: "hello", winlike: ["hello (1)", "hello (2)"], firefoxlike: ["hello(1)", "hello(2)"], dashnum: ["hello-1", "hello-2"] }, TestCase { input: "/tmp/hello", winlike: ["/tmp/hello (1)", "/tmp/hello (2)"], firefoxlike: ["/tmp/hello(1)", "/tmp/hello(2)"], dashnum: ["/tmp/hello-1", "/tmp/hello-2"] }, TestCase { input: "hello.txt", winlike: ["hello (1).txt", "hello (2).txt"], firefoxlike: ["hello(1).txt", "hello(2).txt"], dashnum: ["hello.txt-1", "hello.txt-2"] }, TestCase { input: "/tmp/hello.txt", winlike: ["/tmp/hello (1).txt", "/tmp/hello (2).txt"], firefoxlike: ["/tmp/hello(1).txt", "/tmp/hello(2).txt"], dashnum: ["/tmp/hello.txt-1", "/tmp/hello.txt-2"] }, TestCase { input: ".hello", winlike: [".hello (1)", ".hello (2)"], firefoxlike: [".hello(1)", ".hello(2)"], dashnum: [".hello-1", ".hello-2"] }, TestCase { input: "/tmp/.hello", winlike: ["/tmp/.hello (1)", "/tmp/.hello (2)"], firefoxlike: ["/tmp/.hello(1)", "/tmp/.hello(2)"], dashnum: ["/tmp/.hello-1", "/tmp/.hello-2"] }, TestCase { input: ".hello.txt", winlike: [".hello (1).txt", ".hello (2).txt"], firefoxlike: [".hello(1).txt", ".hello(2).txt"], dashnum: [".hello.txt-1", ".hello.txt-2"] }, TestCase { input: "/tmp/.hello.txt", winlike: ["/tmp/.hello (1).txt", "/tmp/.hello (2).txt"], firefoxlike: ["/tmp/.hello(1).txt", "/tmp/.hello(2).txt"], dashnum: ["/tmp/.hello.txt-1", "/tmp/.hello.txt-2"] } ]; #[test] fn batch() { for t in TESTCASE { let mut gen = namegen(t.input, Naming::WinLike, 1).unwrap(); assert_eq!( gen(), PathBuf::from(t.winlike[0]), "winlike input '{}'", t.input ); assert_eq!( gen(), PathBuf::from(t.winlike[1]), "winlike input '{}'", t.input ); let mut gen = namegen(t.input, Naming::FirefoxLike, 1).unwrap(); assert_eq!( gen(), PathBuf::from(t.firefoxlike[0]), "firefoxlike input '{}'", t.input ); assert_eq!( gen(), PathBuf::from(t.firefoxlike[1]), "firefoxlike input '{}'", t.input ); let mut gen = namegen(t.input, Naming::DashNum, 1).unwrap(); assert_eq!( gen(), PathBuf::from(t.dashnum[0]), "dashnum input '{}", t.input ); assert_eq!( gen(), PathBuf::from(t.dashnum[1]), "dashnum input '{}'", t.input ); } } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :