from __future__ import unicode_literals
import pytest

from arpeggio import ZeroOrMore, Optional, ParserPython, NoMatch


def test_optional_inside_zeroormore():
    """
    Test optional match inside a zero or more.
    Optional should always succeed thus inducing ZeroOrMore
    to try the match again.
    Arpeggio handle this using soft failures.
    """
    def grammar():  return ZeroOrMore(Optional('a'))

    parser = ParserPython(grammar)

    with pytest.raises(NoMatch):
        # This could lead to infinite loop
        parser.parse('b')

from __future__ import unicode_literals
import pytest

from arpeggio import ZeroOrMore, Optional, ParserPython, NoMatch, EOF


def test_optional_inside_zeroormore():
    """
    Test optional match inside a zero or more.
    Optional should always succeed thus inducing ZeroOrMore
    to try the match again.
    Arpeggio handle this case.
    """
    def grammar():  return ZeroOrMore(Optional('a')), EOF

    parser = ParserPython(grammar)

    with pytest.raises(NoMatch):
        # This could lead to infinite loop
        parser.parse('b')

Fix in test for pathologic grammars.
Fix in test for pathologic grammars.

  from __future__ import unicode_literals
  import pytest
  
- from arpeggio import ZeroOrMore, Optional, ParserPython, NoMatch
+ from arpeggio import ZeroOrMore, Optional, ParserPython, NoMatch, EOF
  
  
  def test_optional_inside_zeroormore():
      """
      Test optional match inside a zero or more.
      Optional should always succeed thus inducing ZeroOrMore
      to try the match again.
-     Arpeggio handle this using soft failures.
+     Arpeggio handle this case.
      """
-     def grammar():  return ZeroOrMore(Optional('a'))
+     def grammar():  return ZeroOrMore(Optional('a')), EOF
  
      parser = ParserPython(grammar)
  
      with pytest.raises(NoMatch):
          # This could lead to infinite loop
          parser.parse('b')
  
Fix in test for pathologic grammars.
## Code Before:
from __future__ import unicode_literals
import pytest

from arpeggio import ZeroOrMore, Optional, ParserPython, NoMatch


def test_optional_inside_zeroormore():
    """
    Test optional match inside a zero or more.
    Optional should always succeed thus inducing ZeroOrMore
    to try the match again.
    Arpeggio handle this using soft failures.
    """
    def grammar():  return ZeroOrMore(Optional('a'))

    parser = ParserPython(grammar)

    with pytest.raises(NoMatch):
        # This could lead to infinite loop
        parser.parse('b')

## Instruction:
Fix in test for pathologic grammars.
## Code After:
from __future__ import unicode_literals
import pytest

from arpeggio import ZeroOrMore, Optional, ParserPython, NoMatch, EOF


def test_optional_inside_zeroormore():
    """
    Test optional match inside a zero or more.
    Optional should always succeed thus inducing ZeroOrMore
    to try the match again.
    Arpeggio handle this case.
    """
    def grammar():  return ZeroOrMore(Optional('a')), EOF

    parser = ParserPython(grammar)

    with pytest.raises(NoMatch):
        # This could lead to infinite loop
        parser.parse('b')
