# Path: jcn/formatting.py
# class Placeholder(metaclass=InheritDocstrings):
# class FormatPlaceholder(Placeholder):
# class ParameterizingFormatPlaceholder(FormatPlaceholder):
# class StylePlaceholder(Placeholder):
# class NullPlaceholder(Placeholder):
# class PlaceholderGroup:
# class FormatPlaceholderFactory:
# class StylePlaceholderFactory:
# class StringComponent(str):
# class StringWithFormatting:
#     def __init__(self, attr_name):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __add__(self, other):
#     def __call__(self, content):
#     def populate(self, terminal, styles):
#     def populate(self, terminal, styles):
#     def __init__(self, attr_name):
#     def __repr__(self):
#     def __eq__(self, other):
#     def _protect_from_not_called(self):
#     def __add__(self, other):
#     def __call__(self, *args):
#     def populate(self, terminal, styles):
#     def populate(self, terminal, styles):
#     def __init__(self):
#     def __repr__(self):
#     def populate(self, terminal, styles):
#     def __init__(self, placeholders=None):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __add__(self, other):
#     def __call__(self, content):
#     def populate(self, terminal, styles):
#     def __getattr__(self, attr_name):
#     def __init__(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __getitem__(self, name):
#     def __new__(cls, placeholder, string, *args, **kwargs):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __getitem__(self, index):
#     def __add__(self, other):
#     def __radd__(self, other):
#     def __getattribute__(self, name):
#                 def wrapped_str_method(self, *args, **kwargs):
#     def populate(self, terminal, styles, default_esc_seq):
#     def __init__(self, content):
#     def __repr__(self):
#     def __str__(self):
#     def __len__(self):
#     def __bool__(self):
#     def __contains__(self, string):
#     def __eq__(self, other):
#     def __add__(self, other):
#     def __radd__(self, other):
#     def apply_placeholder(self, placeholder):
#     def __iter__(self):
#     def _get_slice(self, start, stop):
#     def __getitem__(self, index):
#     def _apply_list_returning_str_method(
#             self, name, *args, reference, **kwargs):
#     def __getattr__(self, name):
#             def str_method_executor(self, *args, **kwargs):
#     def chunk(self, regex):
#     def strip(self):
#     def populate(self, terminal=None, styles=None, default_esc_seq=''):
# 
# Path: jcn/textwrap.py
# def wrap(self, text):
#     '''Wraps the text object to width, breaking at whitespaces. Runs of
#     whitespace characters are preserved, provided they do not fall at a
#     line boundary. The implementation is based on that of textwrap from the
#     standard library, but we can cope with StringWithFormatting objects.
# 
#     :returns: a list of string-like objects.
#     '''
#     result = []
#     chunks = self._chunk(text)
#     while chunks:
#         self._lstrip(chunks)
#         current_line = []
#         current_line_length = 0
#         current_chunk_length = 0
#         while chunks:
#             current_chunk_length = len(chunks[0])
#             if current_line_length + current_chunk_length <= self.width:
#                 current_line.append(chunks.pop(0))
#                 current_line_length += current_chunk_length
#             else:
#                 # Line is full
#                 break
#         # Handle case where chunk is bigger than an entire line
#         if current_chunk_length > self.width:
#             space_left = self.width - current_line_length
#             current_line.append(chunks[0][:space_left])
#             chunks[0] = chunks[0][space_left:]
#         self._rstrip(current_line)
#         if current_line:
#             result.append(reduce(
#                 lambda x, y: x + y, current_line[1:], current_line[0]))
#         else:
#             # FIXME: should this line go? Removing it makes at least simple
#             # cases like wrap('    ', 10) actually behave like
#             # textwrap.wrap...
#             result.append('')
#     return result


from unittest import TestCase
from jcn.formatting import (
    FormatPlaceholderFactory, StringComponent, StringWithFormatting,
    null_placeholder)
