helpers.js 1.5 KB

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