<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
import unittest
from curtsies.formatstring import (FmtStr, fmtstr, Chunk, linesplit,
                                   normalize_slice, width_aware_slice)
from curtsies.fmtfuncs import *
from curtsies.termformatconstants import FG_COLORS
from curtsies.formatstringarray import fsarray, FSArray, FormatStringTest

try:
    from unittest import skip
except ImportError:
    def skip(f):
        return lambda self: None

PY2 = sys.version_info[0] == 2

try:
    unicode = unicode
except:
    unicode = str


def repr_without_leading_u(s):
    assert isinstance(s, type(u''))
    if PY2:
        r = repr(s)
        assert r[0] == 'u'
        return r[1:]
    else:
        return repr(s)


class TestFmtStrInitialization(unittest.TestCase):
    def test_bad(self):
        # Can't specify fg or bg color two ways
        self.assertRaises(ValueError, fmtstr, 'hello', 'blue', {'fg': 30})
        self.assertRaises(ValueError, fmtstr, 'hello', 'on_blue', {'bg': 40})
        # Only specific fg and bg colors are allowed
        self.assertRaises(ValueError, fmtstr, 'hello', {'bg': 30})
        self.assertRaises(ValueError, fmtstr, 'hello', {'fg': 40})
        # Only existing xforms can be used in kwargs
        self.assertRaises(ValueError, fmtstr, 'hello', 'make it big')

    def test_actual_init(self):
        FmtStr()


class TestFmtStrParsing(unittest.TestCase):
    def test_no_escapes(self):
        self.assertEqual(str(fmtstr('abc')), 'abc')

    def test_simple_escapes(self):
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[0m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[39m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[49m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[0m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[32;1mhello')), '\x1b[32m\x1b[1mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[0m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')

    def test_out_of_order(self):
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[39m\x1b[49m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')<commit_msg>Add tests for e1d5697<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
import unittest
from curtsies.formatstring import (FmtStr, fmtstr, Chunk, linesplit,
                                   normalize_slice, width_aware_slice)
from curtsies.fmtfuncs import *
from curtsies.termformatconstants import FG_COLORS
from curtsies.formatstringarray import fsarray, FSArray, FormatStringTest

try:
    from unittest import skip
except ImportError:
    def skip(f):
        return lambda self: None

PY2 = sys.version_info[0] == 2

try:
    unicode = unicode
except:
    unicode = str


def repr_without_leading_u(s):
    assert isinstance(s, type(u''))
    if PY2:
        r = repr(s)
        assert r[0] == 'u'
        return r[1:]
    else:
        return repr(s)


class TestFmtStrInitialization(unittest.TestCase):
    def test_bad(self):
        # Can't specify fg or bg color two ways
        self.assertRaises(ValueError, fmtstr, 'hello', 'blue', {'fg': 30})
        self.assertRaises(ValueError, fmtstr, 'hello', 'on_blue', {'bg': 40})
        # Only specific fg and bg colors are allowed
        self.assertRaises(ValueError, fmtstr, 'hello', {'bg': 30})
        self.assertRaises(ValueError, fmtstr, 'hello', {'fg': 40})
        # Only existing xforms can be used in kwargs
        self.assertRaises(ValueError, fmtstr, 'hello', 'make it big')

    def test_actual_init(self):
        FmtStr()


class TestFmtStrParsing(unittest.TestCase):
    def test_no_escapes(self):
        self.assertEqual(str(fmtstr('abc')), 'abc')

    def test_simple_escapes(self):
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[0m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello\x1b[39m')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33mhello')), '\x1b[33mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[49m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello\x1b[0m')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[43mhello')), '\x1b[43mhello\x1b[49m')
        self.assertEqual(str(fmtstr('\x1b[32;1mhello')), '\x1b[32m\x1b[1mhello\x1b[0m\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[2mhello')), 'hello')
        self.assertEqual(str(fmtstr('\x1b[32;2mhello')), '\x1b[32mhello\x1b[39m')
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[0m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')

    def test_out_of_order(self):
        self.assertEqual(str(fmtstr('\x1b[33m\x1b[43mhello\x1b[39m\x1b[49m')),
                         '\x1b[33m\x1b[43mhello\x1b[49m\x1b[39m')
{'fraction_non_alphanumeric': 0.14931427467645356, 'fraction_numerical': 0.056210160324512266, 'mean_word_length': 3.3807106598984773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7280143', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1984, 'n_words': 324}