# Path: capirca/lib/aclgenerator.py
# def WrapWords(textlist, size, joiner='\n'):
#   r"""Insert breaks into the listed strings at specified width.
# 
#   Args:
#     textlist: a list of text strings
#     size: width of reformated strings
#     joiner: text to insert at break.  eg. '\n  ' to add an indent.
#   Returns:
#     list of strings
#   """
#   # \S{%d}(?!\s|\Z) collets the max size for words that are larger than the max
#   # (?<=\S{%d})\S+ collects the remaining text for overflow words in their own
#   # line
#   # \S.{1,%d}(?=\s|\Z)) collects all words and spaces up to max size, breaking
#   # at the last space
#   rval = []
#   linelength_re = re.compile(
#       r'(\S{%d}(?!\s|\Z)|(?<=\S{%d})\S+|\S.{1,%d}(?=\s|\Z))' %
#       (size, size, size - 1))
#   for index in range(len(textlist)):
#     if len(textlist[index]) > size:
#       # insert joiner into the string at appropriate places.
#       textlist[index] = joiner.join(linelength_re.findall(textlist[index]))
#     # avoid empty comment lines
#     rval.extend(x.strip() for x in textlist[index].strip().split(joiner) if x)
#   return rval


from capirca.lib.aclgenerator import WrapWords
import pytest
NO_OVERFLOW_LONG = \
    "This " + \
    "is a long header. It's long on purpose. It's " + \
    "purpose is to test that the splitting works co" + \
    "rrectly. It should be well over the line limit" + \
    ". If it is shorter, it would not test the limit."

NO_OVERFLOW_LONG_EXPECTED = [
    "This is a long header. It's long on purpose. It's purpose is to test",
    "that the splitting works correctly. It should be well over the line",
    "limit. If it is shorter, it would not test the limit."
]

NO_OVERFLOW_SHORT = \
    "This is a short line of text"

NO_OVERFLOW_SHORT_EXPECTED = [
    "This is a short line of text"
]

@pytest.mark.parametrize("test_input,expected", [
    (NO_OVERFLOW_SHORT, NO_OVERFLOW_SHORT_EXPECTED),
    (NO_OVERFLOW_LONG, NO_OVERFLOW_LONG_EXPECTED),
    (SINGLE_LINE_OVERFLOW_TEXT_LONG, SINGLE_LINE_OVERFLOW_TEXT_LONG_EXPECTED),
    (MULTI_LINE_OVERFLOW_TEXT_LONG, MULTI_LINE_OVERFLOW_TEXT_LONG_EXPECTED)
]
                         )


def testWrapWords(test_input, expected):

# Path: capirca/lib/aclgenerator.py
# def WrapWords(textlist, size, joiner='\n'):
#   r"""Insert breaks into the listed strings at specified width.
# 
#   Args:
#     textlist: a list of text strings
#     size: width of reformated strings
#     joiner: text to insert at break.  eg. '\n  ' to add an indent.
#   Returns:
#     list of strings
#   """
#   # \S{%d}(?!\s|\Z) collets the max size for words that are larger than the max
#   # (?<=\S{%d})\S+ collects the remaining text for overflow words in their own
#   # line
#   # \S.{1,%d}(?=\s|\Z)) collects all words and spaces up to max size, breaking
#   # at the last space
#   rval = []
#   linelength_re = re.compile(
#       r'(\S{%d}(?!\s|\Z)|(?<=\S{%d})\S+|\S.{1,%d}(?=\s|\Z))' %
#       (size, size, size - 1))
#   for index in range(len(textlist)):
#     if len(textlist[index]) > size:
#       # insert joiner into the string at appropriate places.
#       textlist[index] = joiner.join(linelength_re.findall(textlist[index]))
#     # avoid empty comment lines
#     rval.extend(x.strip() for x in textlist[index].strip().split(joiner) if x)
#   return rval


# Path: tests/unit/wrapwords_test.py
from capirca.lib.aclgenerator import WrapWords
import pytest

NO_OVERFLOW_LONG = \
    "This " + \
    "is a long header. It's long on purpose. It's " + \
    "purpose is to test that the splitting works co" + \
    "rrectly. It should be well over the line limit" + \
    ". If it is shorter, it would not test the limit."

NO_OVERFLOW_LONG_EXPECTED = [
    "This is a long header. It's long on purpose. It's purpose is to test",
    "that the splitting works correctly. It should be well over the line",
    "limit. If it is shorter, it would not test the limit."
]

NO_OVERFLOW_SHORT = \
    "This is a short line of text"

NO_OVERFLOW_SHORT_EXPECTED = [
    "This is a short line of text"
]

@pytest.mark.parametrize("test_input,expected", [
    (NO_OVERFLOW_SHORT, NO_OVERFLOW_SHORT_EXPECTED),
    (NO_OVERFLOW_LONG, NO_OVERFLOW_LONG_EXPECTED),
    (SINGLE_LINE_OVERFLOW_TEXT_LONG, SINGLE_LINE_OVERFLOW_TEXT_LONG_EXPECTED),
    (MULTI_LINE_OVERFLOW_TEXT_LONG, MULTI_LINE_OVERFLOW_TEXT_LONG_EXPECTED)
]
                         )


def testWrapWords(test_input, expected):

  result = WrapWords([test_input], 70)