Skip to main content

aiken_lang/parser/pattern/
int.rs

1use chumsky::prelude::*;
2
3use crate::{
4    ast::UntypedPattern,
5    parser::{error::ParseError, literal, token::Token},
6};
7
8pub fn parser() -> impl Parser<Token, UntypedPattern, Error = ParseError> {
9    literal::int().map_with_span(|(value, base), location| UntypedPattern::Int {
10        location,
11        value,
12        base,
13    })
14}
15
16#[cfg(test)]
17mod tests {
18    use crate::assert_expr;
19
20    #[test]
21    fn pattern_negative_int() {
22        assert_expr!(
23            r#"
24            when foo is {
25              -1 -> True
26            }
27            "#
28        );
29    }
30
31    #[test]
32    fn pattern_negative_int_not_first_case() {
33        assert_expr!(
34            r#"
35            when bar is {
36              42 -> -14
37              -42 -> 14
38            }
39            "#
40        );
41    }
42}