view tests/test_match.py @ 296:ca293f708cb4

Begin some preparation for handling glob-style patterns in treeview. Needed to implement inclusions and exclusions.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 02 Mar 2025 22:54:40 +0100
parents
children 141a3aa0b403
line wrap: on
line source

# -*- coding: utf-8 -*-
r"""Unit tests for :mod:`cutils.util.glob`

"""

from __future__ import absolute_import, print_function

import _test_setup    # noqa: F401 imported but unused

import sys
import unittest

from cutils.util.glob import CharIter


class TestCharIter(unittest.TestCase):

    def test_transitive_iter(self):
        it = CharIter("1234")
        self.assertIs(iter(it), it)

    def test_native_str(self):
        it = CharIter("1234")
        chars = []
        for c in it:
            chars.append(c)
        self.assertEqual("1234", "".join(chars))

    def test_unicode_str(self):
        it = CharIter(u"1234")
        chars = []
        for c in it:
            chars.append(c)
        self.assertEqual(u"1234", "".join(chars))

    def test_byte_str(self):
        it = CharIter(b"1234")
        chars = []
        for c in it:
            chars.append(c)
        self.assertEqual(b"1234", b"".join(chars))

    def test_peek_exhausted(self):
        it = CharIter("1234")
        for _ in it:
            pass
        self.assertIsNone(it.peek())

    def test_peek_first(self):
        it = CharIter("1234")
        self.assertEqual("1", it.peek())
        chars = "".join(it)
        self.assertEqual("1234", chars)
        self.assertIsNone(it.peek())

    def test_peek_from_second(self):
        it = CharIter("1234")
        self.assertEqual("1", it.peek())
        self.assertEqual("1", next(it))
        self.assertEqual("2", it.peek())
        chars = "".join(it)
        self.assertEqual("234", chars)
        self.assertIsNone(it.peek())


if __name__ == "__main__":
    sys.exit(unittest.main())