string.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. it('parse null string', () => {
  13. expect($service.getWord(null, 1)).toEqual(jasmine.objectContaining({
  14. word: null,
  15. realLength: 0
  16. }));
  17. });
  18. it('parse empty string', () => {
  19. expect($service.getWord('', 1)).toEqual(jasmine.objectContaining({
  20. word: null,
  21. realLength: 0
  22. }));
  23. });
  24. it('parse string (spaces)', () => {
  25. expect($service.getWord('When the man comes around.', 12)).toEqual(jasmine.objectContaining({
  26. word: 'man',
  27. realLength: 3
  28. }));
  29. expect($service.getWord('When the man comes around.', 13)).toEqual(jasmine.objectContaining({
  30. word: 'man',
  31. realLength: 4
  32. }));
  33. expect($service.getWord('When the man comes around.', 16)).toEqual(jasmine.objectContaining({
  34. word: 'man',
  35. realLength: 7
  36. }));
  37. });
  38. it('parse string (newline)', () => {
  39. expect($service.getWord("When\nthe\nman\ncomes\naround.", 12)).toEqual(jasmine.objectContaining({
  40. word: 'man',
  41. realLength: 3
  42. }));
  43. expect($service.getWord("When\nthe\nman\ncomes\naround.", 13)).toEqual(jasmine.objectContaining({
  44. word: 'man',
  45. realLength: 4
  46. }));
  47. expect($service.getWord("When\nthe\nman\n\n\n\n\n\n\n\ncomes\naround.", 16)).toEqual(jasmine.objectContaining({
  48. word: 'man',
  49. realLength: 7
  50. }));
  51. });
  52. it('parse string (newline/spaces)', () => {
  53. expect($service.getWord("When the\nman comes around.", 12)).toEqual(jasmine.objectContaining({
  54. word: 'man',
  55. realLength: 3
  56. }));
  57. expect($service.getWord("When the\nman \ncomes around.", 13)).toEqual(jasmine.objectContaining({
  58. word: 'man',
  59. realLength: 4
  60. }));
  61. expect($service.getWord("When the\nman \n \n \n \ncomes around.", 16)).toEqual(jasmine.objectContaining({
  62. word: 'man',
  63. realLength: 7
  64. }));
  65. });
  66. it('parse string (special character)', () => {
  67. expect($service.getWord('When the :man: comes around.', 15)).toEqual(jasmine.objectContaining({
  68. word: ':man:',
  69. realLength: 6
  70. }));
  71. expect($service.getWord('When the :man: comes around.', 14)).toEqual(jasmine.objectContaining({
  72. word: ':man:',
  73. realLength: 5
  74. }));
  75. });
  76. it('parse string (with emoji (2 chars))', () => {
  77. expect($service.getWord('this 😄 is a :smile: face', 19)).toEqual(jasmine.objectContaining({
  78. word: ':smile:',
  79. realLength: 7
  80. }));
  81. });
  82. it('parse string (additional separators)', () => {
  83. expect($service.getWord('When the spider:man: comes around.', 20, [':'])).toEqual(jasmine.objectContaining({
  84. word: ':man:',
  85. realLength: 5
  86. }));
  87. });
  88. });