summaryrefslogtreecommitdiffstats
path: root/src/tests/test_utils.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-08-02 11:43:47 -0400
committerDan Davison <dandavison7@gmail.com>2020-08-02 12:24:20 -0400
commitdc6737ad5776407a071c234c610003ffb8c5dc22 (patch)
treebde20ac15c858eb9cd8263b1a6a8c7bcc4786edd /src/tests/test_utils.rs
parent4a2ddc430e88bb6454032c8d2cfc4f7d3485b8d8 (diff)
Add failing test: duplicated header when file renamed with changes
Reproduces bug #245
Diffstat (limited to 'src/tests/test_utils.rs')
-rw-r--r--src/tests/test_utils.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tests/test_utils.rs b/src/tests/test_utils.rs
new file mode 100644
index 00000000..054365d2
--- /dev/null
+++ b/src/tests/test_utils.rs
@@ -0,0 +1,45 @@
+#[cfg(test)]
+pub mod test_utils {
+ /// Return true iff `s` contains exactly one occurrence of substring `t`.
+ pub fn contains_once(s: &str, t: &str) -> bool {
+ match (s.find(t), s.rfind(t)) {
+ (Some(i), Some(j)) => i == j,
+ _ => false,
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::test_utils::test_utils::*;
+
+ #[test]
+ fn test_contains_once_1() {
+ assert!(contains_once("", ""));
+ }
+
+ #[test]
+ fn test_contains_once_2() {
+ assert!(contains_once("a", "a"));
+ }
+
+ #[test]
+ fn test_contains_once_3() {
+ assert!(!contains_once("", "a"));
+ }
+
+ #[test]
+ fn test_contains_once_4() {
+ assert!(!contains_once("a", "b"));
+ }
+
+ #[test]
+ fn test_contains_once_5() {
+ assert!(!contains_once("a a", "a"));
+ }
+
+ #[test]
+ fn test_contains_once_6() {
+ assert!(contains_once("a b", "b"));
+ }
+}