A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

12 years ago
  1. require('./helper');
  2. var Scanner = Mustache.Scanner;
  3. describe('A new Mustache.Scanner', function () {
  4. describe('for an empty string', function () {
  5. it('is at the end', function () {
  6. var scanner = new Scanner('');
  7. assert(scanner.eos());
  8. });
  9. });
  10. describe('for a non-empty string', function () {
  11. var scanner;
  12. beforeEach(function () {
  13. scanner = new Scanner('a b c');
  14. });
  15. describe('scan', function () {
  16. describe('when the RegExp matches the entire string', function () {
  17. it('returns the entire string', function () {
  18. var match = scanner.scan(/a b c/);
  19. assert.equal(match, scanner.string);
  20. assert(scanner.eos());
  21. });
  22. });
  23. describe('when the RegExp matches at index 0', function () {
  24. it('returns the portion of the string that matched', function () {
  25. var match = scanner.scan(/a/);
  26. assert.equal(match, 'a');
  27. assert.equal(scanner.pos, 1);
  28. });
  29. });
  30. describe('when the RegExp matches at some index other than 0', function () {
  31. it('returns the empty string', function () {
  32. var match = scanner.scan(/b/);
  33. assert.equal(match, '');
  34. assert.equal(scanner.pos, 0);
  35. });
  36. });
  37. describe('when the RegExp does not match', function () {
  38. it('returns the empty string', function () {
  39. var match = scanner.scan(/z/);
  40. assert.equal(match, '');
  41. assert.equal(scanner.pos, 0);
  42. });
  43. });
  44. }); // scan
  45. describe('scanUntil', function () {
  46. describe('when the RegExp matches at index 0', function () {
  47. it('returns the empty string', function () {
  48. var match = scanner.scanUntil(/a/);
  49. assert.equal(match, '');
  50. assert.equal(scanner.pos, 0);
  51. });
  52. });
  53. describe('when the RegExp matches at some index other than 0', function () {
  54. it('returns the string up to that index', function () {
  55. var match = scanner.scanUntil(/b/);
  56. assert.equal(match, 'a ');
  57. assert.equal(scanner.pos, 2);
  58. });
  59. });
  60. describe('when the RegExp does not match', function () {
  61. it('returns the entire string', function () {
  62. var match = scanner.scanUntil(/z/);
  63. assert.equal(match, scanner.string);
  64. assert(scanner.eos());
  65. });
  66. });
  67. }); // scanUntil
  68. }); // for a non-empty string
  69. });