Specs cleanup: Split specs into unit and API specs

Unit specs are unit tests of internal stuff. API specs are tests of the
user-visible APIs and behavior.

I think it makes sense to make this distinction because then the public
API line is more clearly visible e.g. when using the specs as
documentation.
redux
David Majda 11 years ago
parent f457c41dd4
commit 3d637173ee

@ -1,63 +1,3 @@
if (typeof module !== "undefined") {
PEG = require("../lib/peg.js");
}
beforeEach(function() {
this.addMatchers({
toChangeAST: function(grammar) {
function matchDetails(value, details) {
function isArray(value) {
return Object.prototype.toString.apply(value) === "[object Array]";
}
function isObject(value) {
return value !== null && typeof value === "object";
}
var i, key;
if (isArray(details)) {
if (!isArray(value)) { return false; }
if (value.length !== details.length) { return false; }
for (i = 0; i < details.length; i++) {
if (!matchDetails(value[i], details[i])) { return false; }
}
return true;
} else if (isObject(details)) {
if (!isObject(value)) { return false; }
for (key in details) {
if (details.hasOwnProperty(key)) {
if (!(key in value)) { return false; }
if (!matchDetails(value[key], details[key])) { return false; }
}
}
return true;
} else {
return value === details;
}
}
var options = arguments.length > 2 ? arguments[1] : {},
details = arguments[arguments.length - 1],
ast = PEG.parser.parse(grammar);
this.actual(ast, options);
this.message = function() {
return "Expected the pass "
+ "with options " + jasmine.pp(options) + " "
+ (this.isNot ? "not " : "")
+ "to change the AST " + jasmine.pp(ast) + " "
+ "to match " + jasmine.pp(details) + ", "
+ "but it " + (this.isNot ? "did" : "didn't") + ".";
};
return matchDetails(ast, details);
}
});
});

@ -7,12 +7,13 @@
<script src="vendor/jasmine/jasmine-html.js"></script>
<script src="../browser/peg-0.8.0.js"></script>
<script src="helpers.js"></script>
<script src="parser.spec.js"></script>
<script src="generated-parser.spec.js"></script>
<script src="compiler/passes/report-missing-rules.spec.js"></script>
<script src="compiler/passes/report-left-recursion.spec.js"></script>
<script src="compiler/passes/remove-proxy-rules.spec.js"></script>
<script src="compiler/passes/generate-bytecode.spec.js"></script>
<script src="unit/parser.spec.js"></script>
<script src="unit/compiler/passes/helpers.js"></script>
<script src="unit/compiler/passes/report-missing-rules.spec.js"></script>
<script src="unit/compiler/passes/report-left-recursion.spec.js"></script>
<script src="unit/compiler/passes/remove-proxy-rules.spec.js"></script>
<script src="unit/compiler/passes/generate-bytecode.spec.js"></script>
<script src="api/generated-parser.spec.js"></script>
<script>
(function() {
var env = jasmine.getEnv(),

@ -0,0 +1,59 @@
beforeEach(function() {
this.addMatchers({
toChangeAST: function(grammar) {
function matchDetails(value, details) {
function isArray(value) {
return Object.prototype.toString.apply(value) === "[object Array]";
}
function isObject(value) {
return value !== null && typeof value === "object";
}
var i, key;
if (isArray(details)) {
if (!isArray(value)) { return false; }
if (value.length !== details.length) { return false; }
for (i = 0; i < details.length; i++) {
if (!matchDetails(value[i], details[i])) { return false; }
}
return true;
} else if (isObject(details)) {
if (!isObject(value)) { return false; }
for (key in details) {
if (details.hasOwnProperty(key)) {
if (!(key in value)) { return false; }
if (!matchDetails(value[key], details[key])) { return false; }
}
}
return true;
} else {
return value === details;
}
}
var options = arguments.length > 2 ? arguments[1] : {},
details = arguments[arguments.length - 1],
ast = PEG.parser.parse(grammar);
this.actual(ast, options);
this.message = function() {
return "Expected the pass "
+ "with options " + jasmine.pp(options) + " "
+ (this.isNot ? "not " : "")
+ "to change the AST " + jasmine.pp(ast) + " "
+ "to match " + jasmine.pp(details) + ", "
+ "but it " + (this.isNot ? "did" : "didn't") + ".";
};
return matchDetails(ast, details);
}
});
});
Loading…
Cancel
Save