use assert_matches::assert_matches;

use crate::test;

use super::{ErrorKind, InternalError, RawStr, Span, Token, TokenType};

#[test]
fn should_fail_to_create_raw_str_from_non_string_token() {
    test::setup();

    let err = RawStr::from_quoted_str("fail", TokenType::Number.into()).unwrap_err();
    let err = assert_matches!(err.kind, ErrorKind::Internal(err) => err);
    let err = err.downcast_ref::<InternalError>().unwrap();
    assert_matches!(err, InternalError::RawStringFromInvalidToken);
}

#[test]
fn should_fail_to_create_raw_str_from_string_without_quotes() {
    test::setup();

    let err = RawStr::from_quoted_str("fail", TokenType::String.into()).unwrap_err();
    let err = assert_matches!(err.kind, ErrorKind::Internal(err) => err);
    let err = err.downcast_ref::<InternalError>().unwrap();
    assert_matches!(err, InternalError::StringWithoutQuotes);
}

impl From<TokenType> for Token {
    fn from(kind: TokenType) -> Self {
        Self {
            kind,
            span: Span::default(),
        }
    }
}
