Bladeren bron

Scanner returns empty string if it can't match

tags/0.5.2
Michael Jackson 13 jaren geleden
bovenliggende
commit
9e6943c867
2 gewijzigde bestanden met toevoegingen van 10 en 11 verwijderingen
  1. +4
    -5
      mustache.js
  2. +6
    -6
      test/scanner_test.js

+ 4
- 5
mustache.js Bestand weergeven

@@ -114,7 +114,7 @@ var Mustache;

/**
* Tries to match the given regular expression at the current position.
* Returns the matched text if it can match, `null` otherwise.
* Returns the matched text if it can match, the empty string otherwise.
*/
Scanner.prototype.scan = function (re) {
var match = this.tail.match(re);
@@ -125,13 +125,12 @@ var Mustache;
return match[0];
}

return null;
return "";
};

/**
* Skips all text until the given regular expression can be matched. Returns
* the skipped string, which is the entire tail of this scanner if no match
* can be made.
* the skipped string, which is the entire tail if no match can be made.
*/
Scanner.prototype.scanUntil = function (re) {
var match, pos = this.tail.search(re);
@@ -143,7 +142,7 @@ var Mustache;
this.tail = "";
break;
case 0:
match = null;
match = "";
break;
default:
match = this.tail.substring(0, pos);


+ 6
- 6
test/scanner_test.js Bestand weergeven

@@ -47,8 +47,8 @@ vows.describe("Mustache.Scanner").addBatch({
var match = scanner.scan(/b/);
this.callback(scanner, match);
},
"it should return null": function (scanner, match) {
assert.equal(match, null);
"it should return the empty string": function (scanner, match) {
assert.equal(match, "");
},
"it should not advance the internal pointer": function (scanner, match) {
assert.equal(scanner.pos, 0);
@@ -61,8 +61,8 @@ vows.describe("Mustache.Scanner").addBatch({
var match = scanner.scan(/z/);
this.callback(scanner, match);
},
"it should return null": function (scanner, match) {
assert.equal(match, null);
"it should return the empty string": function (scanner, match) {
assert.equal(match, "");
},
"it should not advance the internal pointer": function (scanner, match) {
assert.equal(scanner.pos, 0);
@@ -77,8 +77,8 @@ vows.describe("Mustache.Scanner").addBatch({
var match = scanner.scanUntil(/a/);
this.callback(scanner, match);
},
"it should return null": function (scanner, match) {
assert.equal(match, null)
"it should return the empty string": function (scanner, match) {
assert.equal(match, "")
},
"it should not advance the internal pointer": function (scanner, match) {
assert.equal(scanner.pos, 0);


Laden…
Annuleren
Opslaan