tests.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # Tests of i18n scripts.
  4. #
  5. # Copyright 2013 Google Inc.
  6. # https://developers.google.com/blockly/
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. import common
  20. import re
  21. import unittest
  22. class TestSequenceFunctions(unittest.TestCase):
  23. def test_insert_breaks(self):
  24. spaces = re.compile(r'\s+|\\n')
  25. def contains_all_chars(orig, result):
  26. return re.sub(spaces, '', orig) == re.sub(spaces, '', result)
  27. sentences = [u'Quay Pegman qua bên trái hoặc bên phải 90 độ.',
  28. u'Foo bar baz this is english that is okay bye.',
  29. u'If there is a path in the specified direction, \nthen ' +
  30. u'do some actions.',
  31. u'If there is a path in the specified direction, then do ' +
  32. u'the first block of actions. Otherwise, do the second ' +
  33. u'block of actions.']
  34. for sentence in sentences:
  35. output = common.insert_breaks(sentence, 30, 50)
  36. self.assert_(contains_all_chars(sentence, output),
  37. u'Mismatch between:\n{0}\n{1}'.format(
  38. re.sub(spaces, '', sentence),
  39. re.sub(spaces, '', output)))
  40. if __name__ == '__main__':
  41. unittest.main()