penmanship 0.1.0

A Unicode character lookup library for converting text patterns to Unicode characters
Documentation
//! Mathematical operator and symbol mappings.

use phf::phf_map;

/// Mathematical operator and symbol mappings.
///
/// Includes operators, arrows, set theory symbols, and other mathematical notation.
pub static MATH: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! {
    // Basic operators
    "+-" => ("\u{00B1}", "plus-minus sign"),                // ±
    "*" => ("\u{00D7}", "multiplication sign"),             // ×
    "x" => ("\u{00D7}", "multiplication sign"),             // ×
    "div" => ("\u{00F7}", "division sign"),                 // ÷
    "divide" => ("\u{00F7}", "division sign"),              // ÷
    "!=" => ("\u{2260}", "not equal to"),                   //    "ne" => ("\u{2260}", "not equal to"),                   //    "<=" => ("\u{2264}", "less-than or equal to"),          //    "lte" => ("\u{2264}", "less-than or equal to"),         //    ">=" => ("\u{2265}", "greater-than or equal to"),       //    "gte" => ("\u{2265}", "greater-than or equal to"),      //    "~=" => ("\u{2248}", "almost equal to"),                //
    // Arrows
    "->" => ("\u{2192}", "rightwards arrow"),               //    "<-" => ("\u{2190}", "leftwards arrow"),                //    "<->" => ("\u{2194}", "left right arrow"),              //    "=>" => ("\u{21D2}", "rightwards double arrow"),        //    "<=>" => ("\u{21D4}", "left right double arrow"),       //    "^^" => ("\u{2191}", "upwards arrow"),                  //    "up" => ("\u{2191}", "upwards arrow"),                  //    "vv" => ("\u{2193}", "downwards arrow"),                //    "down" => ("\u{2193}", "downwards arrow"),              //
    // Advanced symbols
    "infinity" => ("\u{221E}", "infinity"),                 //    "inf" => ("\u{221E}", "infinity"),                      //    "sum" => ("\u{2211}", "n-ary summation"),               //    "product" => ("\u{220F}", "n-ary product"),             //    "prod" => ("\u{220F}", "n-ary product"),                //    "sqrt" => ("\u{221A}", "square root"),                  //    "integral" => ("\u{222B}", "integral"),                 //    "int" => ("\u{222B}", "integral"),                      //    "partial" => ("\u{2202}", "partial differential"),      //    "nabla" => ("\u{2207}", "nabla"),                       //    "in" => ("\u{2208}", "element of"),                     //    "notin" => ("\u{2209}", "not an element of"),           //    "subset" => ("\u{2282}", "subset of"),                  //    "superset" => ("\u{2283}", "superset of"),              //    "union" => ("\u{222A}", "union"),                       //    "intersection" => ("\u{2229}", "intersection"),         //    "intersect" => ("\u{2229}", "intersection"),            //    "forall" => ("\u{2200}", "for all"),                    //    "exists" => ("\u{2203}", "there exists"),               //    "empty" => ("\u{2205}", "empty set"),                   //    "emptyset" => ("\u{2205}", "empty set"),                //    "propto" => ("\u{221D}", "proportional to"),            //};

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

    /// Test basic math operators.
    #[test]
    fn test_basic_operators() {
        assert_eq!(MATH.get("+-"), Some(&("\u{00B1}", "plus-minus sign")));
        assert_eq!(MATH.get("!="), Some(&("\u{2260}", "not equal to")));
        assert_eq!(MATH.get("<="), Some(&("\u{2264}", "less-than or equal to")));
        assert_eq!(
            MATH.get(">="),
            Some(&("\u{2265}", "greater-than or equal to"))
        );
    }

    /// Test arrow symbols.
    #[test]
    fn test_arrows() {
        assert_eq!(MATH.get("->"), Some(&("\u{2192}", "rightwards arrow")));
        assert_eq!(MATH.get("<-"), Some(&("\u{2190}", "leftwards arrow")));
        assert_eq!(
            MATH.get("=>"),
            Some(&("\u{21D2}", "rightwards double arrow"))
        );
    }

    /// Test advanced mathematical symbols.
    #[test]
    fn test_advanced_symbols() {
        assert_eq!(MATH.get("infinity"), Some(&("\u{221E}", "infinity")));
        assert_eq!(MATH.get("sum"), Some(&("\u{2211}", "n-ary summation")));
        assert_eq!(MATH.get("integral"), Some(&("\u{222B}", "integral")));
    }

    /// Test set theory symbols.
    #[test]
    fn test_set_theory() {
        assert_eq!(MATH.get("in"), Some(&("\u{2208}", "element of")));
        assert_eq!(MATH.get("union"), Some(&("\u{222A}", "union")));
        assert_eq!(
            MATH.get("intersection"),
            Some(&("\u{2229}", "intersection"))
        );
        assert_eq!(MATH.get("empty"), Some(&("\u{2205}", "empty set")));
    }
}