use super::*;
use crate::lexer::token::{Keyword, Literal, TokenKind};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum TestKeyword {
    Fn,
}

impl Keyword for TestKeyword {
    type Tag = TestKeyword;
    fn matches(src: &str) -> Option<Self> {
        match src {
            "fn" => Some(TestKeyword::Fn),
            _ => None,
        }
    }
    fn tag(&self) -> Self::Tag {
        *self
    }
}

impl std::fmt::Display for TestKeyword {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TestKeyword::Fn => write!(f, "fn"),
        }
    }
}

fn lex_all(input: &str) -> Vec<crate::lexer::token::Token<TestKeyword>> {
    crate::lexer::Lexer::<TestKeyword>::from(input).collect()
}

#[test]
fn lex_punct_all() {
    let tokens = lex_all("{}()[]:,;.");
    let kinds: Vec<_> = tokens.into_iter().map(|t| t.kind().clone()).collect();
    assert_eq!(
        kinds,
        [
            TokenKind::LeftBrace,
            TokenKind::RightBrace,
            TokenKind::LeftParen,
            TokenKind::RightParen,
            TokenKind::LeftBracket,
            TokenKind::RightBracket,
            TokenKind::Colon,
            TokenKind::Comma,
            TokenKind::Semicolon,
            TokenKind::Dot,
        ]
    );
}
