Tighten "try ... catch" clauses in spec helpers

They wrapped too much code.
redux
David Majda 8 years ago
parent 67d85f2de8
commit bf9d9561c4

@ -41,20 +41,6 @@ describe("generated parser behavior", function() {
try {
result = this.actual.parse(input, options);
if (expected !== undefined) {
this.message = function() {
return "Expected " + jasmine.pp(input) + " "
+ "with options " + jasmine.pp(options) + " "
+ (this.isNot ? "not " : "")
+ "to parse as " + jasmine.pp(expected) + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return this.env.equals_(result, expected);
} else {
return true;
}
} catch (e) {
this.message = function() {
return "Expected " + jasmine.pp(input) + " "
@ -66,6 +52,20 @@ describe("generated parser behavior", function() {
return false;
}
if (expected !== undefined) {
this.message = function() {
return "Expected " + jasmine.pp(input) + " "
+ "with options " + jasmine.pp(options) + " "
+ (this.isNot ? "not " : "")
+ "to parse as " + jasmine.pp(expected) + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return this.env.equals_(result, expected);
} else {
return true;
}
},
toFailToParse: function(input, details, options) {
@ -75,16 +75,6 @@ describe("generated parser behavior", function() {
try {
result = this.actual.parse(input, options);
this.message = function() {
return "Expected " + jasmine.pp(input) + " "
+ "with options " + jasmine.pp(options) + " "
+ "to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return false;
} catch (e) {
if (this.isNot) {
this.message = function() {
@ -117,6 +107,16 @@ describe("generated parser behavior", function() {
return true;
}
this.message = function() {
return "Expected " + jasmine.pp(input) + " "
+ "with options " + jasmine.pp(options) + " "
+ "to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return false;
}
});
});

@ -66,15 +66,6 @@ beforeEach(function() {
try {
this.actual(ast);
this.message = function() {
return "Expected the pass to report an error "
+ (details ? "with details " + jasmine.pp(details) + " ": "")
+ "for grammar " + jasmine.pp(grammar) + ", "
+ "but it didn't.";
};
return false;
} catch (e) {
if (this.isNot) {
this.message = function() {
@ -104,6 +95,15 @@ beforeEach(function() {
return true;
}
this.message = function() {
return "Expected the pass to report an error "
+ (details ? "with details " + jasmine.pp(details) + " ": "")
+ "for grammar " + jasmine.pp(grammar) + ", "
+ "but it didn't.";
};
return false;
}
});
});

@ -179,17 +179,6 @@ describe("PEG.js grammar parser", function() {
try {
result = peg.parser.parse(this.actual);
stripLocation(result);
this.message = function() {
return "Expected " + jasmine.pp(this.actual) + " "
+ (this.isNot ? "not " : "")
+ "to parse as " + jasmine.pp(expected) + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return this.env.equals_(result, expected);
} catch (e) {
this.message = function() {
return "Expected " + jasmine.pp(this.actual) + " "
@ -200,6 +189,17 @@ describe("PEG.js grammar parser", function() {
return false;
}
stripLocation(result);
this.message = function() {
return "Expected " + jasmine.pp(this.actual) + " "
+ (this.isNot ? "not " : "")
+ "to parse as " + jasmine.pp(expected) + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return this.env.equals_(result, expected);
},
toFailToParse: function(details) {
@ -207,16 +207,6 @@ describe("PEG.js grammar parser", function() {
try {
result = peg.parser.parse(this.actual);
stripLocation(result);
this.message = function() {
return "Expected " + jasmine.pp(this.actual) + " to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return false;
} catch (e) {
if (this.isNot) {
this.message = function() {
@ -245,6 +235,16 @@ describe("PEG.js grammar parser", function() {
return true;
}
stripLocation(result);
this.message = function() {
return "Expected " + jasmine.pp(this.actual) + " to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but it parsed as " + jasmine.pp(result) + ".";
};
return false;
}
});
});

Loading…
Cancel
Save