Forge-core keeps its stamp ordering and closing keyword spec tests
Browse files at this commit868c8a695fa532ac52335d7c8817d969266e8ba0Parent: 654f528- test
- forge-core keeps its stamp ordering and closing keyword spec tests
2 changed files +38 -0
crates/forge-core/src/issue_refs.rsmodified+10 -0
| @@ -152,4 +152,14 @@ mod tests { | |||
| 152 | assert_eq!(find_closing_refs(text), *want, "case {text:?}"); | 152 | assert_eq!(find_closing_refs(text), *want, "case {text:?}"); |
| 153 | } | 153 | } |
| 154 | } | 154 | } |
| 155 | + | ||
| 156 | + #[test] | ||
| 157 | + fn all_keywords_are_case_insensitive() { | ||
| 158 | + for kw in [ | ||
| 159 | + "close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved", | ||
| 160 | + ] { | ||
| 161 | + let text = format!("{}: #5", kw.to_uppercase()); | ||
| 162 | + assert_eq!(find_closing_refs(&text), vec![5], "{kw}"); | ||
| 163 | + } | ||
| 164 | + } | ||
| 155 | } | 165 | } |
crates/forge-core/src/time.rsmodified+28 -0
| @@ -46,3 +46,31 @@ pub fn stamp_to_unix(stamp: &str) -> Option<i64> { | |||
| 46 | .ok() | 46 | .ok() |
| 47 | .map(OffsetDateTime::unix_timestamp) | 47 | .map(OffsetDateTime::unix_timestamp) |
| 48 | } | 48 | } |
| 49 | + | ||
| 50 | +#[cfg(test)] | ||
| 51 | +mod tests { | ||
| 52 | + use super::*; | ||
| 53 | + | ||
| 54 | + fn is_valid_stamp(s: &str) -> bool { | ||
| 55 | + let b = s.as_bytes(); | ||
| 56 | + b.len() == 30 | ||
| 57 | + && b[4] == b'-' | ||
| 58 | + && b[7] == b'-' | ||
| 59 | + && b[10] == b'T' | ||
| 60 | + && b[13] == b':' | ||
| 61 | + && b[16] == b':' | ||
| 62 | + && b[19] == b'.' | ||
| 63 | + && b[29] == b'Z' | ||
| 64 | + && b[20..29].iter().all(u8::is_ascii_digit) | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + #[test] | ||
| 68 | + fn stamps_sort_lexicographically_in_time_order() { | ||
| 69 | + let a = now_stamp(); | ||
| 70 | + let b = stamp_after(Duration::from_secs(3600)); | ||
| 71 | + assert!(is_valid_stamp(&b), "bad stamp: {b}"); | ||
| 72 | + assert!(a < b); | ||
| 73 | + let c = stamp_after(Duration::from_secs(7200)); | ||
| 74 | + assert!(b < c); | ||
| 75 | + } | ||
| 76 | +} | ||