whatisinternet / Inflector

A rust inflection library
https://docs.rs/Inflector
BSD 2-Clause "Simplified" License
126 stars 28 forks source link

Wrong converting to class case #76

Open WaffleLapkin opened 4 years ago

WaffleLapkin commented 4 years ago

This code:

assert_eq!(
    inflector::cases::classcase::to_class_case("editMessageMedia"), 
    "EditMessageMedia"
);

Fails with this error:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"EditMessageMedum"`,
 right: `"EditMessageMedia"`', src/main.rs:228:5
hgomersall commented 4 years ago

This happens on i or t in the second last position or s in the last position (when the second last is not s:

use inflector::Inflector;

fn main() {

    for b_last_letter in b'a'..=b'z' {
        let last_letter = b_last_letter as char;

        for b_mid_letter in b'a'..=b'z' {
            let mid_letter = b_mid_letter as char;
            let class_case_string =
                format!("a{}{}", mid_letter, last_letter).to_class_case();

            if class_case_string != format!("A{}{}", mid_letter, last_letter) {
                println!("a{}{} => {}", 
                    mid_letter, last_letter, class_case_string);
            }
        }
    }
}

outputs:

aia => Aum
ata => Aum
aas => Aa
abs => Ab
acs => Ac
ads => Ad
aes => Ae
afs => Af
ags => Ag
ahs => Ah
ais => Ai
ajs => Aj
aks => Ak
als => Al
ams => Am
ans => An
aos => Ao
aps => Ap
aqs => Aq
ars => Ar
ats => At
aus => Au
avs => Av
aws => Aw
axs => Ax
ays => Ay
azs => Az
hgomersall commented 4 years ago

The problem is the final to_singular().

This seems like the wrong behaviour to me...