runic_kit/
token.rs

1//! This module defines the `Token` struct, which represents a token in the source code.
2
3use crate::span::Span;
4
5/// Represents a token in the source code.
6#[derive(Debug)]
7pub struct Token<T> {
8    /// The kind of token
9    pub kind: T,
10    /// The span in the source code where the token is located.
11    pub span: Span,
12}
13
14impl<T> Token<T> {
15    /// Creates a new `Token`.
16    pub fn new(kind: T, span: Span) -> Self {
17        Token { kind, span }
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24    use crate::span::Span;
25
26    #[test]
27    fn test_token_creation() {
28        let span = Span::new(0, 10);
29        let token = Token::new("let", span);
30
31        assert_eq!(token.kind, "let");
32        assert_eq!(token.span.start, 0);
33        assert_eq!(token.span.end, 10);
34    }
35}