summaryrefslogtreecommitdiff
path: root/tests/test_analyzer.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-20 13:25:32 +0300
committerAlon Levy <alon@pobox.com>2014-10-20 21:36:37 +0300
commitc919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch)
treedd6394603680976c48801b53321e8085b0db1505 /tests/test_analyzer.js
parentf1f4e937932f52c630831d0d501f8f8756b37531 (diff)
introduce require.js and rewrite tests
Yes, I'm being lazy. The purpose of require.js is to allow writing modules, i.e. individual smaller then the whole files with clear dependencies. This is achieved by using a new api provided by require.js: define, require, requirejs Read more at [requirejs] (http://requirejs.org) Tests have been rewritten to work correctly with require.js; they still use jsdom. Test output is now stored in the repository, all tests are run via run_tests.js; This is a hack - once a good harness (with assertions, suites - unittest like) presents itself it will be used. Hidden here is also using FileSaver for history saving, so history is saved to history.json instead to a random name. Plus dropping some dead code.
Diffstat (limited to 'tests/test_analyzer.js')
-rw-r--r--tests/test_analyzer.js87
1 files changed, 18 insertions, 69 deletions
diff --git a/tests/test_analyzer.js b/tests/test_analyzer.js
index b7b66a66..d003f8f6 100644
--- a/tests/test_analyzer.js
+++ b/tests/test_analyzer.js
@@ -1,55 +1,4 @@
-var fs = require('fs'),
- jsdom = require('jsdom');
-
-var script_filenames = [
- "external/scripts/d3/d3.js",
- "external/scripts/jquery.js",
- "external/scripts/jquery-ui.js",
- "external/scripts/autocomplete.js",
-
- "scripts/caret.js",
- "scripts/history.js",
- "scripts/rhizicore.js",
- "scripts/textanalysis.js",
- "scripts/textanalysis-ui.js",
- "scripts/buttons.js",
- "scripts/drag_n_drop.js",
- "scripts/robot.js",
- "scripts/watchdog.js",
- "scripts/gant.js"].map(function(x) { return "../" + x; });
-
-function dump_nodes(window) {
- var nodes = window.force.nodes();
- for(var i = 0 ; i < nodes.length; ++i) {
- console.log('nodes[' + nodes[i].id + '/' + nodes[i].type + '].[xy] = (' + nodes[i].x + ',' + nodes[i].y + ')');
- }
-}
-
-function dump_graphviz(window) {
- var i;
- var nodes = window.force.nodes();
- var links = window.force.links();
- var q = function(s) {
- if (s.search(' ') == -1) {
- return s;
- }
- return '"' + s + '"';
- };
-
- console.log('digraph {');
- for (i = 0 ; i < nodes.length; ++i) {
- if (nodes[i].type == 'bubble') {
- console.log(' BUBBLE;');
- } else {
- console.log(' ' + q(nodes[i].name) + ';');
- }
- }
- for (i = 0 ; i < links.length; ++i) {
- var link = links[i];
- console.log(' ' + q(link.source.name) + ' -> ' + q(link.target.name) + ';');
- }
- console.log('}');
-}
+var base = require('./base');
var data = [
["#a hello there #b", ["a", "b"], [["a", "b", "hello there"]],
@@ -66,21 +15,21 @@ sometimes #z and #ab aren't friends
I like to work with #a
*/
-
-var done = function (errors, window) {
- debugger;
- if (process.argv.length > 2) {
- window.analyzeSentence(process.argv.slice(2).join(" "), true);
- dump_graphviz(window);
+base.run_tests({
+ done: function (errors, window) {
+ debugger;
+ if (process.argv.length > 2) {
+ window.analyzeSentence(process.argv.slice(2).join(" "), true);
+ dump_graphviz(window);
+ } else {
+ for (var k in data) {
+ var sentence = data[k][0];
+ var expected_nodes = data[k][1];
+ var expected_links = data[k][2];
+ window.analyzeSentence(sentence, true);
+ // TODO - compare graphs
+ }
+ }
+ process.exit();
}
- process.exit();
-}
-
-var env = jsdom.env({
- scripts: script_filenames,
- html: "<html><body></body></html>",
- created: function(errors, window) {
- window.console.log = console.log; // slightly evil
- window.process = process; // more evil
- },
- done: done});
+});