string.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. describe('StringService', function() {
  2. let $service;
  3. // Ignoring page reload request
  4. beforeAll(() => window.onbeforeunload = () => null);
  5. beforeEach(function() {
  6. module('3ema.services');
  7. // Inject the service
  8. inject(function(StringService) {
  9. $service = StringService;
  10. });
  11. });
  12. describe('byteChunkSplit', function() {
  13. this.testPatterns = (cases, size, offset) => {
  14. for (let testcase of cases) {
  15. const input = testcase[0];
  16. const expected = testcase[1];
  17. expect($service.byteChunk(input, size, offset)).toEqual(expected);
  18. }
  19. };
  20. it('short chunks', () => {
  21. this.testPatterns([
  22. ['abc',
  23. ['abc',]],
  24. ['abcdefghijklmn',
  25. ['abcdef', 'ghijkl', 'mn',]],
  26. // four byte emoji
  27. ['😅😅',
  28. ['😅', '😅']]
  29. ], 6, null);
  30. });
  31. it('chunks with offset', () => {
  32. this.testPatterns([
  33. ['The quick white 🐼. He jumped over the lazy 🐶.',
  34. ['The', 'quick', 'white', '🐼.', 'He', 'jumped', 'over', 'the', 'lazy', '🐶.',]],
  35. ], 6, 10);
  36. this.testPatterns([
  37. ['The quick white 🐼. He jumped over the lazy 🐶.',
  38. ['The quick white 🐼', '. He jumped over the', 'lazy 🐶.',]],
  39. ], 20, 10);
  40. });
  41. });
  42. });