# -*- coding: utf-8 -*-
# :-
# SPDX-FileCopyrightText: © 2026 Franz Glasner
# SPDX-License-Identifier: MIT
# :-
"""Test helper"""

__all__ = ["TokenAssertHelper"]


from pygments.token import Token, is_token_subtype, string_to_tokentype


class TokenAssertHelper(object):
    """Mixin to test for token stream equality"""

    def assertTokenEqual(self, tok_or_str, txt, token):
        if is_token_subtype(tok_or_str, Token):
            t = tok_or_str
        else:
            t = string_to_tokentype(tok_or_str)
        self.assertEqual((t, txt), token)

    def assertNextTokenEqual(self, tok_or_str, txt, tokens):
        self.assertTokenEqual(tok_or_str, txt, next(tokens))

    def assertTokenStreamEqual(self, expected_tokens, given_tokens):
        for tok, txt in expected_tokens:
            self.assertNextTokenEqual(tok, txt, given_tokens)

    def assertTokenStreamEqualComplete(self, expected_tokens, given_tokens):
        self.assertTokenStreamEqual(expected_tokens, given_tokens)
        self.assertRaises(StopIteration, next, given_tokens)
