Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

var y = 2 w/o new line -> unexpected panic (scan_digits_suffix_opt) #262

Open
github-actions bot opened this issue Oct 12, 2023 · 0 comments
Open
Assignees
Labels

Comments

@github-actions
Copy link

https://api.github.com/KisaragiEffective/origlang/blob/deaec8386e80690dc705769e8f783a80fe90b15b/package/origlang-compiler/src/lexer/tests.rs#L112

        assert_eq!(lexer.consume_char().expect("oops"), S.chars().nth(i).expect("out of bounds from literal"))
    }
}

use std::num::NonZeroUsize;
use origlang_source_span::{Pointed, SourcePosition};

#[test]
fn token_location() {
    // TODO: var y = 2 w/o new line -> unexpected panic (scan_digits_suffix_opt)
    let src = "var x = 1\nvar y = 2\n";
    let lexer = Lexer::create(src);

    assert_eq!(lexer.next(), Pointed {
        data: Token::VarKeyword,
        position: SourcePosition {
            line: NonZeroUsize::new(1).unwrap(),
            column: NonZeroUsize::new(1).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::Identifier {
            inner: Identifier::new("x".to_string())
        },
        position: SourcePosition {
            line: NonZeroUsize::new(1).unwrap(),
            column: NonZeroUsize::new(5).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::SymEq,
        position: SourcePosition {
            line: NonZeroUsize::new(1).unwrap(),
            column: NonZeroUsize::new(7).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::Digits {
            sequence: "1".to_string(),
            suffix: None,
        },
        position: SourcePosition {
            line: NonZeroUsize::new(1).unwrap(),
            column: NonZeroUsize::new(9).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::NewLine,
        position: SourcePosition {
            line: NonZeroUsize::new(1).unwrap(),
            column: NonZeroUsize::new(10).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::VarKeyword,
        position: SourcePosition {
            line: NonZeroUsize::new(2).unwrap(),
            column: NonZeroUsize::new(1).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::Identifier {
            inner: Identifier::new("y".to_string())
        },
        position: SourcePosition {
            line: NonZeroUsize::new(2).unwrap(),
            column: NonZeroUsize::new(5).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::SymEq,
        position: SourcePosition {
            line: NonZeroUsize::new(2).unwrap(),
            column: NonZeroUsize::new(7).unwrap()
        }
    });

    assert_eq!(lexer.next(), Pointed {
        data: Token::Digits {
            sequence: "2".to_string(),
            suffix: None,
        },
        position: SourcePosition {
            line: NonZeroUsize::new(2).unwrap(),
            column: NonZeroUsize::new(9).unwrap()
        }
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant