use crate::{Kind, Lex, Token};

#[test]
fn properties() {
    let source: &'static str = "the source";
    let tokens: Vec<Token<'static>> = vec![
        Token::new(Kind::Symbol, "the", 0, 0),
        Token::new(Kind::Whitespace, " ", 0, 1),
        Token::new(Kind::Symbol, "source", 0, 4),
    ];
    let lex: Lex<'static> = Lex::new(source, tokens.clone());
    assert_eq!(lex.source(), source);
    assert_eq!(lex.tokens(), &tokens);
}

#[test]
fn display() {
    let source: &'static str = "the source\nsecond line";
    let tokens: Vec<Token<'static>> = vec![
        Token::new(Kind::Symbol, "the", 0, 0),
        Token::new(Kind::Whitespace, " ", 0, 1),
        Token::new(Kind::Symbol, "source", 0, 4),
        Token::new(Kind::LineEnding, "\n", 0, 10),
        Token::new(Kind::Symbol, "second", 1, 0),
        Token::new(Kind::Whitespace, " ", 1, 6),
        Token::new(Kind::Symbol, "line", 1, 11),
    ];
    let lex: Lex<'static> = Lex::new(source, tokens.clone());
    let s: String = lex.to_string();
    let lines: Vec<&str> = s.split("\n").collect();

    assert_eq!(lines.len(), 10);

    assert_eq!(lines[0], "line 1:");
    assert_eq!(lines[1], "\t0      symbol          the");
    assert_eq!(lines[2], "\t1      whitespace      s");
    assert_eq!(lines[3], "\t4      symbol          source");
    assert_eq!(lines[4], "\t10     line-ending     n");

    assert_eq!(lines[5], "line 2:");
    assert_eq!(lines[6], "\t0      symbol          second");
    assert_eq!(lines[7], "\t6      whitespace      s");
    assert_eq!(lines[8], "\t11     symbol          line");

    assert_eq!(lines[9], "");
}