from jcn.textwrap import wrap
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see [http://www.gnu.org/licenses/].




class TestTextWrapper(TestCase):
    def setUp(self):
        self.format = FormatPlaceholderFactory()

    def test_wrap_str(self):
        text = 'The  quick brown fox jumps over the lazy dog'
        result = wrap(text, width=15)
        expected = [
            'The  quick',
            'brown fox jumps',
            'over the lazy',
            'dog']
        self.assertEqual(result, expected)

# Path: jcn/formatting.py
# class Placeholder(metaclass=InheritDocstrings):
# class FormatPlaceholder(Placeholder):
# class ParameterizingFormatPlaceholder(FormatPlaceholder):
# class StylePlaceholder(Placeholder):
# class NullPlaceholder(Placeholder):
# class PlaceholderGroup:
# class FormatPlaceholderFactory:
# class StylePlaceholderFactory:
# class StringComponent(str):
# class StringWithFormatting:
#     def __init__(self, attr_name):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __add__(self, other):
#     def __call__(self, content):
#     def populate(self, terminal, styles):
#     def populate(self, terminal, styles):
#     def __init__(self, attr_name):
#     def __repr__(self):
#     def __eq__(self, other):
#     def _protect_from_not_called(self):
#     def __add__(self, other):
#     def __call__(self, *args):
#     def populate(self, terminal, styles):
#     def populate(self, terminal, styles):
#     def __init__(self):
#     def __repr__(self):
#     def populate(self, terminal, styles):
#     def __init__(self, placeholders=None):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __add__(self, other):
#     def __call__(self, content):
#     def populate(self, terminal, styles):
#     def __getattr__(self, attr_name):
#     def __init__(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):
#     def __getitem__(self, name):
#     def __new__(cls, placeholder, string, *args, **kwargs):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __getitem__(self, index):
#     def __add__(self, other):
#     def __radd__(self, other):
#     def __getattribute__(self, name):
#                 def wrapped_str_method(self, *args, **kwargs):
#     def populate(self, terminal, styles, default_esc_seq):
#     def __init__(self, content):
#     def __repr__(self):
#     def __str__(self):
#     def __len__(self):
#     def __bool__(self):
#     def __contains__(self, string):
#     def __eq__(self, other):
#     def __add__(self, other):
#     def __radd__(self, other):
#     def apply_placeholder(self, placeholder):
#     def __iter__(self):
#     def _get_slice(self, start, stop):
#     def __getitem__(self, index):
#     def _apply_list_returning_str_method(
#             self, name, *args, reference, **kwargs):
#     def __getattr__(self, name):
#             def str_method_executor(self, *args, **kwargs):
#     def chunk(self, regex):
#     def strip(self):
#     def populate(self, terminal=None, styles=None, default_esc_seq=''):
# 
# Path: jcn/textwrap.py
# def wrap(self, text):
#     '''Wraps the text object to width, breaking at whitespaces. Runs of
#     whitespace characters are preserved, provided they do not fall at a
#     line boundary. The implementation is based on that of textwrap from the
#     standard library, but we can cope with StringWithFormatting objects.
# 
#     :returns: a list of string-like objects.
#     '''
#     result = []
#     chunks = self._chunk(text)
#     while chunks:
#         self._lstrip(chunks)
#         current_line = []
#         current_line_length = 0
#         current_chunk_length = 0
#         while chunks:
#             current_chunk_length = len(chunks[0])
#             if current_line_length + current_chunk_length <= self.width:
#                 current_line.append(chunks.pop(0))
#                 current_line_length += current_chunk_length
#             else:
#                 # Line is full
#                 break
#         # Handle case where chunk is bigger than an entire line
#         if current_chunk_length > self.width:
#             space_left = self.width - current_line_length
#             current_line.append(chunks[0][:space_left])
#             chunks[0] = chunks[0][space_left:]
#         self._rstrip(current_line)
#         if current_line:
#             result.append(reduce(
#                 lambda x, y: x + y, current_line[1:], current_line[0]))
#         else:
#             # FIXME: should this line go? Removing it makes at least simple
#             # cases like wrap('    ', 10) actually behave like
#             # textwrap.wrap...
#             result.append('')
#     return result


# Path: test/test_textwrap.py
from unittest import TestCase
from jcn.formatting import (
    FormatPlaceholderFactory, StringComponent, StringWithFormatting,
    null_placeholder)
from jcn.textwrap import wrap

#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see [http://www.gnu.org/licenses/].




class TestTextWrapper(TestCase):
    def setUp(self):
        self.format = FormatPlaceholderFactory()

    def test_wrap_str(self):
        text = 'The  quick brown fox jumps over the lazy dog'
        result = wrap(text, width=15)
        expected = [
            'The  quick',
            'brown fox jumps',
            'over the lazy',
            'dog']
        self.assertEqual(result, expected)

        self.assertEqual(wrap('', 10), [])