Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving the tests out of that old html file and in to plain js

  • Loading branch information...
commit 39942e5ae30dfbccdd4250f562792920013d9fc4 1 parent d99dd05
@fitzgen authored
Showing with 46 additions and 59 deletions.
  1. +46 −0 tests/tests.js
  2. +0 −59 tests/xform-tests.html
View
46 tests/tests.js
@@ -0,0 +1,46 @@
+var ops = require("../operations");
+var xform = require("../xform");
+var apply = require("../apply");
+
+var numTests = 0;
+var failed = 0;
+
+function test (original, a, b, expected) {
+ var operationsA = ops.operation(original, a);
+ var operationsB = ops.operation(original, b);
+ xform(operationsA, operationsB, function (ap, bp) {
+ numTests++;
+ try {
+ console.log(original + " -< (" + a + ", " + b +") >- "
+ + expected);
+
+ var docA = apply(operationsA, original);
+ var finalA = apply(bp, docA);
+ console.log(" " + original + " -> " + docA + " -> "
+ + finalA);
+ if ( finalA !== expected ) {
+ throw new Error(finalA + " !== " + expected);
+ }
+
+ var docB = apply(operationsB, original);
+ var finalB = apply(ap, docB);
+ console.log(" " + original + " -> " + docB + " -> "
+ + finalB);
+ if ( finalB !== expected ) {
+ throw new Error(finalB + " !== " + expected);
+ }
+ } catch (e) {
+ failed++;
+ console.log(" ERROR: " + e.message);
+ }
+ });
+}
+
+test("at", "t", "fat", "ft");
+test("nick", "Nick", "nick is cool", "Nick is cool");
+test("sudo", "sumo", "suo", "sumo");
+test("hello", "Hello", "Hello", "Hello");
+test("care", "are", "are", "are");
+test("air", "fair", "lair", "flair");
+
+console.log(numTests - failed + " / " + numTests + " tests passed.");
View
59 tests/xform-tests.html
@@ -1,59 +0,0 @@
-<html>
- <body>
- <script src="require.js"></script>
- <script>
- require({ baseUrl: "",
- urlArgs: "bust=" + new Date() },
- ["operations", "xform", "apply"],
- function (ops, xform, apply) {
- window.ops = ops;
- window.xform = xform;
- window.apply = apply;
-
- var numTests = 0;
- var failed = 0;
-
- function test (original, a, b, expected) {
- var operationsA = ops.getOperations(original, a);
- var operationsB = ops.getOperations(original, b);
- xform(operationsA, operationsB, function (ap, bp) {
- numTests++;
- try {
- console.log(original + " -< (" + a + ", " + b +") >- "
- + expected);
-
- var docA = apply(operationsA, original);
- var finalA = apply(bp, docA);
- console.log(" " + original + " -> " + docA + " -> "
- + finalA);
- if ( finalA !== expected ) {
- throw new Error(finalA + " !== " + expected);
- }
-
- var docB = apply(operationsB, original);
- var finalB = apply(ap, docB);
- console.log(" " + original + " -> " + docB + " -> "
- + finalB);
- if ( finalB !== expected ) {
- throw new Error(finalB + " !== " + expected);
- }
- } catch (e) {
- failed++;
- console.log(" ERROR: " + e.message);
- }
- });
- }
-
- test("at", "t", "fat", "ft");
- test("nick", "Nick", "nick is cool", "Nick is cool");
- test("sudo", "sumo", "suo", "sumo");
- test("hello", "Hello", "Hello", "Hello");
- test("care", "are", "are", "are");
- test("air", "fair", "lair", "flair");
-
- console.log(numTests - failed + " / " + numTests + " tests passed.");
-
- });
- </script>
- </body>
-</html>
Please sign in to comment.
Something went wrong with that request. Please try again.