penmanship 0.1.0

A Unicode character lookup library for converting text patterns to Unicode characters
Documentation
//! Fraction character mappings.

use phf::phf_map;

/// Fraction character mappings.
///
/// Common fraction characters represented as Unicode glyphs.
pub static FRACTIONS: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! {
    "1/2" => ("\u{00BD}", "fraction one half"),          // ½
    "1/4" => ("\u{00BC}", "fraction one quarter"),       // ¼
    "3/4" => ("\u{00BE}", "fraction three quarters"),    // ¾
    "1/3" => ("\u{2153}", "fraction one third"),         //    "2/3" => ("\u{2154}", "fraction two thirds"),        //    "1/5" => ("\u{2155}", "fraction one fifth"),         //    "2/5" => ("\u{2156}", "fraction two fifths"),        //    "3/5" => ("\u{2157}", "fraction three fifths"),      //    "4/5" => ("\u{2158}", "fraction four fifths"),       //    "1/6" => ("\u{2159}", "fraction one sixth"),         //    "5/6" => ("\u{215A}", "fraction five sixths"),       //    "1/8" => ("\u{215B}", "fraction one eighth"),        //    "3/8" => ("\u{215C}", "fraction three eighths"),     //    "5/8" => ("\u{215D}", "fraction five eighths"),      //    "7/8" => ("\u{215E}", "fraction seven eighths"),     //};

#[cfg(test)]
mod tests {
    use super::*;

    /// Test common fraction lookups.
    #[test]
    fn test_common_fractions() {
        assert_eq!(
            FRACTIONS.get("1/2"),
            Some(&("\u{00BD}", "fraction one half"))
        );
        assert_eq!(
            FRACTIONS.get("1/4"),
            Some(&("\u{00BC}", "fraction one quarter"))
        );
        assert_eq!(
            FRACTIONS.get("3/4"),
            Some(&("\u{00BE}", "fraction three quarters"))
        );
    }

    /// Test thirds and fifths.
    #[test]
    fn test_thirds_and_fifths() {
        assert_eq!(
            FRACTIONS.get("1/3"),
            Some(&("\u{2153}", "fraction one third"))
        );
        assert_eq!(
            FRACTIONS.get("2/5"),
            Some(&("\u{2156}", "fraction two fifths"))
        );
    }
}