# Path: mdn/utils.py
# def date_to_iso(date):
#     """Convert a datetime.Date to the ISO 8601 format, or None."""
#     if date:
#         return date.isoformat()
#     else:
#         return None
# 
# def end_of_line(text, pos):
#     """Get the position of the end of the line from pos."""
#     try:
#         return text.index('\n', pos)
#     except ValueError:
#         return len(text)
# 
# def format_version(version):
#     """Format a version to 1.0, 1.0.1, etc."""
#     if '.' in version:
#         return version
#     else:
#         assert version
#         assert int(version)
#         return version + '.0'
# 
# def is_new_id(_id):
#     """Detect if an ID signifies a new resource.
# 
#     New resource IDs are text strings prefixed with an underscore.
#     """
#     return isinstance(_id, text_type) and _id[0] == '_'
# 
# def join_content(content_bits):
#     """Construct a string with just the right whitespace."""
#     out = ''
#     nospace_before = '!,.;?[ '
#     nospace_after = ' '
#     for bit in content_bits:
#         if bit:
#             if (out and out[-1] not in nospace_after and
#                     bit[0] not in nospace_before):
#                 out += ' '
#             out += bit
#     return out
# 
# def slugify(word, length=50, suffix=''):
#     """Create a slugged version of a word or phrase."""
#     raw = word.lower()
#     out = []
#     acceptable = string.ascii_lowercase + string.digits + '_-'
#     for c in raw:
#         if c in acceptable:
#             out.append(c)
#         else:
#             out.append('_')
#     slugged = ''.join(out)
#     while '__' in slugged:
#         slugged = slugged.replace('__', '_')
#     if slugged.endswith('_') and len(slugged) > 1:
#         slugged = slugged[:-1]
#     suffix = text_type(suffix) if suffix else ''
#     with_suffix = slugged[slice(length - len(suffix))] + suffix
#     return with_suffix


from datetime import date
from mdn.utils import (
    date_to_iso, end_of_line, format_version, is_new_id, join_content,
    slugify)
from .base import TestCase
        self.assertTrue(is_new_id('_new'))

    def test_string_id(self):
        self.assertFalse(is_new_id('6'))

    def test_int_id(self):
        self.assertFalse(is_new_id(6))


class TestJoinContent(TestCase):
    def test_join_content_simple(self):
        joined = join_content(['Works', 'like', 'join.'])
        self.assertEqual(joined, 'Works like join.')

    def test_join_content_code(self):
        joined = join_content([
            'Text with', '<code>code1</code>', ',' '<code>code2</code>',
            ', and', '<code>code3</code>', 'blocks.'])
        expected_text = (
            'Text with <code>code1</code>,<code>code2</code>, and'
            ' <code>code3</code> blocks.')
        self.assertEqual(joined, expected_text)

    def test_join_content_empty(self):
        joined = join_content(['Text with', '', 'blank', None, 'bits', '.'])
        self.assertEqual(joined, 'Text with blank bits.')


class TestSlugify(TestCase):
    def test_already_slugged(self):

# Path: mdn/utils.py
# def date_to_iso(date):
#     """Convert a datetime.Date to the ISO 8601 format, or None."""
#     if date:
#         return date.isoformat()
#     else:
#         return None
# 
# def end_of_line(text, pos):
#     """Get the position of the end of the line from pos."""
#     try:
#         return text.index('\n', pos)
#     except ValueError:
#         return len(text)
# 
# def format_version(version):
#     """Format a version to 1.0, 1.0.1, etc."""
#     if '.' in version:
#         return version
#     else:
#         assert version
#         assert int(version)
#         return version + '.0'
# 
# def is_new_id(_id):
#     """Detect if an ID signifies a new resource.
# 
#     New resource IDs are text strings prefixed with an underscore.
#     """
#     return isinstance(_id, text_type) and _id[0] == '_'
# 
# def join_content(content_bits):
#     """Construct a string with just the right whitespace."""
#     out = ''
#     nospace_before = '!,.;?[ '
#     nospace_after = ' '
#     for bit in content_bits:
#         if bit:
#             if (out and out[-1] not in nospace_after and
#                     bit[0] not in nospace_before):
#                 out += ' '
#             out += bit
#     return out
# 
# def slugify(word, length=50, suffix=''):
#     """Create a slugged version of a word or phrase."""
#     raw = word.lower()
#     out = []
#     acceptable = string.ascii_lowercase + string.digits + '_-'
#     for c in raw:
#         if c in acceptable:
#             out.append(c)
#         else:
#             out.append('_')
#     slugged = ''.join(out)
#     while '__' in slugged:
#         slugged = slugged.replace('__', '_')
#     if slugged.endswith('_') and len(slugged) > 1:
#         slugged = slugged[:-1]
#     suffix = text_type(suffix) if suffix else ''
#     with_suffix = slugged[slice(length - len(suffix))] + suffix
#     return with_suffix


# Path: mdn/tests/test_utils.py
from datetime import date
from mdn.utils import (
    date_to_iso, end_of_line, format_version, is_new_id, join_content,
    slugify)
from .base import TestCase

        self.assertTrue(is_new_id('_new'))

    def test_string_id(self):
        self.assertFalse(is_new_id('6'))

    def test_int_id(self):
        self.assertFalse(is_new_id(6))


class TestJoinContent(TestCase):
    def test_join_content_simple(self):
        joined = join_content(['Works', 'like', 'join.'])
        self.assertEqual(joined, 'Works like join.')

    def test_join_content_code(self):
        joined = join_content([
            'Text with', '<code>code1</code>', ',' '<code>code2</code>',
            ', and', '<code>code3</code>', 'blocks.'])
        expected_text = (
            'Text with <code>code1</code>,<code>code2</code>, and'
            ' <code>code3</code> blocks.')
        self.assertEqual(joined, expected_text)

    def test_join_content_empty(self):
        joined = join_content(['Text with', '', 'blank', None, 'bits', '.'])
        self.assertEqual(joined, 'Text with blank bits.')


class TestSlugify(TestCase):
    def test_already_slugged(self):

        self.assertEqual('foo', slugify('foo'))