From 3d637173ee2f4d07c016135ceee9eb3321cd5769 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 16 May 2014 15:59:49 +0200 Subject: [PATCH] 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. --- spec/{ => api}/generated-parser.spec.js | 0 spec/helpers.js | 60 ------------------- spec/index.html | 13 ++-- .../compiler/passes/generate-bytecode.spec.js | 0 spec/unit/compiler/passes/helpers.js | 59 ++++++++++++++++++ .../passes/remove-proxy-rules.spec.js | 0 .../passes/report-left-recursion.spec.js | 0 .../passes/report-missing-rules.spec.js | 0 spec/{ => unit}/parser.spec.js | 0 9 files changed, 66 insertions(+), 66 deletions(-) rename spec/{ => api}/generated-parser.spec.js (100%) rename spec/{ => unit}/compiler/passes/generate-bytecode.spec.js (100%) create mode 100644 spec/unit/compiler/passes/helpers.js rename spec/{ => unit}/compiler/passes/remove-proxy-rules.spec.js (100%) rename spec/{ => unit}/compiler/passes/report-left-recursion.spec.js (100%) rename spec/{ => unit}/compiler/passes/report-missing-rules.spec.js (100%) rename spec/{ => unit}/parser.spec.js (100%) diff --git a/spec/generated-parser.spec.js b/spec/api/generated-parser.spec.js similarity index 100% rename from spec/generated-parser.spec.js rename to spec/api/generated-parser.spec.js diff --git a/spec/helpers.js b/spec/helpers.js index 41b7954..e7ab8f7 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -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); - } - }); -}); diff --git a/spec/index.html b/spec/index.html index 8e2a25f..4f3ba53 100644 --- a/spec/index.html +++ b/spec/index.html @@ -7,12 +7,13 @@ - - - - - - + + + + + + +