Default to isort's import sort logic (#691)

This commit is contained in:
Charlie Marsh
2022-11-11 22:41:39 -05:00
committed by GitHub
parent 048a13c795
commit 558883299a
10 changed files with 231 additions and 122 deletions

View File

@@ -1,5 +1,6 @@
pub mod builtins;
pub mod future;
pub mod keyword;
pub mod string;
pub mod sys;
pub mod typing;

50
src/python/string.rs Normal file
View File

@@ -0,0 +1,50 @@
pub fn is_lower(s: &str) -> bool {
let mut cased = false;
for c in s.chars() {
if c.is_uppercase() {
return false;
} else if !cased && c.is_lowercase() {
cased = true;
}
}
cased
}
pub fn is_upper(s: &str) -> bool {
let mut cased = false;
for c in s.chars() {
if c.is_lowercase() {
return false;
} else if !cased && c.is_uppercase() {
cased = true;
}
}
cased
}
#[cfg(test)]
mod tests {
use crate::python::string::{is_lower, is_upper};
#[test]
fn test_is_lower() -> () {
assert!(is_lower("abc"));
assert!(is_lower("a_b_c"));
assert!(is_lower("a2c"));
assert!(!is_lower("aBc"));
assert!(!is_lower("ABC"));
assert!(!is_lower(""));
assert!(!is_lower("_"));
}
#[test]
fn test_is_upper() -> () {
assert!(is_upper("ABC"));
assert!(is_upper("A_B_C"));
assert!(is_upper("A2C"));
assert!(!is_upper("aBc"));
assert!(!is_upper("abc"));
assert!(!is_upper(""));
assert!(!is_upper("_"));
}
}