Permalink
Please sign in to comment.
Browse files
Fix bug in prefix/suffix strip operators.
I had to make a table to show that we always consider N prefixes and suffixes, and that the order is exactly revesred for # vs ## an % and %%. Uncovered by k-script-build.
- Loading branch information...
Showing
with
70 additions
and 4 deletions.
- +8 −4 core/libstr.py
- +42 −0 core/libstr_test.py
- +20 −0 spec/var-op-strip.test.sh
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/python -S | ||
| """ | ||
| libstr_test.py: Tests for libstr.py | ||
| """ | ||
| import unittest | ||
| import libstr # module under test | ||
| class LibStrTest(unittest.TestCase): | ||
| def testUnarySuffixOpDemo(self): | ||
| s = 'abcd' | ||
| n = len(s) | ||
| # All of these loops test exactly 4. | ||
| # NOTE: These are manually copied into DoUnarySuffixOp | ||
| print('## shortest prefix') | ||
| for i in xrange(1, n+1): | ||
| print '%d test %06r return %06r' % (i, s[:i], s[i:]) | ||
| print('# longest prefix') | ||
| for i in xrange(n, 0, -1): | ||
| print '%d test %06r return %06r' % (i, s[:i], s[i:]) | ||
| print('% shortest suffix') | ||
| for i in xrange(n-1, -1, -1): | ||
| print '%d test %06r return %06r' % (i, s[i:], s[:i]) | ||
| print('%% longest suffix') | ||
| for i in xrange(0, n): | ||
| print '%d test %06r return %06r' % (i, s[i:], s[:i]) | ||
| if __name__ == '__main__': | ||
| unittest.main() |
0 comments on commit
a9a7fad