import pytest

from cornflake.fields import StringField, ValidationError


@pytest.mark.parametrize(('value', 'expected'), [
    ('hello', 'hello'),
    (u'\u263A', u'\u263A'),
])
def test_to_representation(value, expected):
    assert StringField().to_representation(value) == expected


@pytest.mark.parametrize(('data', 'expected'), [
    ('hello', 'hello'),
    (u'\u263A', u'\u263A'),  # unicode
    (123, '123'),
    (123.456, '123.456'),
    (' foo ', 'foo'),  # strip whitespace
])
def test_to_internal_value(data, expected):
    assert StringField().to_internal_value(data) == expected


@pytest.mark.parametrize('data', [
    True,
    False,
    {'foo': 1, 'bar': 2},
    ['foo', 'bar', 'baz'],
])
def test_to_internal_value_invalid(data):
    with pytest.raises(ValidationError):
        StringField().to_internal_value(data)

@@ -831,8 +831,316 @@
 e(data)%0A
+%0A%0Adef test_trim_whitespace_true():%0A    field = StringField(trim_whitespace=True)%0A    value = field.to_internal_value(' abc ')%0A    assert value == 'abc'%0A%0A%0Adef test_trim_whitespace_false():%0A    field = StringField(trim_whitespace=False)%0A    value = field.to_internal_value(' abc ')%0A    assert value == ' abc '%0A

Add trim_whitespace tests