speed.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. (function() {
  2. JSLitmus.test('levenshtein', function() {
  3. return [
  4. _.levenshtein('pineapple', 'potato'),
  5. _.levenshtein('seven', 'eight'),
  6. _.levenshtein('the very same string', 'the very same string'),
  7. _.levenshtein('very very very long string', 'something completely different')
  8. ];
  9. });
  10. JSLitmus.test('trimNoNative', function() {
  11. return _.trim(" foobar ", " ");
  12. });
  13. JSLitmus.test('trim', function() {
  14. return _.trim(" foobar ");
  15. });
  16. JSLitmus.test('trim object-oriented', function() {
  17. return _(" foobar ").trim();
  18. });
  19. JSLitmus.test('trim jQuery', function() {
  20. return jQuery.trim(" foobar ");
  21. });
  22. JSLitmus.test('ltrimp', function() {
  23. return _.ltrim(" foobar ", " ");
  24. });
  25. JSLitmus.test('rtrimp', function() {
  26. return _.rtrim(" foobar ", " ");
  27. });
  28. JSLitmus.test('startsWith', function() {
  29. return _.startsWith("foobar", "foo");
  30. });
  31. JSLitmus.test('endsWith', function() {
  32. return _.endsWith("foobar", "xx");
  33. });
  34. JSLitmus.test('chop', function(){
  35. return _('whitespace').chop(2);
  36. });
  37. JSLitmus.test('count', function(){
  38. return _('Hello worls').count('l');
  39. });
  40. JSLitmus.test('insert', function() {
  41. return _('Hello ').insert(6, 'world');
  42. });
  43. JSLitmus.test('splice', function() {
  44. return _('https://edtsech@bitbucket.org/edtsech/underscore.strings').splice(30, 7, 'epeli');
  45. });
  46. JSLitmus.test('succ', function(){
  47. var let = 'a', alphabet = [];
  48. for (var i=0; i < 26; i++) {
  49. alphabet.push(let);
  50. let = _(let).succ();
  51. }
  52. return alphabet;
  53. });
  54. JSLitmus.test('titleize', function(){
  55. return _('the titleize string method').titleize();
  56. });
  57. JSLitmus.test('truncate', function(){
  58. return _('Hello world').truncate(5);
  59. });
  60. JSLitmus.test('prune', function(){
  61. return _('Hello world').prune(5);
  62. });
  63. JSLitmus.test('isBlank', function(){
  64. return _('').isBlank();
  65. });
  66. JSLitmus.test('escapeHTML', function(){
  67. _('<div>Blah blah blah</div>').escapeHTML();
  68. });
  69. JSLitmus.test('unescapeHTML', function(){
  70. _('&lt;div&gt;Blah blah blah&lt;/div&gt;').unescapeHTML();
  71. });
  72. JSLitmus.test('reverse', function(){
  73. _('Hello World').reverse();
  74. });
  75. JSLitmus.test('pad default', function(){
  76. _('foo').pad(12);
  77. });
  78. JSLitmus.test('pad hash left', function(){
  79. _('foo').pad(12, '#');
  80. });
  81. JSLitmus.test('pad hash right', function(){
  82. _('foo').pad(12, '#', 'right');
  83. });
  84. JSLitmus.test('pad hash both', function(){
  85. _('foo').pad(12, '#', 'both');
  86. });
  87. JSLitmus.test('pad hash both longPad', function(){
  88. _('foo').pad(12, 'f00f00f00', 'both');
  89. });
  90. JSLitmus.test('toNumber', function(){
  91. _('10.232323').toNumber(2);
  92. });
  93. JSLitmus.test('strRight', function(){
  94. _('aaa_bbb_ccc').strRight('_');
  95. });
  96. JSLitmus.test('strRightBack', function(){
  97. _('aaa_bbb_ccc').strRightBack('_');
  98. });
  99. JSLitmus.test('strLeft', function(){
  100. _('aaa_bbb_ccc').strLeft('_');
  101. });
  102. JSLitmus.test('strLeftBack', function(){
  103. _('aaa_bbb_ccc').strLeftBack('_');
  104. });
  105. JSLitmus.test('join', function(){
  106. _('separator').join(1, 2, 3, 4, 5, 6, 7, 8, 'foo', 'bar', 'lol', 'wut');
  107. });
  108. JSLitmus.test('slugify', function(){
  109. _("Un éléphant à l'orée du bois").slugify();
  110. });
  111. })();