# Path: mistletoe/block_token.py
# class Document(BlockToken):
#     """
#     Document token.
#     """
#     def __init__(self, lines):
#         if isinstance(lines, str):
#             lines = lines.splitlines(keepends=True)
#         lines = [line if line.endswith('\n') else '{}\n'.format(line) for line in lines]
#         self.footnotes = {}
#         global _root_node
#         _root_node = self
#         span_token._root_node = self
#         self.children = tokenize(lines)
#         span_token._root_node = None
#         _root_node = None
# 
# Path: mistletoe/utils.py
# def traverse(source, klass=None, depth=None, include_source=False):
#     """Traverse the syntax tree, recursively yielding children.
# 
#     Args:
# 
#         source: The source syntax token
#         klass: filter children by a certain token class
#         depth (int): The depth to recurse into the tree
#         include_source (bool): whether to first yield the source element
# 
#     Yields:
#         A container for an element, its parent and depth
#     """
#     current_depth = 0
#     if include_source:
#         yield TraverseResult(source, None, current_depth)
#     next_children = [(source, c) for c in getattr(source, 'children', [])]
#     while next_children and (depth is None or current_depth > depth):
#         current_depth += 1
#         new_children = []
#         for parent, child in next_children:
#             if klass is None or issubclass(child, klass):
#                 yield TraverseResult(child, parent, current_depth)
#             new_children.extend(
#                 [(child, c) for c in getattr(child, 'children', [])]
#             )
#         next_children = new_children


from textwrap import dedent
from mistletoe import Document
from mistletoe.utils import traverse
import unittest



class TestTraverse(unittest.TestCase):
    def test_a(self):
        doc = Document(
            dedent(
                """\
            a **b**

            c [*d*](link)
            """
            )
        )
        tree = [
            (
                t.node.__class__.__name__,
                t.parent.__class__.__name__ if t.parent else None,
                t.depth
            )

# Path: mistletoe/block_token.py
# class Document(BlockToken):
#     """
#     Document token.
#     """
#     def __init__(self, lines):
#         if isinstance(lines, str):
#             lines = lines.splitlines(keepends=True)
#         lines = [line if line.endswith('\n') else '{}\n'.format(line) for line in lines]
#         self.footnotes = {}
#         global _root_node
#         _root_node = self
#         span_token._root_node = self
#         self.children = tokenize(lines)
#         span_token._root_node = None
#         _root_node = None
# 
# Path: mistletoe/utils.py
# def traverse(source, klass=None, depth=None, include_source=False):
#     """Traverse the syntax tree, recursively yielding children.
# 
#     Args:
# 
#         source: The source syntax token
#         klass: filter children by a certain token class
#         depth (int): The depth to recurse into the tree
#         include_source (bool): whether to first yield the source element
# 
#     Yields:
#         A container for an element, its parent and depth
#     """
#     current_depth = 0
#     if include_source:
#         yield TraverseResult(source, None, current_depth)
#     next_children = [(source, c) for c in getattr(source, 'children', [])]
#     while next_children and (depth is None or current_depth > depth):
#         current_depth += 1
#         new_children = []
#         for parent, child in next_children:
#             if klass is None or issubclass(child, klass):
#                 yield TraverseResult(child, parent, current_depth)
#             new_children.extend(
#                 [(child, c) for c in getattr(child, 'children', [])]
#             )
#         next_children = new_children


# Path: test/test_traverse.py
from textwrap import dedent
from mistletoe import Document
from mistletoe.utils import traverse
import unittest




class TestTraverse(unittest.TestCase):
    def test_a(self):
        doc = Document(
            dedent(
                """\
            a **b**

            c [*d*](link)
            """
            )
        )
        tree = [
            (
                t.node.__class__.__name__,
                t.parent.__class__.__name__ if t.parent else None,
                t.depth
            )

            for t in traverse(doc, include_source=True)