Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var assert = require("assert");
  2. var vows = require("vows");
  3. var Scanner = require("./../mustache").Scanner;
  4. vows.describe("Mustache.Scanner").addBatch({
  5. "A Scanner": {
  6. "for an empty string": {
  7. topic: new Scanner(""),
  8. "is at the end of the string": function () {
  9. var scanner = new Scanner("");
  10. assert(scanner.eos());
  11. }
  12. },
  13. "for a non-empty string": {
  14. topic: "a b c",
  15. "when calling scan": {
  16. "when the regexp matches the entire string": {
  17. topic: function (string) {
  18. var scanner = new Scanner(string);
  19. var match = scanner.scan(/a b c/);
  20. this.callback(scanner, match);
  21. },
  22. "returns the entire string": function (scanner, match) {
  23. assert.equal(match, scanner.string);
  24. },
  25. "is at the end of the string": function (scanner, match) {
  26. assert(scanner.eos());
  27. }
  28. }, // when the regexp matches the entire string
  29. "when the regexp matches": {
  30. "at the 0th index": {
  31. topic: function (string) {
  32. var scanner = new Scanner(string);
  33. var match = scanner.scan(/a/);
  34. this.callback(scanner, match);
  35. },
  36. "returns the portion of the string that was matched": function (scanner, match) {
  37. assert.equal(match, "a");
  38. },
  39. "advances the internal pointer the length of the match": function (scanner, match) {
  40. assert.equal(scanner.pos, 1);
  41. }
  42. }, // at the 0th index
  43. "at some index other than 0": {
  44. topic: function (string) {
  45. var scanner = new Scanner(string);
  46. var match = scanner.scan(/b/);
  47. this.callback(scanner, match);
  48. },
  49. "returns the empty string": function (scanner, match) {
  50. assert.equal(match, "");
  51. },
  52. "does not advance the internal pointer": function (scanner, match) {
  53. assert.equal(scanner.pos, 0);
  54. }
  55. } // at some index other than 0
  56. }, // when the regexp matches
  57. "when the regexp doesn't match": {
  58. topic: function (string) {
  59. var scanner = new Scanner(string);
  60. var match = scanner.scan(/z/);
  61. this.callback(scanner, match);
  62. },
  63. "returns the empty string": function (scanner, match) {
  64. assert.equal(match, "");
  65. },
  66. "does not advance the internal pointer": function (scanner, match) {
  67. assert.equal(scanner.pos, 0);
  68. }
  69. }
  70. }, // when calling scan
  71. "when calling scanUntil": {
  72. "when the regexp matches": {
  73. "at the 0th index": {
  74. topic: function (string) {
  75. var scanner = new Scanner(string);
  76. var match = scanner.scanUntil(/a/);
  77. this.callback(scanner, match);
  78. },
  79. "returns the empty string": function (scanner, match) {
  80. assert.equal(match, "")
  81. },
  82. "does not advance the internal pointer": function (scanner, match) {
  83. assert.equal(scanner.pos, 0);
  84. }
  85. },
  86. "at index 2": {
  87. topic: function (string) {
  88. var scanner = new Scanner(string);
  89. var match = scanner.scanUntil(/b/);
  90. this.callback(scanner, match);
  91. },
  92. "returns the portion of the string it scanned": function (scanner, match) {
  93. assert.equal(match, "a ");
  94. },
  95. "advances the internal pointer the length of the match": function (scanner, match) {
  96. assert.equal(scanner.pos, 2);
  97. }
  98. }
  99. }, // when the regexp matches
  100. "when the regexp doesn't match": {
  101. topic: function (string) {
  102. var scanner = new Scanner(string);
  103. var match = scanner.scanUntil(/z/);
  104. this.callback(scanner, match);
  105. },
  106. "returns the entire string": function (scanner, match) {
  107. assert.equal(match, scanner.string);
  108. },
  109. "is at the end of the string": function (scanner, match) {
  110. assert(scanner.eos());
  111. }
  112. } // when the regexp doesn't match
  113. } // when calling scanUntil
  114. } // for a non-empty string
  115. }
  116. }).export(module);