~jojo/kapreolo

6f065d641755fd63cb79c7c1eb6066f6f6982e2d — JoJo 2 months ago f0b5398 main
add some commented test ideas
1 files changed, 46 insertions(+), 0 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +46 -0
@@ 472,4 472,50 @@ mod test {
        ";
        assert_matches!(run_tmp(src), Ok(Operand::Const(Const::Int(32))))
    }

    // #[test]
    // fn test_type_synonym() {
    //     let src = "
    //         (defsyn Byte [] N8)
    //         (defsyn Pair [a b] [a b])
    //         (defsyn Be16 [] (Pair Byte Byte))
    //         (def read-n16-be (of (Fun [Be16] N16) (fun [x] (match x [[hi lo] (+ (* (as N16 lo) 8) (as N16 hi))]))))
    //         (def main (read-n16-be [2 16]))
    //     ";
    //     assert_matches!(run_tmp(src), Ok(Operand::Const(Const::N16(528))))
    // }

    // #[test]
    // fn test_nominal_type() {
    //     let src = "
    //         (nomtype Unsigned Nat)
    //         (def inc (of (Fun [Unsigned] Unsigned)))
    //         (def unwrap (fun [x] (match x [(Unsigned y) y])))
    //         (def main (unwrap (inc (Unsigned 1234))))
    //     ";
    //     assert_matches!(run_tmp(src), Ok(Operand::Const(Const::N16(1235))))
    // }

    // #[test]
    // fn test_type_err_nominal_type() {
    //     let src = "
    //         (nomtype Unsigned Nat)
    //         (def unwrap (fun [x] (match x [(Unsigned y) y])))
    //         (def main (unwrap (+ (of Int 500) (Unsigned 43))))
    //     ";
    //     assert_matches!(run_tmp(src), Err(_))
    // }

    // #[test]
    // fn test_tagged() {
    //     let src = "
    //         (nomtype (Maybe a) (tagged (Some a) None))
    //         (def map (of (for [a b] (Fun [(Fun [a] b) (Maybe a)] (Maybe b)))
    //                      (fun [f x] (match x [(Some y) (Some (f y))] [None None]))))
    //         (def unwrap-or (of (for [a] (Fun [(Maybe a) a] a))
    //                            (fun [may y] (match may [(Some x) x] [None y]))))
    //         (def main (unwrap-or (map (fun [x] (* x 2)) (Some (of N8 33))) 0))
    //     ";
    //     assert_matches!(run_tmp(src), Ok(Operand::Const(Const::N8(66))))
    // }
}