These are chat archives for Latrasis/petrovich-rs

19th
Feb 2016
Aleksey Troitskiy
@road21
Feb 19 2016 13:31
Заметил странный тест:
assert_eq!("Лёшы",
               subject.firstname(Gender::Male, "Лёша", Case::Genitive).unwrap());
По-русски, должно быть "Леши". Другое дело, что тест не совсем корректный, надо тестировать "Алексей".
Aleksey Troitskiy
@road21
Feb 19 2016 13:39
This message was deleted
Aleksey Troitskiy
@road21
Feb 19 2016 15:53
И почему все тесты с фамилиями только на дательный падеж?
Aleksey Troitskiy
@road21
Feb 19 2016 16:46
pub fn firstname(&self, gender: Gender, name: &str, case: Case) -> Result<String, &str> {

        // First Let's Check for Exceptions
        find_exception(&self.firstname["exceptions"], name, gender)
        // Then Check for Suffixes
        .or(find_suffix(&self.firstname["suffixes"], name, gender))
            // If no matching found return error
            .ok_or("No Matching Firstname Rule Found")
            // Then Inflect Name using matched rule
            .and_then(|rule| Ok(Petrovich::inflect(name, rule, case)))
    }

    pub fn middlename(&self, gender: Gender, name: &str, case: Case) -> Result<String, &str> {

        // First Let's Check for Exceptions
        find_exception(&self.middlename["exceptions"], name, gender)
        // Then Check for Suffixes
        .or(find_suffix(&self.middlename["suffixes"], name, gender))
            // If no matching found return error
            .ok_or("No Matching Middlename Rule Found")
            // Then Inflect Name using matched rule
            .and_then(|rule| Ok(Petrovich::inflect(name, rule, case)))
    }

    pub fn lastname(&self, gender: Gender, name: &str, case: Case) -> Result<String, &str> {

        // First Let's Check for Exceptions
        find_exception(&self.lastname["exceptions"], name, gender)
        // Then Check for Suffixes
        .or(find_suffix(&self.lastname["suffixes"], name, gender))
            // If no matching found return error
            .ok_or("No Matching Lastname Rule Found")
            // Then Inflect Name using matched rule
            .and_then(|rule| Ok(Petrovich::inflect(name, rule, case)))
    }
Этот кусок кода - Copy+Paste.
Может, есть способ написать это через вспомогательный метод?