diff --git a/README.md b/README.md index 6e1e4fb..5d81e07 100644 --- a/README.md +++ b/README.md @@ -675,7 +675,7 @@ Partially supported - [ ] transduce - [ ] transpose - [ ] traverse -- [ ] trim +- [x] trim - [ ] tryCatch - [ ] type - [ ] unapply diff --git a/ramda/__init__.py b/ramda/__init__.py index e4bbf50..89ee699 100644 --- a/ramda/__init__.py +++ b/ramda/__init__.py @@ -111,6 +111,7 @@ from .toPairs import toPairs from .toPairsIn import toPairsIn from .toString import toString +from .trim import trim from .unary import unary from .union import union from .unionWith import unionWith diff --git a/ramda/trim.py b/ramda/trim.py new file mode 100644 index 0000000..e4169a0 --- /dev/null +++ b/ramda/trim.py @@ -0,0 +1,3 @@ +from .private._curry1 import _curry1 + +trim = _curry1(lambda s: s.strip()) diff --git a/test/test_trim.py b/test/test_trim.py new file mode 100644 index 0000000..cd29e1e --- /dev/null +++ b/test/test_trim.py @@ -0,0 +1,22 @@ + +import unittest + +import ramda as R + +""" +https://github.com/ramda/ramda/blob/master/test/T.js +""" + +test = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFFHello, World!\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF' + +class TestT(unittest.TestCase): + def test_trims_a_string(self): + self.assertEqual('xyz', R.trim(' xyz ')) + + def test_does_not_trim_the_zero_width_space(self): + self.assertEqual('\u200b', R.trim('\u200b')) + self.assertEqual(1, len(R.trim('\u200b'))) + + +if __name__ == '__main__': + unittest.main()