diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-20 13:25:32 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-20 21:36:37 +0300 |
| commit | c919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch) | |
| tree | dd6394603680976c48801b53321e8085b0db1505 /scripts/util.js | |
| parent | f1f4e937932f52c630831d0d501f8f8756b37531 (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 'scripts/util.js')
| -rw-r--r-- | scripts/util.js | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/scripts/util.js b/scripts/util.js index 4eb94266..4af7a7cf 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -1,12 +1,39 @@ -function set_from_array(a) { +/* + Craziness to deal with the bolted on module systems that we use: + In browser: require.js, it uses a global function named 'define' + On server for tests: Node, it provides a module definition time object named 'exports' +*/ +(function(factory) { + if (typeof define != 'undefined') { + define('util', factory); + } else { + if (typeof exports == 'object') { + var obj = factory(); + for (var i in obj) { + exports[i] = obj[i]; + } + } + } +})(function() { +return { + +set_from_array: function (a) { var ret = {}; for (var k = 0 ; k < a.length ; ++k) { ret[a[k]] = 1; } return ret; -} +}, + +set_from_object: function(o) { + var ret = {} + for (var k in o) { + ret[k] = 1; + } + return ret; +}, -function set_diff(sa, sb) { +set_diff: function(sa, sb) { var ret = {a_b:[], b_a:[]}; var i; for (i in sa) { @@ -20,16 +47,12 @@ function set_diff(sa, sb) { } } return ret; -} +}, -function array_diff(aa, ab) { +array_diff: function(aa, ab) { var sa = set_from_array(aa); var sb = set_from_array(ab); return set_diff(sa, sb); -} +}, -if (typeof(exports) != 'undefined') { - exports.set_diff = set_diff; - exports.array_diff = array_diff; - exports.set_from_array = set_from_array; -} +}}); |
