..  _RefElementBasicDocTests:

Doctests for the fundamental element classes
****************************************************************************

Sequence element class
==========================================================================

Test fixture initialization::

    >>> from dragonfly import *
    >>> from dragonfly.test import ElementTester


Sequence
----------------------------------------------------------------------------

Basic usage::

    >>> seq = Sequence([Literal("hello"), Literal("world")])
    >>> test_seq = ElementTester(seq)
    >>> test_seq.recognize("hello world")
    [u'hello', u'world']


Sequence
----------------------------------------------------------------------------

Basic usage::

    >>> seq = Sequence([Literal("hello"), Literal("world")])
    >>> test_seq = ElementTester(seq)
    >>> test_seq.recognize("hello world")
    [u'hello', u'world']
    >>> test_seq.recognize("hello universe")
    RecognitionFailure

Constructor arguments::

    >>> c1, c2 = Literal("hello"), Literal("world")
    >>> len(Sequence(children=[c1, c2]).children)
    2
    >>> Sequence(children=[c1, c2], name="sequence_test").name
    'sequence_test'
    >>> Sequence([c1, c2], "sequence_test").name
    'sequence_test'
    >>> Sequence("invalid_children_type")
    Traceback (most recent call last):
      ...
    TypeError: children object must contain only <class 'dragonfly.grammar.elements_basic.ElementBase'> types.  (Received ('i', 'n', 'v', 'a', 'l', 'i', 'd', '_', 'c', 'h', 'i', 'l', 'd', 'r', 'e', 'n', '_', 't', 'y', 'p', 'e'))