From 44273245f86aa41d0984cad44d411f10a2cbc68c Mon Sep 17 00:00:00 2001 From: mohayonao Date: Wed, 2 Jul 2014 13:17:09 +0900 Subject: [PATCH 1/6] :sparkles: fix how to use function definition - function name() {} should be private in a module - called : YES - assigned: NO - name = function() {} - called : YES - assigned: YES --- Gruntfile.js | 80 +++++++++++++------------- demo/index.js | 32 +++++------ demo/parse.js | 4 +- src/sc/lang/fn.js | 92 +++++++++++++++--------------- src/sc/lang/iterator.js | 56 +++++++++--------- src/sc/libs/extend.js | 4 +- tools/grunt-tasks/assets/sorter.js | 8 +-- tools/grunt-tasks/build.js | 35 ++++++------ tools/grunt-tasks/mocha.js | 34 +++++------ tools/test-utils.js | 24 ++++---- 10 files changed, 185 insertions(+), 184 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 82e51cb..5a61c65 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,46 +5,6 @@ module.exports = function(grunt) { var _ = require("underscore"); - grunt._loadNpmTasksIfNeeded = function(name) { - if (!grunt._loadNpmTasksIfNeeded[name]) { - grunt._loadNpmTasksIfNeeded[name] = true; - grunt.loadNpmTasks(name); - } - }; - - grunt.file._expand = function() { - var dict = grunt.file.readJSON("tools/grunt-tasks/assets/files.json"); - var list = grunt.file.expand(_.chain(arguments).map(function(name) { - return dict[name] || name; - }).flatten().value()); - - Object.defineProperty(list, "applyFilter", { - value: function(filter) { - return applyFilter(this, filter); - } - }); - - return list; - }; - - var applyFilter = function(list, filter) { - return !filter ? list : _.chain(filter.split("+")).map(function(filter) { - return _.chain(list).filter(function(file) { - return file.indexOf(filter) !== -1; - }).value(); - }).flatten().value(); - }; - - var toTaskArgs = function(args) { - if (_.isUndefined(args)) { - return ""; - } - if (_.isArguments(args)) { - return _.map(args, toTaskArgs).join(":"); - } - return args; - }; - grunt.initConfig({ pkg: grunt.file.readJSON("package.json") }); @@ -128,4 +88,44 @@ module.exports = function(grunt) { "build", "test::nyan:lcov", "plato" ] ); + + grunt._loadNpmTasksIfNeeded = function(name) { + if (!grunt._loadNpmTasksIfNeeded[name]) { + grunt._loadNpmTasksIfNeeded[name] = true; + grunt.loadNpmTasks(name); + } + }; + + grunt.file._expand = function() { + var dict = grunt.file.readJSON("tools/grunt-tasks/assets/files.json"); + var list = grunt.file.expand(_.chain(arguments).map(function(name) { + return dict[name] || name; + }).flatten().value()); + + Object.defineProperty(list, "applyFilter", { + value: function(filter) { + return applyFilter(this, filter); + } + }); + + return list; + }; + + function applyFilter(list, filter) { + return !filter ? list : _.chain(filter.split("+")).map(function(filter) { + return _.chain(list).filter(function(file) { + return file.indexOf(filter) !== -1; + }).value(); + }).flatten().value(); + } + + function toTaskArgs(args) { + if (_.isUndefined(args)) { + return ""; + } + if (_.isArguments(args)) { + return _.map(args, toTaskArgs).join(":"); + } + return args; + } }; diff --git a/demo/index.js b/demo/index.js index 44385de..9599878 100644 --- a/demo/index.js +++ b/demo/index.js @@ -14,14 +14,14 @@ window.onload = function() { }; } - var update = function(source) { + function update(source) { if (prev !== source) { window.location.replace("#" + encodeURIComponent(source)); prev = source; } - }; + } - var getCode = function(editor) { + function getCode(editor) { var code, cursor, line, range, callback; var cssName = "blink1"; @@ -43,9 +43,9 @@ window.onload = function() { blink(cssName, ".CodeMirror-focused .CodeMirror-selected", callback); return code; - }; + } - var selectRegion = function(editor, begin) { + function selectRegion(editor, begin) { var lookAt, end, last, line; var depth, code; @@ -81,7 +81,7 @@ window.onload = function() { lookAt = end; } } - }; + } var getCssRule = (function() { var cache = {}; @@ -100,7 +100,7 @@ window.onload = function() { }; })(); - var blink = function(cssName, selector, callback) { + function blink(cssName, selector, callback) { var rule = getCssRule(selector); if (rule) { setTimeout(function() { @@ -111,9 +111,9 @@ window.onload = function() { }, 500); rule.style.setProperty("-webkit-animation", cssName + " 0.5s"); } - }; + } - var evaluate = function() { + function evaluate() { var code, result; var beginTime, elapsedTime; @@ -138,17 +138,17 @@ window.onload = function() { if (!isNaN(elapsedTime)) { $("#timecop").text(elapsedTime.toFixed(3) + "ms"); } - }; + } - var boot = function() { + function boot() { console.log("boot"); - }; + } - var stop = function() { + function stop() { console.log("stop"); - }; + } - var readFromGist = function(gistid, callback) { + function readFromGist(gistid, callback) { var url = "https://api.github.com/gists/" + gistid; $.ajax({ url: url, type: "GET", dataType: "jsonp" }).then(function(result) { var files, code; @@ -165,7 +165,7 @@ window.onload = function() { } callback(code); }); - }; + } editor = CodeMirror.fromTextArea(document.getElementById("editor"), { mode: "SCScript", diff --git a/demo/parse.js b/demo/parse.js index 9c32903..52e2f66 100644 --- a/demo/parse.js +++ b/demo/parse.js @@ -13,7 +13,7 @@ $(function() { return escodegen.generate(esprima.parse(code), { indent: " " }); } - var update = function(code, mode) { + function update(code, mode) { while (/^\([\s\S]+\)$/.test(code)) { code = code.slice(1, -1); } @@ -37,7 +37,7 @@ $(function() { } prev = [ code, mode ]; } - }; + } $("#selector a").each(function(i, elem) { $(elem).on("click", function() { diff --git a/src/sc/lang/fn.js b/src/sc/lang/fn.js index 250821e..524bad8 100644 --- a/src/sc/lang/fn.js +++ b/src/sc/lang/fn.js @@ -6,46 +6,6 @@ var slice = [].slice; var $ = sc.lang.$; - var _getDefaultValue = function(value) { - var ch; - - switch (value) { - case "nil": - return $.Nil(); - case "true": - return $.True(); - case "false": - return $.False(); - case "inf": - return $.Float(Infinity); - case "-inf": - return $.Float(-Infinity); - } - - ch = value.charAt(0); - switch (ch) { - case "$": - return $.Char(value.charAt(1)); - case "\\": - return $.Symbol(value.substr(1)); - } - - if (value.indexOf(".") !== -1) { - return $.Float(+value); - } - - return $.Integer(+value); - }; - - var getDefaultValue = function(value) { - if (value.charAt(0) === "[") { - return $.Array(value.slice(1, -2).split(",").map(function(value) { - return _getDefaultValue(value.trim()); - })); - } - return _getDefaultValue(value); - }; - var fn = function(func, def) { var argItems, argNames, argVals; var remain, wrapper; @@ -93,26 +53,66 @@ return wrapper; }; - var isDictionary = function(obj) { + function isDictionary(obj) { return !!(obj && obj.constructor === Object); - }; + } - var copy = function(args, given, length) { + function copy(args, given, length) { for (var i = 0; i < length; ++i) { if (given[i]) { args[i] = given[i]; } } - }; + } + + function _getDefaultValue(value) { + var ch; + + switch (value) { + case "nil": + return $.Nil(); + case "true": + return $.True(); + case "false": + return $.False(); + case "inf": + return $.Float(Infinity); + case "-inf": + return $.Float(-Infinity); + } + + ch = value.charAt(0); + switch (ch) { + case "$": + return $.Char(value.charAt(1)); + case "\\": + return $.Symbol(value.substr(1)); + } - var setKeywordArguments = function(args, argNames, dict) { + if (value.indexOf(".") !== -1) { + return $.Float(+value); + } + + return $.Integer(+value); + } + + function getDefaultValue(value) { + if (value.charAt(0) === "[") { + return $.Array(value.slice(1, -2).split(",").map(function(value) { + return _getDefaultValue(value.trim()); + })); + } + return _getDefaultValue(value); + } + + function setKeywordArguments(args, argNames, dict) { Object.keys(dict).forEach(function(key) { var index = argNames.indexOf(key); if (index !== -1) { args[index] = dict[key]; } }); - }; + } sc.lang.fn = fn; })(sc); diff --git a/src/sc/lang/iterator.js b/src/sc/lang/iterator.js index b93b427..b8855af 100644 --- a/src/sc/lang/iterator.js +++ b/src/sc/lang/iterator.js @@ -25,7 +25,7 @@ }; nop$iter(nop$iter); - var once$iter = function(value) { + function once$iter(value) { var iter = { hasNext: true, next: function() { @@ -37,7 +37,7 @@ } }; return iter; - }; + } iterator.execute = function(iter, $function) { $function._bytecode.setIterator(iter).run(); @@ -80,7 +80,7 @@ return iter; }; - var sc$incremental$iter = function($start, $end, $step) { + function sc$incremental$iter($start, $end, $step) { var $i = $start, j = 0, iter = { hasNext: true, next: function() { @@ -96,9 +96,9 @@ } }; return iter; - }; + } - var sc$decremental$iter = function($start, $end, $step) { + function sc$decremental$iter($start, $end, $step) { var $i = $start, j = 0, iter = { hasNext: true, next: function() { @@ -114,9 +114,9 @@ } }; return iter; - }; + } - var sc$numeric$iter = function($start, $end, $step) { + function sc$numeric$iter($start, $end, $step) { if ($start.valueOf() === $end.valueOf()) { return once$iter($start); } else if ($start < $end && $step > 0) { @@ -125,7 +125,7 @@ return sc$decremental$iter($start, $end, $step); } return nop$iter; - }; + } iterator.number$do = function($end) { var $start, $step; @@ -167,7 +167,7 @@ return sc$numeric$iter($start, $last, $step); }; - var js$incremental$iter = function(start, end, step, type) { + function js$incremental$iter(start, end, step, type) { var i = start, j = 0, iter = { hasNext: true, next: function() { @@ -183,9 +183,9 @@ } }; return iter; - }; + } - var js$decremental$iter = function(start, end, step, type) { + function js$decremental$iter(start, end, step, type) { var i = start, j = 0, iter = { hasNext: true, next: function() { @@ -201,9 +201,9 @@ } }; return iter; - }; + } - var js$numeric$iter = function(start, end, step, type) { + function js$numeric$iter(start, end, step, type) { if (start === end) { return once$iter(type(start)); } else if (start < end && step > 0) { @@ -212,43 +212,43 @@ return js$decremental$iter(start, end, step, type); } return nop$iter; - }; + } - var js$numeric$iter$do = function($endval, type) { + function js$numeric$iter$do($endval, type) { var end = type($endval.__num__()).valueOf(); return js$numeric$iter(0, end - 1, +1, type); - }; + } - var js$numeric$iter$reverseDo = function($startval, type) { + function js$numeric$iter$reverseDo($startval, type) { var start = type($startval.__num__()).valueOf(); var end = (start|0) - start; return js$numeric$iter(start - 1, end, -1, type); - }; + } - var js$numeric$iter$for = function($startval, $endval, type) { + function js$numeric$iter$for($startval, $endval, type) { var start = type($startval.__num__()).valueOf(); var end = type($endval .__num__()).valueOf(); var step = (start <= end) ? +1 : -1; return js$numeric$iter(start, end, step, type); - }; + } - var js$numeric$iter$forBy = function($startval, $endval, $stepval, type) { + function js$numeric$iter$forBy($startval, $endval, $stepval, type) { var start = type($startval.__num__()).valueOf(); var end = type($endval .__num__()).valueOf(); var step = type($stepval .__num__()).valueOf(); return js$numeric$iter(start, end, step, type); - }; + } - var js$numeric$iter$forSeries = function($startval, $second, $last, type) { + function js$numeric$iter$forSeries($startval, $second, $last, type) { var start = type($startval.__num__()).valueOf(); var second = type($second .__num__()).valueOf(); var end = type($last .__num__()).valueOf(); var step = second - start; return js$numeric$iter(start, end, step, type); - }; + } iterator.integer$do = function($endval) { return js$numeric$iter$do($endval, $.Integer); @@ -290,7 +290,7 @@ return js$numeric$iter$forSeries($startval, $second, $last, $.Float); }; - var list$iter = function(list) { + function list$iter(list) { var i = 0, iter = { hasNext: true, next: function() { @@ -305,14 +305,14 @@ } }; return iter; - }; + } - var js$array$iter = function(list) { + function js$array$iter(list) { if (list.length) { return list$iter(list); } return nop$iter; - }; + } iterator.array$do = function($array) { return js$array$iter($array._.slice()); diff --git a/src/sc/libs/extend.js b/src/sc/libs/extend.js index 575358c..d2e2e18 100644 --- a/src/sc/libs/extend.js +++ b/src/sc/libs/extend.js @@ -3,7 +3,7 @@ require("./sc"); - function extend(child, parent) { + var extend = function(child, parent) { var ctor = function() { this.constructor = child; }; @@ -12,7 +12,7 @@ child.prototype = new ctor(); /* jshint newcap: true */ return child; - } + }; sc.libs.extend = extend; })(sc); diff --git a/tools/grunt-tasks/assets/sorter.js b/tools/grunt-tasks/assets/sorter.js index 38615c4..0b4c439 100644 --- a/tools/grunt-tasks/assets/sorter.js +++ b/tools/grunt-tasks/assets/sorter.js @@ -6,13 +6,13 @@ var FILENAME = 2; var re = /^src\/sc\/(?:(.+?)\/)?(.+)\.js$/; -var order = function(dirname) { +function order(dirname) { return ORDER[dirname] || Infinity; -}; +} -var depth = function(filepath) { +function depth(filepath) { return filepath.split("/").length; -}; +} var byFilePath = function(a, b) { var cond = 0; diff --git a/tools/grunt-tasks/build.js b/tools/grunt-tasks/build.js index 53def20..10f0750 100644 --- a/tools/grunt-tasks/build.js +++ b/tools/grunt-tasks/build.js @@ -6,9 +6,6 @@ module.exports = function(grunt) { var path = require("path"); var sorter = require("./assets/sorter"); - var q = function(str) { - return "\"" + str + "\""; - }; var constVariables = {}; grunt.registerTask("build", function() { @@ -20,28 +17,32 @@ module.exports = function(grunt) { makeBrowserTest(); }); - var build = function(files) { + function q(str) { + return "\"" + str + "\""; + } + + function build(files) { return sortModules(files).map(formatter).join("").trim(); - }; + } - var buildSCScript = function() { + function buildSCScript() { var tmpl = _.template(grunt.file.read(__dirname + "/assets/scscript.tmpl")); grunt.file.write("build/scscript.js", tmpl({ version: q(grunt.config.data.pkg.version), source: build(grunt.file._expand("src", "!classlib", "!test")) })); - }; + } - var buildClassLib = function() { + function buildClassLib() { grunt.file.write("build/scscript-classlib.js", [ build(grunt.file._expand("classlib", "!test")) ].join("")); - }; + } - var sortModules = function(files) { + function sortModules(files) { var result = []; - var walker = function(filepath) { + function walker(filepath) { var index, dir, src, re, m; index = result.indexOf(filepath); @@ -57,14 +58,14 @@ module.exports = function(grunt) { while ((m = re.exec(src)) !== null) { walker(path.join(dir, m[1] + ".js")); } - }; + } _.each(files, walker); return result; - }; + } - var formatter = function(filepath) { + function formatter(filepath) { var src; src = grunt.file.read(filepath); @@ -83,9 +84,9 @@ module.exports = function(grunt) { } return src; - }; + } - var makeBrowserTest = function() { + function makeBrowserTest() { var tests, html; tests = grunt.file._expand("test").sort(sorter.byFilePath).map(function(filepath) { @@ -94,5 +95,5 @@ module.exports = function(grunt) { html = grunt.file.read("assets/index.tmpl").replace("#{TESTS}", tests.join("\n")); grunt.file.write("docs/report/test/index.html", html); - }; + } }; diff --git a/tools/grunt-tasks/mocha.js b/tools/grunt-tasks/mocha.js index 9e33e47..57167cc 100644 --- a/tools/grunt-tasks/mocha.js +++ b/tools/grunt-tasks/mocha.js @@ -21,21 +21,6 @@ module.exports = function(grunt) { chai.use(require("sinon-chai")); - var trimExtJS = function(path) { - return (/(?:src\/)?(.+?)(?:_test)?\.js$/.exec(path) || [ null, path ])[1]; - }; - - var resolveFilter = function(filter) { - var relationalTest = grunt.file.readJSON(__dirname + "/assets/relational-test.json"); - - filter = trimExtJS(filter); - if (relationalTest[filter]) { - filter = relationalTest[filter].join("+"); - } - - return filter; - }; - grunt.registerTask("-mocha", function(filter, reporter, cover) { var mocha, done, tstFiles; var matchFn, coverageVar, instrumenter; @@ -86,7 +71,7 @@ module.exports = function(grunt) { done(!failure); }); - var createCoverageReport = function(cover) { + function createCoverageReport(cover) { var collector, reports = []; collector = new istanbul.Collector(); @@ -100,6 +85,21 @@ module.exports = function(grunt) { _.each(reports, function(report) { report.writeReport(collector, true); }); - }; + } }); + + function trimExtJS(path) { + return (/(?:src\/)?(.+?)(?:_test)?\.js$/.exec(path) || [ null, path ])[1]; + } + + function resolveFilter(filter) { + var relationalTest = grunt.file.readJSON(__dirname + "/assets/relational-test.json"); + + filter = trimExtJS(filter); + if (relationalTest[filter]) { + filter = relationalTest[filter].join("+"); + } + + return filter; + } }; diff --git a/tools/test-utils.js b/tools/test-utils.js index 0b67743..aa835b6 100644 --- a/tools/test-utils.js +++ b/tools/test-utils.js @@ -33,7 +33,7 @@ }; }; - var toSCObject = function(obj, opts) { + function toSCObject(obj, opts) { var $ = sc.lang.$; if (isSCObject(obj)) { @@ -74,25 +74,25 @@ } return obj; - }; + } - var toString = function(obj) { + function toString(obj) { var str = JSON.stringify(obj) || (typeof obj); if (str.length > 2) { str = str.replace(/([{[,])/g, "$1 ").replace(/([\]}])/g, " $1"); } return str; - }; + } - var isDictionary = function(obj) { + function isDictionary(obj) { return obj && obj.constructor === Object; - }; + } - var isSCObject = function(obj) { + function isSCObject(obj) { return obj && typeof obj._ !== "undefined"; - }; + } - var typeOf = function(obj, guess) { + function typeOf(obj, guess) { var type; if (isSCObject(obj)) { @@ -116,7 +116,7 @@ type = typeof obj; return "JS" + type.charAt(0).toUpperCase() + type.slice(1); - }; + } sc.test.testCase = function(context, cases, opts) { var expect = global.expect; @@ -235,7 +235,7 @@ }; var prev = null; - var setSingletonMethod = function(instance, className, methodName) { + function setSingletonMethod(instance, className, methodName) { var method; if (prev) { @@ -250,7 +250,7 @@ prev = { instance: instance, methodName: methodName }; - }; + } sc.test.object = function(source, opts) { var instance, matches; From 3bb1fed48e01b9050062b8079ed8a06f4d13bfa7 Mon Sep 17 00:00:00 2001 From: mohayonao Date: Wed, 2 Jul 2014 15:06:02 +0900 Subject: [PATCH 2/6] :sparkles: rename assertion --- src/sc/libs/mathlib_test.js | 2 +- tools/test-utils.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sc/libs/mathlib_test.js b/src/sc/libs/mathlib_test.js index 1b3e611..b3358a4 100644 --- a/src/sc/libs/mathlib_test.js +++ b/src/sc/libs/mathlib_test.js @@ -29,7 +29,7 @@ if (isFinite(actual)) { expect(actual).withMessage(desc).to.be.closeTo(expected, opts.closeTo); } else if (isNaN(actual)) { - expect(actual).withMessage(desc).to.be.nan; + expect(actual).withMessage(desc).to.be.NaN; } else { expect(actual).withMessage(desc).to.equal(expected); } diff --git a/tools/test-utils.js b/tools/test-utils.js index aa835b6..7011792 100644 --- a/tools/test-utils.js +++ b/tools/test-utils.js @@ -457,9 +457,10 @@ ); }); - utils.addProperty(assert$proto, "nan", function() { + utils.addProperty(assert$proto, "NaN", function() { + var num = utils.flag(this, "object"); this.assert( - isNaN(utils.flag(this, "object")), + typeof num === "number" && isNaN(num), "expected #{this} to be NaN", "expected #{this} to be not NaN", this.negate ? false : true From f8e479f84a9973a6078a64ff3792b36bf8c28b64 Mon Sep 17 00:00:00 2001 From: mohayonao Date: Wed, 2 Jul 2014 15:19:26 +0900 Subject: [PATCH 3/6] :sparkles: fix to refine test functions --- src/sc/libs/mathlib_test.js | 54 +++++++++++++++++++------------------ src/sc/libs/random_test.js | 5 ++-- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/sc/libs/mathlib_test.js b/src/sc/libs/mathlib_test.js index b3358a4..5c1982f 100644 --- a/src/sc/libs/mathlib_test.js +++ b/src/sc/libs/mathlib_test.js @@ -7,37 +7,39 @@ var mathlib = sc.libs.mathlib; var strlib = sc.libs.strlib; - describe("sc.libs.mathlib", function() { - function testCase(context, cases, opts) { - var methodName = context.test.title; - opts = opts || {}; + function isInfinity(num) { + return Math.abs(num) === Infinity; + } - if (typeof opts.randSeed === "number") { - sc.libs.random.setSeed(opts.randSeed); - } + function testCase(context, cases, opts) { + opts = opts || {}; - cases.forEach(function(items) { - var expected, actual; - var desc; + var methodName = context.test.title; - expected = items.pop(); - actual = mathlib[methodName].apply(null, items); + if (typeof opts.randSeed === "number") { + sc.libs.random.setSeed(opts.randSeed); + } - desc = strlib.format("#{0}(#{1})", methodName, "" + items); + _.each(cases, function(items) { + var expected = items.pop(); + var actual = mathlib[methodName].apply(null, items); + var expects = expect( + actual, strlib.format("#{0}(#{1})", methodName, items) + ); - if (opts.closeTo) { - if (isFinite(actual)) { - expect(actual).withMessage(desc).to.be.closeTo(expected, opts.closeTo); - } else if (isNaN(actual)) { - expect(actual).withMessage(desc).to.be.NaN; - } else { - expect(actual).withMessage(desc).to.equal(expected); - } - } else { - expect(actual).withMessage(desc).to.equal(expected); - } - }); - } + if (isNaN(expected)) { + expects.to.be.NaN; + } else if (isInfinity(expected)) { + expects.to.equal(expected); + } else if (opts.closeTo) { + expects.to.be.closeTo(expected, opts.closeTo); + } else { + expects.to.equal(expected); + } + }); + } + + describe("sc.libs.mathlib", function() { it("rand", function() { testCase(this, [ [ 1.0, 0.85755145549774 ], diff --git a/src/sc/libs/random_test.js b/src/sc/libs/random_test.js index 0c50167..777a41f 100644 --- a/src/sc/libs/random_test.js +++ b/src/sc/libs/random_test.js @@ -8,7 +8,8 @@ describe("sc.libs.random", function() { it("random generator", function() { random.setSeed(0); - [ + + _.each([ 0.85755145549774, 0.07253098487854, 0.15391707420349, @@ -19,7 +20,7 @@ 0.82429480552673, 0.09632408618927, 0.93640172481537 - ].forEach(function(expected, i) { + ], function(expected, i) { expect(random.next()).withMessage("i: #{0}", i) .to.closeTo(expected, 1e-6); }); From b452abfdad475b31fd52f2da5ed9214a08350dae Mon Sep 17 00:00:00 2001 From: mohayonao Date: Thu, 3 Jul 2014 11:34:44 +0900 Subject: [PATCH 4/6] :sparkles: fix to refine test code style --- src/sc/classlib/Collections/Array_test.js | 74 ++- .../Collections/ArrayedCollection_test.js | 89 ++- .../classlib/Collections/Association_test.js | 1 - .../classlib/Collections/Collection_test.js | 287 ++++------ .../classlib/Collections/Dictionary_test.js | 88 ++- .../classlib/Collections/Environment_test.js | 20 +- src/sc/classlib/Collections/Event_test.js | 2 +- .../SequenceableCollection_test.js | 177 +++--- src/sc/classlib/Collections/Set_test.js | 60 +- src/sc/classlib/Collections/String_test.js | 65 +-- src/sc/classlib/Core/AbstractFunction_test.js | 357 +++++------- src/sc/classlib/Core/Boolean_test.js | 68 +-- src/sc/classlib/Core/Char_test.js | 34 +- src/sc/classlib/Core/Function_test.js | 166 +++--- src/sc/classlib/Core/Kernel_test.js | 22 +- src/sc/classlib/Core/Nil_test.js | 229 ++++---- src/sc/classlib/Core/Object_test.js | 521 ++++++++--------- src/sc/classlib/Core/Ref_test.js | 44 +- src/sc/classlib/Core/Symbol_test.js | 499 +++++----------- src/sc/classlib/Core/Thread_test.js | 37 +- src/sc/classlib/Math/Float_test.js | 43 +- src/sc/classlib/Math/Integer_test.js | 107 ++-- src/sc/classlib/Math/Number_test.js | 87 ++- src/sc/classlib/Math/SimpleNumber_test.js | 85 +-- src/sc/classlib/Streams/ListPatterns_test.js | 4 +- src/sc/classlib/Streams/Patterns_test.js | 537 ++++++++---------- src/sc/classlib/Streams/Stream_test.js | 199 +++---- 27 files changed, 1666 insertions(+), 2236 deletions(-) diff --git a/src/sc/classlib/Collections/Array_test.js b/src/sc/classlib/Collections/Array_test.js index 115bc8a..185d198 100644 --- a/src/sc/classlib/Collections/Array_test.js +++ b/src/sc/classlib/Collections/Array_test.js @@ -7,7 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var SCArray = $("Array"); describe("SCArray", function() { @@ -25,7 +24,9 @@ expect(test).to.be.a("JSArray").to.eql([ "freq", 440 ]); }); it(".with", function() { - var test = SCArray.with($$(0), $$(1), $$(2)); + var test; + + test = SCArray.with($$(0), $$(1), $$(2)); expect(test).to.be.a("SCArray").that.eqls([ 0, 1, 2 ]); }); it("#reverse", function() { @@ -692,63 +693,56 @@ }); it("#asUGenInput", sinon.test(function() { var instance, test; - var $elem1, $elem2, $elem3; - var $ugen1, $ugen2, $ugen3; - var $for; - $elem1 = $$({ + var $elem1 = $$({ asUGenInput: this.spy(function() { return $ugen1; }) }); - $elem2 = $$({ + var $elem2 = $$({ asUGenInput: this.spy(function() { return $ugen2; }) }); - $elem3 = $$({ + var $elem3 = $$({ asUGenInput: this.spy(function() { return $ugen3; }) }); - $ugen1 = $$(); - $ugen2 = $$(); - $ugen3 = $$(); - $for = $$(); + var $ugen1 = $$(); + var $ugen2 = $$(); + var $ugen3 = $$(); + var $for = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); test = instance.asUGenInput($for); - expect($elem1.asUGenInput).to.be.calledWith($for); - expect($elem2.asUGenInput).to.be.calledWith($for); - expect($elem3.asUGenInput).to.be.calledWith($for); + expect($elem1.asUGenInput, 1).to.be.calledWith($for); + expect($elem2.asUGenInput, 2).to.be.calledWith($for); + expect($elem3.asUGenInput, 3).to.be.calledWith($for); expect(test).to.be.a("SCArray").that.eqls([ $ugen1, $ugen2, $ugen3 ]); })); it("#asAudioRateInput", sinon.test(function() { var instance, test; - var $elem1, $elem2, $elem3; - var $ugen1, $ugen2, $ugen3; - var $for; - - $elem1 = $$({ + var $elem1 = $$({ asAudioRateInput: this.spy(function() { return $ugen1; }) }); - $elem2 = $$({ + var $elem2 = $$({ asAudioRateInput: this.spy(function() { return $ugen2; }) }); - $elem3 = $$({ + var $elem3 = $$({ asAudioRateInput: this.spy(function() { return $ugen3; }) }); - $ugen1 = $$(); - $ugen2 = $$(); - $ugen3 = $$(); - $for = $$(); + var $ugen1 = $$(); + var $ugen2 = $$(); + var $ugen3 = $$(); + var $for = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); @@ -760,27 +754,24 @@ })); it("#asControlInput", sinon.test(function() { var instance, test; - var $elem1, $elem2, $elem3; - var $ugen1, $ugen2, $ugen3; - - $elem1 = $$({ + var $elem1 = $$({ asControlInput: this.spy(function() { return $ugen1; }) }); - $elem2 = $$({ + var $elem2 = $$({ asControlInput: this.spy(function() { return $ugen2; }) }); - $elem3 = $$({ + var $elem3 = $$({ asControlInput: this.spy(function() { return $ugen3; }) }); - $ugen1 = $$(); - $ugen2 = $$(); - $ugen3 = $$(); + var $ugen1 = $$(); + var $ugen2 = $$(); + var $ugen3 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); @@ -794,6 +785,7 @@ var instance, test; instance = this.createInstance(); + test = instance.isValidUGenInput(); expect(test).to.be.a("SCBoolean").that.equals(true); }); @@ -821,19 +813,17 @@ it.skip("#fork", function() { }); it("#madd", sinon.test(function() { - var instance, test, spy; - var $mul, $add; + var instance, test; + var spy = this.spy(sc.test.func()); + var $mul = $$(); + var $add = $$(); - spy = this.spy(sc.test.func()); - $mul = $$(); - $add = $$(); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("MulAdd").returns($$({ new: spy })); - instance = this.createInstance(); test = instance.madd($mul, $add); - expect(spy).to.be.calledWith(instance, $mul, $add); expect(spy).to.be.calledLastIn(test); })); diff --git a/src/sc/classlib/Collections/ArrayedCollection_test.js b/src/sc/classlib/Collections/ArrayedCollection_test.js index 510c565..94e75fb 100644 --- a/src/sc/classlib/Collections/ArrayedCollection_test.js +++ b/src/sc/classlib/Collections/ArrayedCollection_test.js @@ -7,8 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var iterator = sc.lang.iterator; - var SCInt8Array = $("Int8Array"); var SCInt16Array = $("Int16Array"); var SCInt32Array = $("Int32Array"); @@ -25,9 +23,7 @@ }); it("#__elem__", function() { var instance, test; - var $obj; - - $obj = $$(); + var $obj = $$(); instance = this.createInstance(); @@ -35,7 +31,9 @@ expect(test).to.equal($obj); }); it(".newClear", function() { - var test = SCArray.newClear($$(4)); + var test; + + test = SCArray.newClear($$(4)); expect(test).to.be.a("SCArray").that.eqls([ null, null, null, null ]); }); it.skip("#indexedSize", function() { @@ -520,14 +518,11 @@ expect(instance.copy).to.be.calledLastIn(test); })); it("#setSlots", sinon.test(function() { - var instance, test, spy; - var $array; - - spy = this.spy(sc.test.func()); - $array = $$(); + var instance, test; + var $array = $$(); instance = this.createInstance([ 1, 2, 3 ]); - instance.overWrite = spy; + instance.overWrite = this.spy(sc.test.func()); test = instance.setSlots($array); expect(instance.overWrite).to.be.calledWith($array); @@ -598,7 +593,9 @@ expect(test).to.be.a("SCBoolean").that.is.true; }); it("#asArray", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asArray).to.doNothing; }); it("#copyRange", function() { @@ -976,39 +973,35 @@ ]); }); it("#do", sinon.test(function() { - var test, instance, iter; - var $function; + var test, instance; + var iter = {}; + var $function = $$(); - iter = {}; - $function = $$(); - this.stub(iterator, "array$do", function() { + instance = this.createInstance(); + this.stub(sc.lang.iterator, "array$do", function() { return iter; }); - this.stub(iterator, "execute"); - - instance = this.createInstance(); + this.stub(sc.lang.iterator, "execute"); test = instance.do($function); - expect(iterator.array$do).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.array$do).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#reverseDo", sinon.test(function() { - var test, instance, iter; - var $function; + var test, instance; + var iter = {}; + var $function = $$(); - iter = {}; - $function = $$(); - this.stub(iterator, "array$reverseDo", function() { + instance = this.createInstance(); + this.stub(sc.lang.iterator, "array$reverseDo", function() { return iter; }); - this.stub(iterator, "execute"); - - instance = this.createInstance(); + this.stub(sc.lang.iterator, "execute"); test = instance.reverseDo($function); - expect(iterator.array$reverseDo).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.array$reverseDo).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#reverse", function() { @@ -1294,12 +1287,12 @@ describe("SCInt8Array", function() { it("#valueOf", function() { - var instance, test, expected; + var instance, test; + var expected = new Int8Array([ 0, -1, 0 ]); instance = SCInt8Array.newFrom($$([ 0, 255, 256 ])); - test = instance.valueOf(); - expected = new Int8Array([ 0, -1, 0 ]); + test = instance.valueOf(); expect(test).to.eql(expected); }); it(".newClear", function() { @@ -1312,12 +1305,12 @@ describe("SCInt16Array", function() { it("#valueOf", function() { - var instance, test, expected; + var instance, test; + var expected = new Int16Array([ 0, -1, 0 ]); instance = SCInt16Array.newFrom($$([ 0, 65535, 65536 ])); - test = instance.valueOf(); - expected = new Int16Array([ 0, -1, 0 ]); + test = instance.valueOf(); expect(test).to.eql(expected); }); it(".newClear", function() { @@ -1330,12 +1323,12 @@ describe("SCInt32Array", function() { it("#valueOf", function() { - var instance, test, expected; + var instance, test; + var expected = new Int32Array([ 0, -1, 0 ]); instance = SCInt32Array.newFrom($$([ 0, 4294967295, 4294967296 ])); - test = instance.valueOf(); - expected = new Int32Array([ 0, -1, 0 ]); + test = instance.valueOf(); expect(test).to.eql(expected); }); it(".newClear", function() { @@ -1348,12 +1341,12 @@ describe("SCFloatArray", function() { it("#valueOf", function() { - var instance, test, expected; + var instance, test; + var expected = new Float32Array([ 0, 0.5, -0.5 ]); instance = SCFloatArray.newFrom($$([ 0, 0.5, -0.5 ])); - test = instance.valueOf(); - expected = new Float32Array([ 0, 0.5, -0.5 ]); + test = instance.valueOf(); expect(test).to.eql(expected); }); it(".newClear", function() { @@ -1366,12 +1359,12 @@ describe("SCDoubleArray", function() { it("#valueOf", function() { - var instance, test, expected; + var instance, test; + var expected = new Float64Array([ 0, 0.5, -0.5 ]); instance = SCDoubleArray.newFrom($$([ 0, 0.5, -0.5 ])); - test = instance.valueOf(); - expected = new Float64Array([ 0, 0.5, -0.5 ]); + test = instance.valueOf(); expect(test).to.eql(expected); }); it(".newClear", function() { diff --git a/src/sc/classlib/Collections/Association_test.js b/src/sc/classlib/Collections/Association_test.js index c96f327..809342c 100644 --- a/src/sc/classlib/Collections/Association_test.js +++ b/src/sc/classlib/Collections/Association_test.js @@ -6,7 +6,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var SCAssociation = $("Association"); describe("SCAssociation", function() { diff --git a/src/sc/classlib/Collections/Collection_test.js b/src/sc/classlib/Collections/Collection_test.js index c287c34..6b42d2a 100644 --- a/src/sc/classlib/Collections/Collection_test.js +++ b/src/sc/classlib/Collections/Collection_test.js @@ -7,21 +7,18 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var SCCollection = $("Collection"); var SCArray = $("Array"); describe("SCCollection", function() { - var $int3, $int10, $int100; + var $int3 = $$(3); + var $int10 = $$(10); + var $int100 = $$(100); before(function() { this.createInstance = function(source, immutable) { var instance = $.Array((source||[]).map($$), !!immutable); return $$(instance, "Collection" + this.test.title); }; - - $int3 = $$(3); - $int10 = $$(10); - $int100 = $$(100); }); it("#valueOf", function() { var instance, test; @@ -33,20 +30,16 @@ }); it(".newFrom", function() { var test; - var $aCollection; - - $aCollection = $$([ 1, 2, 3, 4, 5 ]); + var $aCollection = $$([ 1, 2, 3, 4, 5 ]); test = SCCollection.newFrom.call(SCArray, $aCollection); expect(test).to.be.a("SCArray").that.eqls([ 1, 2, 3, 4, 5 ]); }); it(".with", function() { var test; - var $arg1, $arg2, $arg3; - - $arg1 = $$(); - $arg2 = $$(); - $arg3 = $$(); + var $arg1 = $$(); + var $arg2 = $$(); + var $arg3 = $$(); test = SCCollection.with.call(SCArray, $arg1, $arg2, $arg3); expect(test).to.be.a("SCArray").that.eqls([ $arg1, $arg2, $arg3 ]); @@ -98,9 +91,7 @@ }); it("#@", sinon.test(function() { var instance, test; - var $index; - - $index = $$(); + var $index = $$(); instance = this.createInstance(); this.stub(instance, "at", sc.test.func()); @@ -149,7 +140,9 @@ expect(test).to.equal(SCArray); }); it("#do", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.do.__errorType).to.equal("subclassResponsibility"); }); it.skip("#iter", function() { @@ -207,7 +200,9 @@ ]); }); it("#asCollection", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asCollection).to.doNothing; }); it("#isCollection", function() { @@ -219,7 +214,9 @@ expect(test).to.be.a("SCBoolean").that.is.true; }); it("#add", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.add.__errorType).to.equal("subclassResponsibility"); }); it("#addAll", function() { @@ -233,7 +230,9 @@ ]); }); it("#remove", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.remove.__errorType).to.equal("subclassResponsibility"); }); it("#removeAll", function() { @@ -365,9 +364,7 @@ }); it("#matchItem", sinon.test(function() { var instance, test; - var $item; - - $item = $$(); + var $item = $$(); instance = this.createInstance(); this.stub(instance, "includes", sc.test.func()); @@ -378,9 +375,7 @@ })); it("#collect", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); this.stub(instance, "collectAs", sc.test.func()); @@ -391,9 +386,7 @@ })); it("#select", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); this.stub(instance, "selectAs", sc.test.func()); @@ -404,9 +397,7 @@ })); it("#reject", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); this.stub(instance, "rejectAs", sc.test.func()); @@ -417,9 +408,7 @@ })); it("#collectAs", function() { var instance, test; - var $function; - - $function = $$(function($elem, $i) { + var $function = $$(function($elem, $i) { return $elem ["/"] ($$(10)) ["+"] ($i); }); @@ -430,9 +419,7 @@ }); it("#selectAs", function() { var instance, test; - var $function; - - $function = $$(function($elem, $i) { + var $function = $$(function($elem, $i) { return $$(($elem ["%"] ($i)) === $$(0)); }); @@ -443,9 +430,7 @@ }); it("#rejectAs", function() { var instance, test; - var $function; - - $function = $$(function($elem, $i) { + var $function = $$(function($elem, $i) { return $$(($elem ["%"] ($i)) === $$(0)); }); @@ -492,15 +477,12 @@ }); it("#doMsg", sinon.test(function() { var instance, test; - var $elem1, $elem2, $elem3; - var $selector, $arg1, $arg2; - - $elem1 = $$({ perform: this.spy() }); - $elem2 = $$({ perform: this.spy() }); - $elem3 = $$({ perform: this.spy() }); - $selector = $$(); - $arg1 = $$(); - $arg2 = $$(); + var $elem1 = $$({ perform: this.spy() }); + var $elem2 = $$({ perform: this.spy() }); + var $elem3 = $$({ perform: this.spy() }); + var $selector = $$(); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); @@ -511,122 +493,107 @@ expect(test).to.equal(instance); })); it("#collectMsg", sinon.test(function() { - var instance, test, spy1, spy2, spy3; - var $elem1, $elem2, $elem3; - var $selector, $arg1, $arg2; - - $elem1 = $$(1); - $elem2 = $$(2); - $elem3 = $$(3); - spy1 = this.spy($elem1, "odd"); - spy2 = this.spy($elem2, "odd"); - spy3 = this.spy($elem3, "odd"); - $selector = $$("\\odd"); - $arg1 = $$(); - $arg2 = $$(); + var instance, test; + var $elem1 = $$(1); + var $elem2 = $$(2); + var $elem3 = $$(3); + var $selector = $$("\\odd"); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); + this.spy($elem1, "odd"); + this.spy($elem2, "odd"); + this.spy($elem3, "odd"); test = instance.collectMsg($selector, $arg1, $arg2); - expect(spy1).to.be.calledWith($arg1, $arg2); - expect(spy2).to.be.calledWith($arg1, $arg2); - expect(spy3).to.be.calledWith($arg1, $arg2); + expect($elem1.odd).to.be.calledWith($arg1, $arg2); + expect($elem2.odd).to.be.calledWith($arg1, $arg2); + expect($elem3.odd).to.be.calledWith($arg1, $arg2); expect(test).to.be.a("SCArray").that.eqls([ true, false, true ]); })); it("#selectMsg", sinon.test(function() { - var instance, test, spy1, spy2, spy3; - var $elem1, $elem2, $elem3; - var $selector, $arg1, $arg2; - - $elem1 = $$(1); - $elem2 = $$(2); - $elem3 = $$(3); - spy1 = this.spy($elem1, "odd"); - spy2 = this.spy($elem2, "odd"); - spy3 = this.spy($elem3, "odd"); - $selector = $$("\\odd"); - $arg1 = $$(); - $arg2 = $$(); + var instance, test; + var $elem1 = $$(1); + var $elem2 = $$(2); + var $elem3 = $$(3); + var $selector = $$("\\odd"); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); + this.spy($elem1, "odd"); + this.spy($elem2, "odd"); + this.spy($elem3, "odd"); test = instance.selectMsg($selector, $arg1, $arg2); - expect(spy1).to.be.calledWith($arg1, $arg2); - expect(spy2).to.be.calledWith($arg1, $arg2); - expect(spy3).to.be.calledWith($arg1, $arg2); + expect($elem1.odd).to.be.calledWith($arg1, $arg2); + expect($elem2.odd).to.be.calledWith($arg1, $arg2); + expect($elem3.odd).to.be.calledWith($arg1, $arg2); expect(test).to.be.a("SCArray").that.eqls([ 1, 3 ]); })); it("#rejectMsg", sinon.test(function() { - var instance, test, spy1, spy2, spy3; - var $elem1, $elem2, $elem3; - var $selector, $arg1, $arg2; - - $elem1 = $$(1); - $elem2 = $$(2); - $elem3 = $$(3); - spy1 = this.spy($elem1, "odd"); - spy2 = this.spy($elem2, "odd"); - spy3 = this.spy($elem3, "odd"); - $selector = $$("\\odd"); - $arg1 = $$(); - $arg2 = $$(); + var instance, test; + var $elem1 = $$(1); + var $elem2 = $$(2); + var $elem3 = $$(3); + var $selector = $$("\\odd"); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3 ]); + this.spy($elem1, "odd"); + this.spy($elem2, "odd"); + this.spy($elem3, "odd"); test = instance.rejectMsg($selector, $arg1, $arg2); - expect(spy1).to.be.calledWith($arg1, $arg2); - expect(spy2).to.be.calledWith($arg1, $arg2); - expect(spy3).to.be.calledWith($arg1, $arg2); + expect($elem1.odd).to.be.calledWith($arg1, $arg2); + expect($elem2.odd).to.be.calledWith($arg1, $arg2); + expect($elem3.odd).to.be.calledWith($arg1, $arg2); expect(test).to.be.a("SCArray").that.eqls([ 2 ]); })); it("#detectMsg", sinon.test(function() { - var instance, test, spy1, spy2, spy3; - var $elem1, $elem2, $elem3, $elem4, $elem5; - var $selector, $arg1, $arg2; - - $elem1 = $$(-2); - $elem2 = $$(-1); - $elem3 = $$( 0); - $elem4 = $$( 1); - $elem5 = $$( 2); - spy1 = this.spy($elem1, "isPositive"); - spy2 = this.spy($elem2, "isPositive"); - spy3 = this.spy($elem3, "isPositive"); - $selector = $$("\\isPositive"); - $arg1 = $$(); - $arg2 = $$(); + var instance, test; + var $elem1 = $$(-2); + var $elem2 = $$(-1); + var $elem3 = $$( 0); + var $elem4 = $$( 1); + var $elem5 = $$( 2); + var $selector = $$("\\isPositive"); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3, $elem4, $elem5 ]); + this.spy($elem1, "isPositive"); + this.spy($elem2, "isPositive"); + this.spy($elem3, "isPositive"); test = instance.detectMsg($selector, $arg1, $arg2); - expect(spy1).to.be.calledWith($arg1, $arg2); - expect(spy2).to.be.calledWith($arg1, $arg2); - expect(spy3).to.be.calledWith($arg1, $arg2); + expect($elem1.isPositive).to.be.calledWith($arg1, $arg2); + expect($elem2.isPositive).to.be.calledWith($arg1, $arg2); + expect($elem3.isPositive).to.be.calledWith($arg1, $arg2); expect(test).to.be.a("SCInteger").that.equals(0); })); it("#detectIndexMsg", sinon.test(function() { - var instance, test, spy1, spy2, spy3; - var $elem1, $elem2, $elem3, $elem4, $elem5; - var $selector, $arg1, $arg2; - - $elem1 = $$(-2); - $elem2 = $$(-1); - $elem3 = $$( 0); - $elem4 = $$( 1); - $elem5 = $$( 2); - spy1 = this.spy($elem1, "isPositive"); - spy2 = this.spy($elem2, "isPositive"); - spy3 = this.spy($elem3, "isPositive"); - $selector = $$("\\isPositive"); - $arg1 = $$(); - $arg2 = $$(); + var instance, test; + var $elem1 = $$(-2); + var $elem2 = $$(-1); + var $elem3 = $$( 0); + var $elem4 = $$( 1); + var $elem5 = $$( 2); + var $selector = $$("\\isPositive"); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance([ $elem1, $elem2, $elem3, $elem4, $elem5 ]); + this.spy($elem1, "isPositive"); + this.spy($elem2, "isPositive"); + this.spy($elem3, "isPositive"); test = instance.detectIndexMsg($selector, $arg1, $arg2); - expect(spy1).to.be.calledWith($arg1, $arg2); - expect(spy2).to.be.calledWith($arg1, $arg2); - expect(spy3).to.be.calledWith($arg1, $arg2); + expect($elem1.isPositive).to.be.calledWith($arg1, $arg2); + expect($elem2.isPositive).to.be.calledWith($arg1, $arg2); + expect($elem3.isPositive).to.be.calledWith($arg1, $arg2); expect(test).to.be.a("SCInteger").that.equals(2); })); it("#lastForWhich", function() { @@ -1071,15 +1038,13 @@ }); it("#asArray", sinon.test(function() { var instance, test; - var $new, $addAll; - - $new = this.spy(function() { + var $new = this.spy(function() { return $$({ addAll: $addAll }); }); - $addAll = this.spy(sc.test.func()); - this.stub(SCArray, "new", $new); + var $addAll = this.spy(sc.test.func()); instance = this.createInstance([ 1, 2, 3 ]); + this.stub(SCArray, "new", $new); test = instance.asArray(); expect($new.args[0]).to.eql($$([ 3 ])._); @@ -1088,18 +1053,16 @@ })); it("#asBag", sinon.test(function() { var instance, test; - var $new, $addAll; - - $new = this.spy(function() { + var $new = this.spy(function() { return $$({ addAll: $addAll }); }); - $addAll = this.spy(sc.test.func()); + var $addAll = this.spy(sc.test.func()); + + instance = this.createInstance([ 1, 2, 3 ]); this.stub(sc.lang.klass, "get").withArgs("Bag").returns($$({ new: $new })); - instance = this.createInstance([ 1, 2, 3 ]); - test = instance.asBag(); expect($new.args[0]).to.eql($$([ 3 ])._); expect($addAll).to.be.calledWith(instance); @@ -1107,18 +1070,16 @@ })); it("#asList", sinon.test(function() { var instance, test; - var $new, $addAll; - - $new = this.spy(function() { + var $new = this.spy(function() { return $$({ addAll: $addAll }); }); - $addAll = this.spy(sc.test.func()); + var $addAll = this.spy(sc.test.func()); + + instance = this.createInstance([ 1, 2, 3 ]); this.stub(sc.lang.klass, "get").withArgs("List").returns($$({ new: $new })); - instance = this.createInstance([ 1, 2, 3 ]); - test = instance.asList(); expect($new.args[0]).to.eql($$([ 3 ])._); expect($addAll).to.be.calledWith(instance); @@ -1126,18 +1087,16 @@ })); it("#asSet", sinon.test(function() { var instance, test; - var $new, $addAll; - - $new = this.spy(function() { + var $new = this.spy(function() { return $$({ addAll: $addAll }); }); - $addAll = this.spy(sc.test.func()); + var $addAll = this.spy(sc.test.func()); + + instance = this.createInstance([ 1, 2, 3 ]); this.stub(sc.lang.klass, "get").withArgs("Set").returns($$({ new: $new })); - instance = this.createInstance([ 1, 2, 3 ]); - test = instance.asSet(); expect($new.args[0]).to.eql($$([ 3 ])._); expect($addAll).to.be.calledWith(instance); @@ -1145,19 +1104,17 @@ })); it("#asSortedList", sinon.test(function() { var instance, test; - var $new, $addAll, $function; - - $new = this.spy(function() { + var $new = this.spy(function() { return $$({ addAll: $addAll }); }); - $addAll = this.spy(sc.test.func()); - $function = $$(); + var $addAll = this.spy(sc.test.func()); + var $function = $$(); + + instance = this.createInstance([ 1, 2, 3 ]); this.stub(sc.lang.klass, "get").withArgs("SortedList").returns($$({ new: $new })); - instance = this.createInstance([ 1, 2, 3 ]); - test = instance.asSortedList($function); expect($new.args[0]).to.eql($$([ 3, $function ])._); expect($addAll).to.be.calledWith(instance); diff --git a/src/sc/classlib/Collections/Dictionary_test.js b/src/sc/classlib/Collections/Dictionary_test.js index 48ef192..c8f187c 100644 --- a/src/sc/classlib/Collections/Dictionary_test.js +++ b/src/sc/classlib/Collections/Dictionary_test.js @@ -7,7 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var SCDictionary = $("Dictionary"); var SCIdentityDictionary = $("IdentityDictionary"); var SCSet = $("Set"); @@ -24,6 +23,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.be.a("JSObject").that.eqls({}); }); @@ -280,18 +280,16 @@ }); it("#keysValuesDo", sinon.test(function() { var instance, test; - var spy, $function; - - spy = this.spy(); - $function = $$(spy); + var func = this.spy(); + var $function = $$(func); instance = this.createInstance([ 1, 2, 3, 4 ]); test = instance.keysValuesDo($function); expect(test).to.equal(instance); - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ 1, 2, 0 ])._); - expect(spy.args[1]).to.eql($$([ 3, 4, 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ 1, 2, 0 ])._); + expect(func.args[1]).to.eql($$([ 3, 4, 1 ])._); })); it("#keysValuesChange", function() { testCase(this, [ @@ -307,67 +305,55 @@ }); it("#do", sinon.test(function() { var instance, test; - var spy, $function; - - spy = this.spy(); - $function = $$(spy); + var func = this.spy(); + var $function = $$(func); instance = this.createInstance([ 1, 2, 3, 4 ]); test = instance.do($function); expect(test).to.equal(instance); - - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ 2, 0 ])._); - expect(spy.args[1]).to.eql($$([ 4, 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ 2, 0 ])._); + expect(func.args[1]).to.eql($$([ 4, 1 ])._); })); it("#keysDo", sinon.test(function() { var instance, test; - var spy, $function; - - spy = this.spy(); - $function = $$(spy); + var func = this.spy(); + var $function = $$(func); instance = this.createInstance([ 1, 2, 3, 4 ]); test = instance.keysDo($function); expect(test).to.equal(instance); - - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ 1, 0 ])._); - expect(spy.args[1]).to.eql($$([ 3, 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ 1, 0 ])._); + expect(func.args[1]).to.eql($$([ 3, 1 ])._); })); it("#associationsDo", sinon.test(function() { var instance, test; - var spy, $function; - - spy = this.spy(); - $function = $$(spy); + var func = this.spy(); + var $function = $$(func); instance = this.createInstance([ 1, 2, 3, 4 ]); test = instance.associationsDo($function); expect(test).to.equal(instance); - - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ SCAssociation.new($$(1), $$(2)), 0 ])._); - expect(spy.args[1]).to.eql($$([ SCAssociation.new($$(3), $$(4)), 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ SCAssociation.new($$(1), $$(2)), 0 ])._); + expect(func.args[1]).to.eql($$([ SCAssociation.new($$(3), $$(4)), 1 ])._); })); it("#pairsDo", sinon.test(function() { var instance, test; - var spy, $function; - - spy = this.spy(); - $function = $$(spy); + var func = this.spy(); + var $function = $$(func); instance = this.createInstance([ 1, 2, 3, 4 ]); test = instance.pairsDo($function); expect(test).to.equal(instance); - - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ 1, 2, 0 ])._); - expect(spy.args[1]).to.eql($$([ 3, 4, 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ 1, 2, 0 ])._); + expect(func.args[1]).to.eql($$([ 3, 4, 1 ])._); })); it("#collect", function() { testCase(this, [ @@ -468,11 +454,9 @@ }); it("#sortedKeysValuesDo", sinon.test(function() { var instance, test; - var spy, $function, $sortFunc; - - spy = this.spy(); - $function = $$(spy); - $sortFunc = $$(function($a, $b) { + var func = this.spy(); + var $function = $$(func); + var $sortFunc = $$(function($a, $b) { return $b ["<="] ($a); }); @@ -480,10 +464,9 @@ test = instance.sortedKeysValuesDo($function, $sortFunc); expect(test).to.equal(instance); - - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ 3, 4, 0 ])._); - expect(spy.args[1]).to.eql($$([ 1, 2, 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ 3, 4, 0 ])._); + expect(func.args[1]).to.eql($$([ 1, 2, 1 ])._); })); it("#choose", function() { testCase(this, [ @@ -531,15 +514,13 @@ }); it("#transformEvent", sinon.test(function() { var instance, test; - var $event; - - $event = $$({ + var $event = $$({ putAll: this.spy(sc.test.func()) }); instance = this.createInstance(); - test = instance.transformEvent($event); + test = instance.transformEvent($event); expect($event.putAll).to.be.calledWith(instance); expect($event.putAll).to.be.calledLastIn(test); })); @@ -565,6 +546,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.be.a("JSObject").that.eqls({}); }); diff --git a/src/sc/classlib/Collections/Environment_test.js b/src/sc/classlib/Collections/Environment_test.js index 4c8d9e1..27e13de 100644 --- a/src/sc/classlib/Collections/Environment_test.js +++ b/src/sc/classlib/Collections/Environment_test.js @@ -6,7 +6,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var SCEnvironment = $("Environment"); describe("SCEnvironment", function() { @@ -19,6 +18,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.be.a("JSObject").that.eqls({}); }); @@ -26,16 +26,16 @@ var instance, test; instance = this.createInstance([ 1, 2, 3, 4 ]); - test = instance.eventAt($$(1)); + test = instance.eventAt($$(1)); expect(test).to.be.a("SCInteger").equals(2); }); it("#composeEvents", function() { var instance, test; instance = this.createInstance(); - test = instance.composeEvents($$([ 1, 2, 3, 4 ])); + test = instance.composeEvents($$([ 1, 2, 3, 4 ])); expect(test).to.not.equal(instance); expect(test).to.be.a("SCEnvironment").that.eqls({ 1: 2, 3: 4 }); }); @@ -63,14 +63,13 @@ })); it("make", sc.test(function() { var test; - var $function; - - $.Environment("a", $$(1)); - $function = $$(function() { + var $function = $$(function() { $.Environment("a", $$(100)); return $.Environment("a").neg(); }); + $.Environment("a", $$(1)); + test = SCEnvironment.make($function); expect(test).to.be.a("SCEnvironment").that.eqls({ a: 100 }); @@ -79,14 +78,13 @@ })); it("use", sc.test(function() { var test; - var $function; - - $.Environment("a", $$(1)); - $function = $$(function() { + var $function = $$(function() { $.Environment("a", $$(100)); return $.Environment("a").neg(); }); + $.Environment("a", $$(1)); + test = SCEnvironment.use($function); expect(test).to.be.a("SCInteger").that.equals(-100); diff --git a/src/sc/classlib/Collections/Event_test.js b/src/sc/classlib/Collections/Event_test.js index d187e8b..2e5debe 100644 --- a/src/sc/classlib/Collections/Event_test.js +++ b/src/sc/classlib/Collections/Event_test.js @@ -6,7 +6,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var SCEvent = $("Event"); describe("SCEvent", function() { @@ -19,6 +18,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.be.a("JSObject").that.eqls({}); }); diff --git a/src/sc/classlib/Collections/SequenceableCollection_test.js b/src/sc/classlib/Collections/SequenceableCollection_test.js index 167eeac..ff8e1af 100644 --- a/src/sc/classlib/Collections/SequenceableCollection_test.js +++ b/src/sc/classlib/Collections/SequenceableCollection_test.js @@ -7,7 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var SCSequenceableCollection = $("SequenceableCollection"); var SCArray = $("Array"); @@ -28,9 +27,7 @@ }); it("#|@|", sinon.test(function() { var instance, test; - var $index; - - $index = $$(); + var $index = $$(); instance = this.createInstance(); this.stub(instance, "clipAt", sc.test.func()); @@ -41,9 +38,7 @@ })); it("#@@", sinon.test(function() { var instance, test; - var $index; - - $index = $$(); + var $index = $$(); instance = this.createInstance(); this.stub(instance, "wrapAt", sc.test.func()); @@ -54,9 +49,7 @@ })); it("#@|@", sinon.test(function() { var instance, test; - var $index; - - $index = $$(); + var $index = $$(); instance = this.createInstance(); this.stub(instance, "foldAt", sc.test.func()); @@ -66,7 +59,9 @@ expect(instance.foldAt).to.be.calledLastIn(test); })); it(".series", function() { - var test = SCSequenceableCollection.series.call( + var test; + + test = SCSequenceableCollection.series.call( SCArray, $$(6), $$(2), $$(4) ); expect(test).to.be.a("SCArray").to.eql([ @@ -74,7 +69,9 @@ ]); }); it(".geom", function() { - var test = SCSequenceableCollection.geom.call( + var test; + + test = SCSequenceableCollection.geom.call( SCArray, $$(6), $$(2), $$(4) ); expect(test).to.be.a("SCArray").to.eql([ @@ -82,7 +79,9 @@ ]); }); it(".fib", function() { - var test = SCSequenceableCollection.fib.call( + var test; + + test = SCSequenceableCollection.fib.call( SCArray, $$(6) ); expect(test).to.be.a("SCArray").to.eql([ @@ -90,8 +89,11 @@ ]); }); it(".rand", function() { + var test; + sc.libs.random.setSeed(0); - var test = SCSequenceableCollection.rand.call( + + test = SCSequenceableCollection.rand.call( SCArray, $$(5), $.Float(0.0), $.Float(1.0) ); expect(test).to.be.a("SCArray").to.closeTo([ @@ -103,8 +105,11 @@ ], 1e-6); }); it(".exprand", function() { + var test; + sc.libs.random.setSeed(0); - var test = SCSequenceableCollection.exprand.call( + + test = SCSequenceableCollection.exprand.call( SCArray, $$(5), $$(0.01), $$(1) ); expect(test).to.be.a("SCArray").to.closeTo([ @@ -116,8 +121,11 @@ ], 1e-6); }); it(".rand2", function() { + var test; + sc.libs.random.setSeed(0); - var test = SCSequenceableCollection.rand2.call( + + test = SCSequenceableCollection.rand2.call( SCArray, $$(5), $.Float(1.0) ); expect(test).to.be.a("SCArray").to.closeTo([ @@ -129,8 +137,11 @@ ], 1e-6); }); it(".linrand", function() { + var test; + sc.libs.random.setSeed(0); - var test = SCSequenceableCollection.linrand.call( + + test = SCSequenceableCollection.linrand.call( SCArray, $$(5), $.Float(0.0), $.Float(1.0) ); expect(test).to.be.a("SCArray").to.closeTo([ @@ -168,7 +179,9 @@ it.skip("#+++", function() { }); it("#asSequenceableCollection", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asSequenceableCollection).to.doNothing; }); it("#choose", function() { @@ -627,9 +640,7 @@ }); it("#pairsDo", sinon.test(function() { var instance, test; - var $function; - - $function = $$({ value: this.spy() }); + var $function = $$({ value: this.spy() }); instance = this.createInstance([ 10, 20, 30, 40 ]); @@ -641,9 +652,7 @@ })); it("#keysValuesDo", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance([ 10, 20, 30, 40 ]); this.stub(instance, "pairsDo", sc.test.func()); @@ -654,11 +663,7 @@ })); it("#doAdjacentPairs", sinon.test(function() { var instance, test; - var $function; - - $function = $$({ - value: this.spy() - }); + var $function = $$({ value: this.spy() }); instance = this.createInstance([ 10, 20, 30, 40 ]); @@ -727,10 +732,9 @@ ]); }); it("#curdle", function() { - var test, instance, i = 0; - var $probability; - - $probability = $$({ + var test, instance; + var i = 0; + var $probability = $$({ coin: function() { return $$(i++ === 2); } @@ -941,16 +945,15 @@ }); it("#degreeToKey", sinon.test(function() { var instance, test; - var $scale, $stepsPerOctave, $item1, $item2; - - $scale = $$(); - $stepsPerOctave = $$(); - $item1 = sc.test.object({ degreeToKey: this.spy(function() { + var $scale = $$(); + var $stepsPerOctave = $$(); + var $item1 = sc.test.object({ degreeToKey: this.spy(function() { return $item1; }) }); - $item2 = sc.test.object({ degreeToKey: this.spy(function() { + var $item2 = sc.test.object({ degreeToKey: this.spy(function() { return $item2; }) }); + instance = this.createInstance([ $item1, $item2 ]); test = instance.degreeToKey($scale, $stepsPerOctave); @@ -960,16 +963,15 @@ })); it("#keyToDegree", sinon.test(function() { var instance, test; - var $scale, $stepsPerOctave, $item1, $item2; - - $scale = $$(); - $stepsPerOctave = $$(); - $item1 = sc.test.object({ keyToDegree: this.spy(function() { + var $scale = $$(); + var $stepsPerOctave = $$(); + var $item1 = sc.test.object({ keyToDegree: this.spy(function() { return $item1; }) }); - $item2 = sc.test.object({ keyToDegree: this.spy(function() { + var $item2 = sc.test.object({ keyToDegree: this.spy(function() { return $item2; }) }); + instance = this.createInstance([ $item1, $item2 ]); test = instance.keyToDegree($scale, $stepsPerOctave); @@ -1116,7 +1118,7 @@ ]); }); - [ + _.each([ "neg", "bitNot", "abs", @@ -1184,7 +1186,7 @@ "theta", "degrad", "raddeg", - ].forEach(function(methodName) { + ], function(methodName) { it("#" + methodName, sinon.test(function() { var instance, test; @@ -1199,7 +1201,7 @@ })); }); - [ + _.each([ "+", "-", "*", @@ -1247,7 +1249,7 @@ "firstArg", "rrand", "exprand", - ].forEach(function(methodName) { + ], function(methodName) { it("#" + methodName, sinon.test(function() { var instance, test; var $aNumber = $$(), $adverb = $$(); @@ -1266,15 +1268,13 @@ it("#performUnaryOp", sinon.test(function() { var instance, test; - var $elem, $aSelector, $returned; - - $elem = $$({ + var $elem = $$({ perform: this.spy(function() { return $returned; }) }); - $aSelector = $$(); - $returned = $$(); + var $aSelector = $$(); + var $returned = $$(); instance = this.createInstance([ $elem ]); @@ -1285,13 +1285,11 @@ })); it("#performBinaryOp", sinon.test(function() { var instance, test; - var $aSelector, $theOperand, $adverb; - - $aSelector = $$(); - $theOperand = $$({ + var $aSelector = $$(); + var $theOperand = $$({ performBinaryOpOnSeqColl: this.spy(sc.test.func()) }); - $adverb = $$(); + var $adverb = $$(); instance = this.createInstance(); @@ -1420,11 +1418,9 @@ }); it("#performBinaryOpOnSeqColl.error", function() { var instance; - var $aSelector, $theOperand, $adverb; - - $aSelector = $$("\\+"); - $theOperand = $$(); - $adverb = $$("\\error"); + var $aSelector = $$("\\+"); + var $theOperand = $$(); + var $adverb = $$("\\error"); instance = this.createInstance(); @@ -1434,17 +1430,15 @@ }); it("#performBinaryOpOnSimpleNumber", sinon.test(function() { var instance, test; - var $elem, $aSelector, $aNumber, $adverb, $returned; - - $elem = $$(); - $aSelector = $$(); - $aNumber = $$({ + var $elem = $$(); + var $aSelector = $$(); + var $aNumber = $$({ perform: this.spy(function() { return $returned; }) }); - $adverb = $$(); - $returned = $$(); + var $adverb = $$(); + var $returned = $$(); instance = this.createInstance([ $elem ]); @@ -1455,17 +1449,15 @@ })); it("#performBinaryOpOnComplex", sinon.test(function() { var instance, test; - var $elem, $aSelector, $aComplex, $adverb, $returned; - - $elem = $$(); - $aSelector = $$(); - $aComplex = $$({ + var $elem = $$(); + var $aSelector = $$(); + var $aComplex = $$({ perform: this.spy(function() { return $returned; }) }); - $adverb = $$(); - $returned = $$(); + var $adverb = $$(); + var $returned = $$(); instance = this.createInstance([ $elem ]); @@ -1476,16 +1468,14 @@ })); it("#asFraction", sinon.test(function() { var instance, test; - var $elem, $denominator, $fasterBetter, $returned; - - $elem = $$({ + var $elem = $$({ asFraction: this.spy(function() { return $returned; }) }); - $denominator = $$(); - $fasterBetter = $$(); - $returned = $$(); + var $denominator = $$(); + var $fasterBetter = $$(); + var $returned = $$(); instance = this.createInstance([ $elem ]); @@ -1526,21 +1516,25 @@ var instance, test; instance = this.createInstance(); + test = instance.multiChannelPerform(); expect(test).to.be.a("SCArray").to.eql([]); instance = this.createInstance([ 10, 20, 30 ]); + test = instance.multiChannelPerform( $$("\\clip"), $$(15), $$([ 20, 25, 20 ]) ); expect(test).to.be.a("SCArray").to.eqls([ 15, 20, 20 ]); }); it("#multichannelExpandRef", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.multichannelExpandRef).to.doNothing; }); - [ + _.each([ "clip", "wrap", "fold", @@ -1569,14 +1563,12 @@ "blend", "checkBadValues", "prune", - ].forEach(function(methodName) { + ], function(methodName) { it("#" + methodName, sinon.test(function() { var instance, test; - var $arg1, $arg2, $arg3; - - $arg1 = $$(); - $arg2 = $$(); - $arg3 = $$(); + var $arg1 = $$(); + var $arg2 = $$(); + var $arg3 = $$(); instance = this.createInstance(); this.stub(instance, "multiChannelPerform", sc.test.func()); @@ -1642,6 +1634,7 @@ var instance, test; instance = this.createInstance([ 1, 2, 3, 4, 5 ]); + test = instance.swap($$(1), $$(3)); expect(test).to.equal(instance) .that.is.a("SCArray").and.eqls([ 1, 4, 3, 2, 5 ]); diff --git a/src/sc/classlib/Collections/Set_test.js b/src/sc/classlib/Collections/Set_test.js index fd8375b..288228e 100644 --- a/src/sc/classlib/Collections/Set_test.js +++ b/src/sc/classlib/Collections/Set_test.js @@ -7,8 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var iterator = sc.lang.iterator; - var SCSet = $("Set"); describe("SCSet", function() { @@ -22,6 +20,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.eql([]); }); @@ -41,27 +40,26 @@ var instance, test; instance = this.createInstance(); + test = instance.species(); expect(test).to.equal(SCSet); }); it.skip("#copy", function() { }); it("#do", sinon.test(function() { - var test, instance, iter; - var $function; + var test, instance; + var iter = {}; + var $function = $$(); - iter = {}; - $function = $$(); - this.stub(iterator, "set$do", function() { + instance = this.createInstance(); + this.stub(sc.lang.iterator, "set$do", function() { return iter; }); - this.stub(iterator, "execute"); - - instance = this.createInstance(); + this.stub(sc.lang.iterator, "execute"); test = instance.do($function); - expect(iterator.set$do).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.set$do).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#clear", function() { @@ -116,7 +114,6 @@ ]); }); it("#add", function() { - var instance; testCase(this, [ { source: [ 1, 2, 3 ], @@ -131,7 +128,10 @@ after: [ 1, 2, 3, 4 ] }, ]); + + var instance; instance = this.createInstance(); + expect(function() { instance.add($$(null)); }).to.throw("A Set cannot contain nil"); @@ -192,51 +192,46 @@ }); it("#sect", function() { var instance, test; - var $set; + var $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); instance = this.createInstance([ 1, 2, 3, 4, 5, 6 ]); - $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); test = instance.sect($set); expect(test.valueOf()).to.eql([ 1, 3, 5 ]); }); it("#union", function() { var instance, test; - var $set; + var $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); instance = this.createInstance([ 1, 2, 3, 4, 5, 6 ]); - $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); test = instance.union($set); expect(test.valueOf()).to.eql([ 1, 2, 3, 4, 5, 6, 7, 9 ]); }); it("#difference", function() { var instance, test; - var $set; + var $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); instance = this.createInstance([ 1, 2, 3, 4, 5, 6 ]); - $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); test = instance.difference($set); expect(test.valueOf()).to.eql([ 2, 4, 6 ]); }); it("#symmetricDifference", function() { var instance, test; - var $set; + var $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); instance = this.createInstance([ 1, 2, 3, 4, 5, 6 ]); - $set = SCSet.newFrom($$([ 1, 3, 5, 7, 9 ])); test = instance.symmetricDifference($set); expect(test.valueOf()).to.eql([ 2, 4, 6, 7, 9 ]); }); it("#isSubsetOf", function() { var instance, test; - var $set1, $set2; + var $set1 = SCSet.newFrom($$([ 1, 2, 3 ])); + var $set2 = SCSet.newFrom($$([ 0, 1 ])); instance = this.createInstance([ 1, 2 ]); - $set1 = SCSet.newFrom($$([ 1, 2, 3 ])); - $set2 = SCSet.newFrom($$([ 0, 1 ])); test = instance.isSubsetOf($set1); expect(test).to.be.a("SCBoolean").that.is.true; @@ -246,9 +241,7 @@ }); it("#&", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); this.stub(instance, "sect", sc.test.func()); @@ -259,9 +252,7 @@ })); it("#|", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); this.stub(instance, "union", sc.test.func()); @@ -272,9 +263,7 @@ })); it("#-", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); this.stub(instance, "difference", sc.test.func()); @@ -285,9 +274,7 @@ })); it("#--", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); this.stub(instance, "symmetricDifference", sc.test.func()); @@ -298,6 +285,7 @@ })); it("#asSet", function() { var instance; + instance = this.createInstance(); expect(instance.asSet).to.doNothing; }); diff --git a/src/sc/classlib/Collections/String_test.js b/src/sc/classlib/Collections/String_test.js index d21043b..1619f1d 100644 --- a/src/sc/classlib/Collections/String_test.js +++ b/src/sc/classlib/Collections/String_test.js @@ -7,7 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var SCString = $("String"); describe("SCString", function() { @@ -34,9 +33,7 @@ }); it("#__elem__", function() { var instance, test; - var $ch; - - $ch = $$("$a"); + var $ch = $$("$a"); instance = this.createInstance(); @@ -56,7 +53,9 @@ expect(test).to.be.a("JSString").that.equals("str"); }); it(".newClear", function() { - var test = SCString.newClear($$(4)); + var test; + + test = SCString.newClear($$(4)); expect(test).to.be.a("SCString").that.equals(" "); }); it.skip("<>unixCmdActions", function() { @@ -167,47 +166,41 @@ it.skip("#hash", function() { }); it("#performBinaryOpOnSimpleNumber", sinon.test(function() { - var instance, test, spy; - var $aSelector, $aNumber; - - spy = this.spy(sc.test.func()); - $aSelector = $$(); - $aNumber = $$({ + var instance, test; + var $aSelector = $$(); + var $aNumber = $$({ asString: function() { - return $$({ - perform: spy - }); + return $$({ perform: SCString$perform }); } }); + var SCString$perform = this.spy(sc.test.func()); instance = this.createInstance(); test = instance.performBinaryOpOnSimpleNumber($aSelector, $aNumber); - expect(spy).to.be.calledWith($aSelector, instance); - expect(spy).to.be.calledLastIn(test); + expect(SCString$perform).to.be.calledWith($aSelector, instance); + expect(SCString$perform).to.be.calledLastIn(test); })); it("#performBinaryOpOnComplex", sinon.test(function() { - var instance, test, spy; - var $aSelector, $aComplex; - - spy = this.spy(sc.test.func()); - $aSelector = $$(); - $aComplex = $$({ + var instance, test; + var $aSelector = $$(); + var $aComplex = $$({ asString: function() { - return $$({ - perform: spy - }); + return $$({ perform: SCString$perform }); } }); + var SCString$perform = this.spy(sc.test.func()); instance = this.createInstance(); test = instance.performBinaryOpOnComplex($aSelector, $aComplex); - expect(spy).to.be.calledWith($aSelector, instance); - expect(spy).to.be.calledLastIn(test); + expect(SCString$perform).to.be.calledWith($aSelector, instance); + expect(SCString$perform).to.be.calledLastIn(test); })); it("#multiChannelPerform", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(function() { instance.multiChannelPerform(); }).to.throw("Cannot expand strings"); @@ -221,7 +214,9 @@ expect(test).to.be.a("SCBoolean").that.is.true; }); it("#asString", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asString).to.doNothing; }); it("#asCompileString", function() { @@ -243,9 +238,8 @@ it("#postln", sinon.test(function() { var instance, test; - this.stub(sc.lang.io, "post"); - instance = this.createInstance("post"); + this.stub(sc.lang.io, "post"); test = instance.postln(); expect(test).to.equal(instance); @@ -254,9 +248,8 @@ it("#post", sinon.test(function() { var instance, test; - this.stub(sc.lang.io, "post"); - instance = this.createInstance("post"); + this.stub(sc.lang.io, "post"); test = instance.post(); expect(test).to.equal(instance); @@ -265,9 +258,8 @@ it("#postcln", sinon.test(function() { var instance, test; - this.stub(sc.lang.io, "post"); - instance = this.createInstance("post"); + this.stub(sc.lang.io, "post"); test = instance.postcln(); expect(test).to.equal(instance); @@ -276,9 +268,8 @@ it("#postc", sinon.test(function() { var instance, test; - this.stub(sc.lang.io, "post"); - instance = this.createInstance("post"); + this.stub(sc.lang.io, "post"); test = instance.postc(); expect(test).to.equal(instance); diff --git a/src/sc/classlib/Core/AbstractFunction_test.js b/src/sc/classlib/Core/AbstractFunction_test.js index 53800ba..9ec94c3 100644 --- a/src/sc/classlib/Core/AbstractFunction_test.js +++ b/src/sc/classlib/Core/AbstractFunction_test.js @@ -7,9 +7,10 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var klass = sc.lang.klass; - var SCFunctionList = $("FunctionList"); + var $int10 = $$(10); + var $int20 = $$(20); + var $int5 = $$(5); describe("SCAbstractFunction", function() { before(function() { @@ -20,81 +21,71 @@ }); it("#composeUnaryOp", sinon.test(function() { - var instance, test, spy; - var $aSelector; - - spy = this.spy(sc.test.func()); - $aSelector = $$(); - this.stub(klass, "get").withArgs("UnaryOpFunction").returns($$({ - new: spy - })); + var instance, test; + var $aSelector = $$(); + var SCUnaryOpFunction$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("UnaryOpFunction").returns($$({ + new: SCUnaryOpFunction$new + })); test = instance.composeUnaryOp($aSelector); - expect(spy).to.be.calledWith($aSelector, instance); - expect(spy).to.be.calledLastIn(test); + expect(SCUnaryOpFunction$new).to.be.calledWith($aSelector, instance); + expect(SCUnaryOpFunction$new).to.be.calledLastIn(test); })); it("#composeBinaryOp", sinon.test(function() { - var instance, test, spy; - var $aSelector, $something, $adverb; - - spy = this.spy(sc.test.func()); - $aSelector = $$(); - $something = $$(); - $adverb = $$(); - this.stub(klass, "get").withArgs("BinaryOpFunction").returns($$({ - new: spy - })); + var instance, test; + var $aSelector = $$(); + var $something = $$(); + var $adverb = $$(); + var SCBinaryOpFunction$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("BinaryOpFunction").returns($$({ + new: SCBinaryOpFunction$new + })); test = instance.composeBinaryOp($aSelector, $something, $adverb); - expect(spy).to.be.calledWith($aSelector, instance, $something, $adverb); - expect(spy).to.be.calledLastIn(test); + expect(SCBinaryOpFunction$new).to.be.calledWith($aSelector, instance, $something, $adverb); + expect(SCBinaryOpFunction$new).to.be.calledLastIn(test); })); it("#reverseComposeBinaryOp", sinon.test(function() { - var instance, test, spy; - var $aSelector, $something, $adverb; - - spy = this.spy(sc.test.func()); - $aSelector = $$(); - $something = $$(); - $adverb = $$(); - this.stub(klass, "get").withArgs("BinaryOpFunction").returns($$({ - new: spy - })); + var instance, test; + var $aSelector = $$(); + var $something = $$(); + var $adverb = $$(); + var SCBinaryOpFunction$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("BinaryOpFunction").returns($$({ + new: SCBinaryOpFunction$new + })); test = instance.reverseComposeBinaryOp($aSelector, $something, $adverb); - expect(spy).to.be.calledWith($aSelector, $something, instance, $adverb); - expect(spy).to.be.calledLastIn(test); + expect(SCBinaryOpFunction$new).to.be.calledWith($aSelector, $something, instance, $adverb); + expect(SCBinaryOpFunction$new).to.be.calledLastIn(test); })); it("#composeNAryOp", sinon.test(function() { - var instance, test, spy; - var $aSelector, $anArgList; - - spy = this.spy(sc.test.func()); - $aSelector = $$(); - $anArgList = $$(); - this.stub(klass, "get").withArgs("NAryOpFunction").returns($$({ - new: spy - })); + var instance, test; + var $aSelector = $$(); + var $anArgList = $$(); + var SCNAryOpFunction$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("NAryOpFunction").returns($$({ + new: SCNAryOpFunction$new + })); test = instance.composeNAryOp($aSelector, $anArgList); - expect(spy).to.be.calledWith($aSelector, instance, $anArgList); - expect(spy).to.be.calledLastIn(test); + expect(SCNAryOpFunction$new).to.be.calledWith($aSelector, instance, $anArgList); + expect(SCNAryOpFunction$new).to.be.calledLastIn(test); })); it("#performBinaryOpOnSimpleNumber", sinon.test(function() { var instance, test; - var $aSelector, $aNumber, $adverb; - - $aSelector = $$(); - $aNumber = $$(); - $adverb = $$(); + var $aSelector = $$(); + var $aNumber = $$(); + var $adverb = $$(); instance = this.createInstance(); this.stub(instance, "reverseComposeBinaryOp", sc.test.func()); @@ -105,11 +96,9 @@ })); it("#performBinaryOpOnSignal", sinon.test(function() { var instance, test; - var $aSelector, $aSignal, $adverb; - - $aSelector = $$(); - $aSignal = $$(); - $adverb = $$(); + var $aSelector = $$(); + var $aSignal = $$(); + var $adverb = $$(); instance = this.createInstance(); this.stub(instance, "reverseComposeBinaryOp", sc.test.func()); @@ -120,11 +109,9 @@ })); it("#performBinaryOpOnComplex", sinon.test(function() { var instance, test; - var $aSelector, $aComplex, $adverb; - - $aSelector = $$(); - $aComplex = $$(); - $adverb = $$(); + var $aSelector = $$(); + var $aComplex = $$(); + var $adverb = $$(); instance = this.createInstance(); this.stub(instance, "reverseComposeBinaryOp", sc.test.func()); @@ -135,11 +122,9 @@ })); it("#performBinaryOpOnSeqColl", sinon.test(function() { var instance, test; - var $aSelector, $aSeqColl, $adverb; - - $aSelector = $$(); - $aSeqColl = $$(); - $adverb = $$(); + var $aSelector = $$(); + var $aSeqColl = $$(); + var $adverb = $$(); instance = this.createInstance(); this.stub(instance, "reverseComposeBinaryOp", sc.test.func()); @@ -149,7 +134,7 @@ expect(instance.reverseComposeBinaryOp).to.be.calledLastIn(test); })); - [ + _.each([ "neg", "reciprocal", "bitNot", @@ -210,7 +195,7 @@ // "ref", "degrad", "raddeg", - ].forEach(function(methodName) { + ], function(methodName) { it("#" + methodName, sinon.test(function() { var instance, test; @@ -234,7 +219,7 @@ expect(instance.composeUnaryOp).to.be.calledLastIn(test); })); - [ + _.each([ "+", "-", "*", @@ -288,13 +273,11 @@ "&&", "xor", "nand", - ].forEach(function(methodName) { + ], function(methodName) { it("#" + methodName, sinon.test(function() { var instance, test; - var $function, $adverb; - - $function = $$(); - $adverb = $$(); + var $function = $$(); + var $adverb = $$(); instance = this.createInstance(); this.stub(instance, "composeBinaryOp", sc.test.func()); @@ -308,9 +291,7 @@ }); it("#rotate", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); this.stub(instance, "composeBinaryOp", sc.test.func()); @@ -323,9 +304,7 @@ })); it("#dist", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); this.stub(instance, "composeBinaryOp", sc.test.func()); @@ -337,7 +316,9 @@ expect(instance.composeBinaryOp).to.be.calledLastIn(test); })); it("#real", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.real).to.doNothing; }); it("#imag", function() { @@ -347,10 +328,8 @@ }); it("#clip", sinon.test(function() { var instance, test; - var $lo, $hi; - - $lo = $$(); - $hi = $$(); + var $lo = $$(); + var $hi = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -363,10 +342,8 @@ })); it("#wrap", sinon.test(function() { var instance, test; - var $lo, $hi; - - $lo = $$(); - $hi = $$(); + var $lo = $$(); + var $hi = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -379,10 +356,8 @@ })); it("#fold", sinon.test(function() { var instance, test; - var $lo, $hi; - - $lo = $$(); - $hi = $$(); + var $lo = $$(); + var $hi = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -395,10 +370,8 @@ })); it("#blend", sinon.test(function() { var instance, test; - var $that, $blendFrac; - - $that = $$(); - $blendFrac = $$(); + var $that = $$(); + var $blendFrac = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -411,13 +384,11 @@ })); it("#linlin", sinon.test(function() { var instance, test; - var $inMin, $inMax, $outMin, $outMax, $clip; - - $inMin = $$(); - $inMax = $$(); - $outMin = $$(); - $outMax = $$(); - $clip = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -430,13 +401,11 @@ })); it("#linexp", sinon.test(function() { var instance, test; - var $inMin, $inMax, $outMin, $outMax, $clip; - - $inMin = $$(); - $inMax = $$(); - $outMin = $$(); - $outMax = $$(); - $clip = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -449,13 +418,11 @@ })); it("#explin", sinon.test(function() { var instance, test; - var $inMin, $inMax, $outMin, $outMax, $clip; - - $inMin = $$(); - $inMax = $$(); - $outMin = $$(); - $outMax = $$(); - $clip = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -468,13 +435,11 @@ })); it("#expexp", sinon.test(function() { var instance, test; - var $inMin, $inMax, $outMin, $outMax, $clip; - - $inMin = $$(); - $inMax = $$(); - $outMin = $$(); - $outMax = $$(); - $clip = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -487,14 +452,12 @@ })); it("#lincurve", sinon.test(function() { var instance, test; - var $inMin, $inMax, $outMin, $outMax, $curve, $clip; - - $inMin = $$(); - $inMax = $$(); - $outMin = $$(); - $outMax = $$(); - $curve = $$(); - $clip = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $curve = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -507,14 +470,12 @@ })); it("#curvelin", sinon.test(function() { var instance, test; - var $inMin, $inMax, $outMin, $outMax, $curve, $clip; - - $inMin = $$(); - $inMax = $$(); - $outMin = $$(); - $outMax = $$(); - $curve = $$(); - $clip = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $curve = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -527,15 +488,13 @@ })); it("#bilin", sinon.test(function() { var instance, test; - var $inCenter, $inMin, $inMax, $outCenter, $outMin, $outMax, $clip; - - $inCenter = $$(); - $inMin = $$(); - $inMax = $$(); - $outCenter = $$(); - $outMin = $$(); - $outMax = $$(); - $clip = $$(); + var $inCenter = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outCenter = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -548,15 +507,13 @@ })); it("#biexp", sinon.test(function() { var instance, test; - var $inCenter, $inMin, $inMax, $outCenter, $outMin, $outMax, $clip; - - $inCenter = $$(); - $inMin = $$(); - $inMax = $$(); - $outCenter = $$(); - $outMin = $$(); - $outMax = $$(); - $clip = $$(); + var $inCenter = $$(); + var $inMin = $$(); + var $inMax = $$(); + var $outCenter = $$(); + var $outMin = $$(); + var $outMax = $$(); + var $clip = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -569,10 +526,8 @@ })); it("#moddif", sinon.test(function() { var instance, test; - var $function, $mod; - - $function = $$(); - $mod = $$(); + var $function = $$(); + var $mod = $$(); instance = this.createInstance(); this.stub(instance, "composeNAryOp", sc.test.func()); @@ -599,10 +554,8 @@ })); it("#applyTo", sinon.test(function() { var instance, test; - var $arg1, $arg2; - - $arg1 = $$(); - $arg2 = $$(); + var $arg1 = $$(); + var $arg2 = $$(); instance = this.createInstance(); this.stub(instance, "value", sc.test.func()); @@ -617,9 +570,7 @@ }); it("#asUGenInput", sinon.test(function() { var instance, test; - var $for; - - $for = $$(); + var $for = $$(); instance = this.createInstance(); this.stub(instance, "value", sc.test.func()); @@ -629,34 +580,34 @@ expect(instance.value).to.be.calledLastIn(test); })); it("#asAudioRateInput", sinon.test(function() { - var instance, test, spy, rate; - var $result; - - spy = this.spy(sc.test.func()); - $result = $$({ + var instance, test; + var $result = $$({ rate: function() { return $.Symbol(rate); } }); - this.stub(klass, "get").withArgs("K2A").returns($$({ - ar: spy - })); + var SCK2A$ar = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("K2A").returns($$({ + ar: SCK2A$ar + })); this.stub(instance, "value", function() { return $result; }); + var rate; + rate = "audio"; test = instance.asAudioRateInput(); expect(test).to.equal($result); - expect(spy).to.be.not.called; - spy.reset(); + expect(SCK2A$ar).to.be.not.called; + SCK2A$ar.reset(); rate = "control"; test = instance.asAudioRateInput(); - expect(spy).to.be.calledWith($result); - expect(spy).to.be.calledLastIn(test); + expect(SCK2A$ar).to.be.calledWith($result); + expect(SCK2A$ar).to.be.calledLastIn(test); })); it("#asControlInput", sinon.test(function() { var instance, test; @@ -774,10 +725,8 @@ }); it("#functionPerformList", sinon.test(function() { var test, instance; - var $selector, $arglist; - - $selector = $$(); - $arglist = $$(); + var $selector = $$(); + var $arglist = $$(); instance = this.createInstance("{|a, b| a * b} * -1"); this.stub(instance, "performList", sc.test.func()); @@ -823,10 +772,8 @@ }); it("#functionPerformList", sinon.test(function() { var test, instance; - var $selector, $arglist; - - $selector = $$(); - $arglist = $$(); + var $selector = $$(); + var $arglist = $$(); instance = this.createInstance("{|a, b| a + b}.wrap(-199, 20)"); this.stub(instance, "performList", sc.test.func()); @@ -838,7 +785,6 @@ }); describe("SCFunctionList", function() { - var $int10, $int20, $int5; before(function() { this.createInstance = function() { var instance = SCFunctionList.new($$([ @@ -857,9 +803,6 @@ ])); return instance; }; - $int10 = $$(10); - $int20 = $$(20); - $int5 = $$(5); }); describe("operate function list", function() { var instance; @@ -913,7 +856,9 @@ }); }); it("#addFunc.failed", function() { - var instance = this.createInstance().flop(); + var instance; + + instance = this.createInstance().flop(); expect(function() { instance.addFunc(); }).to.throw("cannot add a function to a flopped FunctionList"); @@ -969,28 +914,27 @@ it.skip("#valueArrayEnvir", function() { }); it("#do", sinon.test(function() { - var instance, test, spy; - var $elem1, $elem2, $function; - - spy = this.spy(); - $elem1 = $$(); - $elem2 = $$(); - $function = $$(spy); + var instance, test; + var $elem1 = $$(); + var $elem2 = $$(); + var func = this.spy(); + var $function = $$(func); instance = this.createInstance(); instance.array_($$([ $elem1, $elem2 ])); test = instance.do($function); expect(test).to.equal(instance); - expect(spy).to.callCount(2); - expect(spy.args[0]).to.eql($$([ $elem1, 0 ])._); - expect(spy.args[1]).to.eql($$([ $elem2, 1 ])._); + expect(func).to.callCount(2); + expect(func.args[0]).to.eql($$([ $elem1, 0 ])._); + expect(func.args[1]).to.eql($$([ $elem2, 1 ])._); })); it("#flop", function() { var instance, test; var $array; instance = this.createInstance(); + $array = instance.array(); expect(instance.flopped()).to.be.a("SCBoolean").that.is.false; @@ -1013,7 +957,6 @@ instance = this.createInstance(); test = instance.storeArgs(); - expect(test).to.be.a("SCArray").that.eqls([ instance._$array.valueOf() ]); diff --git a/src/sc/classlib/Core/Boolean_test.js b/src/sc/classlib/Core/Boolean_test.js index 7f959ca..f89ab4d 100644 --- a/src/sc/classlib/Core/Boolean_test.js +++ b/src/sc/classlib/Core/Boolean_test.js @@ -7,7 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var SCBoolean = $("Boolean"); var SCFalse = $("False"); var SCTrue = $("True"); @@ -91,12 +90,8 @@ }); it("#if", sinon.test(function() { var instance, test; - var $trueFunc, $falseFunc; - - $trueFunc = $$({ - value: sc.test.func() - }); - $falseFunc = $$({ + var $trueFunc = $$({ value: sc.test.func() }); + var $falseFunc = $$({ value: function() { throw new Error("not reached"); } @@ -117,11 +112,7 @@ }); it("#&&", function() { var instance, test; - var $that; - - $that = $$({ - value: sc.test.func() - }); + var $that = $$({ value: sc.test.func() }); instance = this.createInstance(); @@ -134,11 +125,7 @@ }); it("#and", function() { var instance, test; - var $that; - - $that = $$({ - value: sc.test.func() - }); + var $that = $$({ value: sc.test.func() }); instance = this.createInstance(); @@ -146,19 +133,16 @@ expect($that.value).to.be.calledLastIn(test); }); it("#or", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.or).to.doNothing; }); it("#nand", function() { var instance, test; - var $that; - - $that = $$({ - value: function() { - return this; - }, - not: sc.test.func() - }); + var $that = $$({ value: function() { + return this; + }, not: sc.test.func() }); instance = this.createInstance(); @@ -196,16 +180,12 @@ }); it("#if", sinon.test(function() { var instance, test; - var $trueFunc, $falseFunc; - - $trueFunc = $$({ + var $trueFunc = $$({ value: function() { throw new Error("not reached"); } }); - $falseFunc = $$({ - value: sc.test.func() - }); + var $falseFunc = $$({ value: sc.test.func() }); instance = this.createInstance(); @@ -216,20 +196,19 @@ var instance, test; instance = this.createInstance(); + test = instance.not(); expect(test).to.be.a("SCBoolean").that.is.true; }); it("#&&", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance["&&"]).to.doNothing; }); it("#||", function() { var instance, test; - var $that; - - $that = $$({ - value: sc.test.func() - }); + var $that = $$({ value: sc.test.func() }); instance = this.createInstance(); @@ -237,16 +216,14 @@ expect($that.value).to.be.calledLastIn(test); }); it("#and", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.and).to.doNothing; }); it("#or", function() { var instance, test; - var $that; - - $that = $$({ - value: sc.test.func() - }); + var $that = $$({ value: sc.test.func() }); instance = this.createInstance(); @@ -257,6 +234,7 @@ var instance, test; instance = this.createInstance(); + test = instance.nand(); expect(test).to.be.a("SCBoolean").that.is.true; }); @@ -264,6 +242,7 @@ var instance, test; instance = this.createInstance(); + test = instance.asInteger(); expect(test).to.be.a("SCInteger").that.equals(0); }); @@ -271,6 +250,7 @@ var instance, test; instance = this.createInstance(); + test = instance.binaryValue(); expect(test).to.be.a("SCInteger").that.equals(0); }); diff --git a/src/sc/classlib/Core/Char_test.js b/src/sc/classlib/Core/Char_test.js index cbe7963..4e4d0fe 100644 --- a/src/sc/classlib/Core/Char_test.js +++ b/src/sc/classlib/Core/Char_test.js @@ -21,6 +21,7 @@ var instance, test; instance = this.createInstance(); + test = instance.__tag; expect(test).to.be.a("JSNumber").that.equals(sc.TAG_CHAR); }); @@ -28,6 +29,7 @@ var instance, test; instance = this.createInstance(); + test = instance.__str__(); expect(test).to.be.a("JSString").that.equals("a"); }); @@ -35,27 +37,38 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.be.a("JSString").that.equals("a"); }); it(".nl", function() { - var test = SCChar.nl(); + var test; + + test = SCChar.nl(); expect(test).to.be.a("SCChar").that.equals("\n"); }); it(".ff", function() { - var test = SCChar.ff(); + var test; + + test = SCChar.ff(); expect(test).to.be.a("SCChar").that.equals("\f"); }); it(".tab", function() { - var test = SCChar.tab(); + var test; + + test = SCChar.tab(); expect(test).to.be.a("SCChar").that.equals("\t"); }); it(".space", function() { - var test = SCChar.space(); + var test; + + test = SCChar.space(); expect(test).to.be.a("SCChar").that.equals(" "); }); it(".comma", function() { - var test = SCChar.comma(); + var test; + + test = SCChar.comma(); expect(test).to.be.a("SCChar").that.equals(","); }); it(".new", function() { @@ -69,6 +82,7 @@ var instance, test; instance = this.createInstance(); + test = instance.ascii(); expect(test).to.be.a("SCInteger").that.equals(0x61); }); @@ -98,7 +112,9 @@ } }); it("#asAscii", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asAscii).to.doNothing; }); it("#asUnicode", sinon.test(function() { @@ -114,6 +130,7 @@ var instance, test; instance = this.createInstance(); + test = instance.toUpper(); expect(test).to.be.a("SCChar").that.equals("A"); }); @@ -121,6 +138,7 @@ var instance, test; instance = this.createInstance(); + test = instance.toLower(); expect(test).to.be.a("SCChar").that.equals("a"); }); @@ -281,9 +299,7 @@ }); it("#++", function() { var test, instance; - var $h; - - $h = $$("$h"); + var $h = $$("$h"); instance = this.createInstance("c"); diff --git a/src/sc/classlib/Core/Function_test.js b/src/sc/classlib/Core/Function_test.js index 401168e..40a340a 100644 --- a/src/sc/classlib/Core/Function_test.js +++ b/src/sc/classlib/Core/Function_test.js @@ -7,9 +7,8 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var iterator = sc.lang.iterator; - var SCFunction = $("Function"); + var SCArray = $("Array"); describe("SCFunction", function() { before(function() { @@ -76,81 +75,71 @@ expect(instance.value).to.be.calledLastIn(test); })); it("#update", sinon.test(function() { - var instance, test, spy; - var $arg1, $arg2, $arg3; - - spy = this.spy(sc.test.func()); - $arg1 = $$(); - $arg2 = $$(); - $arg3 = $$(); + var instance, test; + var $arg1 = $$(); + var $arg2 = $$(); + var $arg3 = $$(); + var func = this.spy(sc.test.func()); - instance = this.createInstance(spy); + instance = this.createInstance(func); test = instance.update($arg1, $arg2, $arg3); - expect(spy).to.be.calledWith($arg1, $arg2, $arg3); - expect(spy).to.be.calledLastIn(test); + expect(func).to.be.calledWith($arg1, $arg2, $arg3); + expect(func).to.be.calledLastIn(test); })); it("#value", sinon.test(function() { - var instance, test, spy; - - spy = this.spy(sc.test.func()); + var instance, test; + var func = this.spy(sc.test.func()); - instance = this.createInstance(spy); + instance = this.createInstance(func); test = instance.value(1, 2, 3); - expect(spy).to.be.calledWith(1, 2, 3); - expect(spy).to.be.calledLastIn(test); + expect(func).to.be.calledWith(1, 2, 3); + expect(func).to.be.calledLastIn(test); })); it("#valueArray", sinon.test(function() { - var instance, test, spy; - var $arg1, $arg2, $arg3; - - spy = this.spy(sc.test.func()); - $arg1 = $$(); - $arg2 = $$(); - $arg3 = $$(); + var instance, test; + var $arg1 = $$(); + var $arg2 = $$(); + var $arg3 = $$(); + var func = this.spy(sc.test.func()); - instance = this.createInstance(spy); + instance = this.createInstance(func); test = instance.valueArray($arg1); - expect(spy).to.be.calledWith($arg1); - expect(spy).to.be.calledLastIn(test); - spy.reset(); + expect(func).to.be.calledWith($arg1); + expect(func).to.be.calledLastIn(test); + func.reset(); test = instance.valueArray($$([ $arg1, $arg2, $arg3 ])); - expect(spy).to.be.calledWith($arg1, $arg2, $arg3); - expect(spy).to.be.calledLastIn(test); + expect(func).to.be.calledWith($arg1, $arg2, $arg3); + expect(func).to.be.calledLastIn(test); })); it("#valueEnvir", sinon.test(sc.test(function() { - var instance, test, spy; - var $arg1; - - spy = this.spy(sc.test.func()); - $arg1 = $$(); + var instance, test; + var $arg1 = $$(); + var func = this.spy(sc.test.func()); - instance = this.createInstance(spy, "a=1; b=2; c=3"); + instance = this.createInstance(func, "a=1; b=2; c=3"); $.Environment("c", $$(300)); test = instance.valueEnvir($arg1); - - expect(spy.args[0]).that.eqls($$([ $arg1, 2, 300 ])._); - expect(spy).to.be.calledLastIn(test); + expect(func.args[0]).that.eqls($$([ $arg1, 2, 300 ])._); + expect(func).to.be.calledLastIn(test); }))); it("#valueArrayEnvir", sinon.test(sc.test(function() { - var instance, test, spy; - var $arg1, $arg2; - - spy = this.spy(sc.test.func()); - $arg1 = $$(); - $arg2 = $$(null); + var instance, test; + var $arg1 = $$(); + var $arg2 = $$(null); + var func = this.spy(sc.test.func()); - instance = this.createInstance(spy, "a=1; b=2; c=3"); + instance = this.createInstance(func, "a=1; b=2; c=3"); $.Environment("c", $$(300)); test = instance.valueArrayEnvir($$([ $arg1, $arg2 ])); - expect(spy.args[0]).that.eqls($$([ $arg1, null, 300 ])._); - expect(spy).to.be.calledLastIn(test); + expect(func.args[0]).that.eqls($$([ $arg1, null, 300 ])._); + expect(func).to.be.calledLastIn(test); }))); it("#functionPerformList", sinon.test(function() { var instance, test; @@ -173,20 +162,18 @@ it.skip("#numVars", function() { }); it("#loop", sinon.test(function() { - var instance, test, iter; - - iter = {}; + var instance, test; + var iter = {}; - this.stub(iterator, "function$loop", function() { + instance = this.createInstance(); + this.stub(sc.lang.iterator, "function$loop", function() { return iter; }); - this.stub(iterator, "execute"); - - instance = this.createInstance(); + this.stub(sc.lang.iterator, "execute"); test = instance.loop(); - expect(iterator.function$loop).to.be.calledWith(undefined); - expect(iterator.execute).to.be.calledWith(iter, instance); + expect(sc.lang.iterator.function$loop).to.be.calledWith(undefined); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, instance); expect(test).to.equal(instance); })); it.skip("#block", function() { @@ -200,17 +187,16 @@ expect(test).to.be.a("SCRoutine"); }); it("#dup", sinon.test(function() { - var instance, test, spy; - var $n; - - spy = this.spy(sc.test.func()); - $n = $$(3); - this.stub($("Array"), "fill", spy); + var instance, test; + var $n = $$(3); + var SCArray$fill = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(SCArray, "fill", SCArray$fill); + test = instance.dup($n); - expect(spy).to.be.calledWith($n, instance); - expect(spy).to.be.calledLastIn(test); + expect(SCArray$fill).to.be.calledWith($n, instance); + expect(SCArray$fill).to.be.calledLastIn(test); })); it.skip("#sum", function() { }); @@ -236,10 +222,8 @@ }); it("#protect", sinon.test(function() { var instance, test; - var spy, $handler; - - spy = this.spy(); - $handler = $$(spy); + var func = this.spy(); + var $handler = $$(func); instance = this.createInstance(function() { return $$(1); @@ -247,14 +231,12 @@ test = instance.protect($handler); expect(test).to.be.a("SCInteger").that.equals(1); - expect(spy).to.be.called; + expect(func).to.be.called; })); it("#protect with error", sinon.test(function() { var instance, test; - var spy, $handler; - - spy = this.spy(); - $handler = $$(spy); + var func = this.spy(); + var $handler = $$(func); instance = this.createInstance(function() { throw new Error("error"); @@ -262,7 +244,7 @@ test = instance.protect($handler); expect(test).to.be.a("SCNil"); - expect(spy).to.be.called; + expect(func).to.be.called; })); it.skip("#handleError", function() { }); @@ -310,18 +292,17 @@ expect(test).to.be.a("SCRoutine"); }); it("#p", sinon.test(function() { - var instance, test, spy; + var instance, test; + var SCProut$new = this.spy(sc.test.func()); - spy = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("Prout").returns($$({ - new: spy + new: SCProut$new })); - instance = this.createInstance(); - test = instance.p(); - expect(spy).to.be.calledWith(instance); - expect(spy).to.be.calledLastIn(test); + expect(SCProut$new).to.be.calledWith(instance); + expect(SCProut$new).to.be.calledLastIn(test); })); it.skip("#matchItem", function() { }); @@ -350,22 +331,19 @@ it.skip("#inEnvir", function() { }); it("#while", sinon.test(function() { - var instance, test, iter; - var $body; - - iter = {}; - $body = $$(); + var instance, test; + var iter = {}; + var $body = $$(); - this.stub(iterator, "function$while", function() { + instance = this.createInstance(); + this.stub(sc.lang.iterator, "function$while", function() { return iter; }); - this.stub(iterator, "execute"); - - instance = this.createInstance(); + this.stub(sc.lang.iterator, "execute"); test = instance.while($body); - expect(iterator.function$while).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $body); + expect(sc.lang.iterator.function$while).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $body); expect(test).to.equal(instance); })); }); diff --git a/src/sc/classlib/Core/Kernel_test.js b/src/sc/classlib/Core/Kernel_test.js index 071b746..ca0c174 100644 --- a/src/sc/classlib/Core/Kernel_test.js +++ b/src/sc/classlib/Core/Kernel_test.js @@ -7,7 +7,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var SCClass = $("Class"); var SCMetaClass = $("Meta_Class"); var SCProcess = $("Process"); @@ -29,11 +28,14 @@ expect(test).to.equal(SCClass); }); it("#name", function() { - var test = SCClass.name(); + var test; + + test = SCClass.name(); expect(test).to.be.a("SCString").that.equals("Class"); }); it("#[]", function() { var test; + test = $("Set")["[]"]($$([ 1, 2, 3, 4 ])); expect(test).to.be.a("SCSet").that.eqls([ 1, 2, 3, 4 ]); }); @@ -49,16 +51,16 @@ var instance, test; instance = this.createInstance(); - test = instance.interpreter(); + test = instance.interpreter(); expect(test).to.be.a("SCNil"); }); it("", function() { var instance, test; - var $obj; + var $obj = $$(); - $obj = $$(); instance = this.createInstance(); test = instance ["->"] ($obj); expect(test).to.be.a("SCAssociation"); }); it("#next", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.next).to.doNothing; }); it("#reset", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.reset).to.doNothing; }); it("#first", sinon.test(function() { var instance, test; - var $inval; - - $inval = $$(); + var $inval = $$(); instance = this.createInstance(); this.stub(instance, "reset"); @@ -610,39 +579,48 @@ expect(instance.next).to.be.calledLastIn(test); })); it("#iter", sinon.test(function() { - var instance, test, spy; + var instance, test; + var SCOneShotStream$new = this.spy(sc.test.func()); - spy = this.spy(sc.test.func()); this.stub(sc.lang.klass, "get").withArgs("OneShotStream").returns($$({ - new: spy + new: SCOneShotStream$new })); instance = this.createInstance(); test = instance.iter(); - expect(spy).to.be.calledWith(instance); - expect(spy).to.be.calledLastIn(test); + expect(SCOneShotStream$new ).to.be.calledWith(instance); + expect(SCOneShotStream$new ).to.be.calledLastIn(test); })); it("#stop", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.stop).to.doNothing; }); it("#free", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.free).to.doNothing; }); it("#clear", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.clear).to.doNothing; }); it("#removedFromScheduler", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.removedFromScheduler).to.doNothing; }); it("#isPlaying", function() { var instance, test; instance = this.createInstance(); + test = instance.isPlaying(); expect(test).to.be.a("SCBoolean").that.is.false; }); @@ -694,22 +672,20 @@ }); it("#repeat", sinon.test(function() { var instance, test; - var $repeats, $new, $asStream; - - $repeats = $$(); - $new = this.spy(function() { - return { asStream: $asStream }; - }); - $asStream = sc.test.func(); - this.stub(sc.lang.klass, "get").withArgs("Pn").returns({ - new: $new + var $repeats = $$(); + var SCPn$new = this.spy(function() { + return { asStream: SCObject$asStream }; }); + var SCObject$asStream = sc.test.func(); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pn").returns({ + new: SCPn$new + }); test = instance.repeat($repeats); - expect($new.args[0]).to.eql($$([ instance, $repeats ])._); - expect($asStream).to.be.calledLastIn(test); + expect(SCPn$new.args[0]).to.eql($$([ instance, $repeats ])._); + expect(SCObject$asStream).to.be.calledLastIn(test); })); it("#loop", sinon.test(function() { var instance, test; @@ -755,11 +731,7 @@ }); it("#composeEvents", function() { var instance, test; - var $event; - - $event = $$({ - copy: sc.test.func() - }); + var $event = $$({ copy: sc.test.func() }); instance = this.createInstance(); @@ -767,7 +739,9 @@ expect($event.copy).to.be.calledLastIn(test); }); it("#finishEvent", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.finishEvent).to.doNothing; }); it("#atLimit", function() { @@ -787,33 +761,38 @@ expect(test).to.be.a("SCBoolean").that.is.false; }); it("#threadPlayer", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.threadPlayer).to.doNothing; }); it("#threadPlayer_", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.threadPlayer_).to.doNothing; }); it("#?", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance["?"]).to.doNothing; }); it("#??", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance["??"]).to.doNothing; }); it("#!?", sinon.test(function() { - var instance, test, spy; - var $obj; - - spy = this.spy(sc.test.func()); - $obj = $$({ value: spy }); + var instance, test; + var $obj = $$({ value: this.spy(sc.test.func()) }); instance = this.createInstance(); test = instance ["!?"] ($obj); - expect(spy).to.be.calledWith(instance); - expect(spy).to.be.calledLastIn(test); + expect($obj.value).to.be.calledWith(instance); + expect($obj.value).to.be.calledLastIn(test); })); it("#isNil", function() { testCase(this, [ @@ -882,9 +861,7 @@ }); it("#matchItem", sinon.test(function() { var instance, test; - var $item; - - $item = $$(); + var $item = $$(); instance = this.createInstance(); this.stub(instance, "===", sc.test.func()); @@ -902,22 +879,18 @@ expect(test).to.be.a("SCBoolean").that.is.false; }); it("#falseAt", sinon.test(function() { - var instance, test, spy; - var $key; - - spy = this.spy(sc.test.func()); - $key = $$(); + var instance, test; + var $key = $$(); + var SCBoolean$not = this.spy(sc.test.func()); instance = this.createInstance(); this.stub(instance, "trueAt", function() { - return $$({ - not: spy - }); + return $$({ not: SCBoolean$not }); }); test = instance.falseAt($key); expect(instance.trueAt).to.be.calledWith($key); - expect(spy).to.be.calledLastIn(test); + expect(SCBoolean$not).to.be.calledLastIn(test); })); it.skip("#pointsTo", function() { }); @@ -1002,9 +975,7 @@ }); it("#as", sinon.test(function() { var instance, test; - var $aSimilarClass; - - $aSimilarClass = $$({ + var $aSimilarClass = $$({ newFrom: this.spy(sc.test.func()) }); @@ -1015,15 +986,16 @@ expect($aSimilarClass.newFrom).to.be.calledLastIn(test); })); it("#dereference", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.dereference).to.doNothing; }); it("#reference", sinon.test(function() { var instance, test; - this.stub($, "Ref", sc.test.func()); - instance = this.createInstance(); + this.stub($, "Ref", sc.test.func()); test = instance.reference(); expect($.Ref).to.be.calledWith(instance); @@ -1032,28 +1004,24 @@ it("#asRef", sinon.test(function() { var instance, test; - this.stub($, "Ref", sc.test.func()); - instance = this.createInstance(); + this.stub($, "Ref", sc.test.func()); test = instance.asRef(); expect($.Ref).to.be.calledWith(instance); expect($.Ref).to.be.calledLastIn(test); })); it("#asArray", sinon.test(function() { - var instance, test, spy; - - spy = this.spy(sc.test.func()); + var instance, test; + var SCCollection$asArray = this.spy(sc.test.func()); instance = this.createInstance(); this.stub(instance, "asCollection", function() { - return $$({ - asArray: spy - }); + return $$({ asArray: SCCollection$asArray }); }); test = instance.asArray(); - expect(spy).to.be.calledLastIn(test); + expect(SCCollection$asArray).to.be.calledLastIn(test); })); it("#asSequenceableCollection", sinon.test(function() { var instance, test; @@ -1071,15 +1039,13 @@ }); it("#deepCollect", sinon.test(function() { var instance, test; - var $depth, $function, $index, $rank; - - $depth = $$(); - $function = $$(); - $index = $$(); - $rank = $$(); - this.stub($function, "value", sc.test.func()); + var $depth = $$(); + var $function = $$(); + var $index = $$(); + var $rank = $$(); instance = this.createInstance(); + this.stub($function, "value", sc.test.func()); test = instance.deepCollect($depth, $function, $index, $rank); expect($function.value).to.be.calledWith(instance, $index, $rank); @@ -1087,41 +1053,42 @@ })); it("#deepDo", sinon.test(function() { var instance, test; - var $depth, $function, $index, $rank; - - $depth = $$(); - $function = $$(); - $index = $$(); - $rank = $$(); - this.stub($function, "value", sc.test.func()); + var $depth = $$(); + var $function = $$(); + var $index = $$(); + var $rank = $$(); instance = this.createInstance(); + this.stub($function, "value", sc.test.func()); test = instance.deepDo($depth, $function, $index, $rank); expect($function.value).to.be.calledWith(instance, $index, $rank); expect(test).to.equal(instance); })); it("#slice", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.slice).to.doNothing; }); it("#shape", function() { var instance, test; instance = this.createInstance(); + test = instance.shape(); expect(test).to.be.a("SCNil"); }); it("#unbubble", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.unbubble).to.doNothing; }); it("#bubble", function() { var instance, test; - var $depth, $levels; - - $depth = $$(); - $levels = $$(3); + var $depth = $$(); + var $levels = $$(3); instance = this.createInstance(); @@ -1157,28 +1124,24 @@ ]); }); it("#addFunc", sinon.test(function() { - var instance, test, spy; - var $elem, $arg1, $arg2; + var instance, test; + var $elem = $$(); + var $arg1 = $$(); + var $arg2 = $$(); + var SCFunctionList$new = this.spy(sc.test.func()); - spy = this.spy(sc.test.func()); + instance = this.createInstance($$([ $elem ])); this.stub(sc.lang.klass, "get").withArgs("FunctionList").returns($$({ - new: spy + new: SCFunctionList$new })); - $elem = $$(); - $arg1 = $$(); - $arg2 = $$(); - - instance = this.createInstance($$([ $elem ])); test = instance.addFunc($arg1, $arg2); - expect(spy.args[0]).to.eql($$([ [ $elem, $arg1, $arg2 ] ])._); - expect(spy).to.be.calledLastIn(test); + expect(SCFunctionList$new.args[0]).to.eql($$([ [ $elem, $arg1, $arg2 ] ])._); + expect(SCFunctionList$new).to.be.calledLastIn(test); })); it("#removeFunc", function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); @@ -1190,10 +1153,8 @@ }); it("#replaceFunc", function() { var instance, test; - var $function, $replace; - - $function = $$(); - $replace = $$(); + var $function = $$(); + var $replace = $$(); instance = this.createInstance(); @@ -1208,10 +1169,9 @@ it.skip("#removeFuncFrom", function() { }); it("#while", sinon.test(function() { - var instance, test, count = 0; - var $body; - - $body = $$({ value: this.spy() }); + var instance, test; + var count = 0; + var $body = $$({ value: this.spy() }); instance = this.createInstance($$(function() { return $$(count++ < 2); @@ -1264,57 +1224,57 @@ var instance, test; instance = this.createInstance(); - this.stub(bytecode, "yield"); + this.stub(sc.lang.bytecode, "yield"); test = instance.yield(); expect(test).to.be.a("SCNil"); - expect(bytecode.yield).to.be.calledWith(instance); + expect(sc.lang.bytecode.yield).to.be.calledWith(instance); })); it("#alwaysYield", sinon.test(function() { var instance, test; instance = this.createInstance(); - this.stub(bytecode, "alwaysYield"); + this.stub(sc.lang.bytecode, "alwaysYield"); test = instance.alwaysYield(); expect(test).to.be.a("SCNil"); - expect(bytecode.alwaysYield).to.be.calledWith(instance); + expect(sc.lang.bytecode.alwaysYield).to.be.calledWith(instance); })); it("#yieldAndReset true", sinon.test(function() { var instance, test; instance = this.createInstance(); - this.stub(bytecode, "yieldAndReset"); - this.stub(bytecode, "yield"); + this.stub(sc.lang.bytecode, "yieldAndReset"); + this.stub(sc.lang.bytecode, "yield"); test = instance.yieldAndReset($$(true)); expect(test).to.be.a("SCNil"); - expect(bytecode.yieldAndReset).to.be.calledWith(instance); - expect(bytecode.yield).to.be.not.called; + expect(sc.lang.bytecode.yieldAndReset).to.be.calledWith(instance); + expect(sc.lang.bytecode.yield).to.be.not.called; })); it("#yieldAndReset null", sinon.test(function() { var instance, test; instance = this.createInstance(); - this.stub(bytecode, "yieldAndReset"); - this.stub(bytecode, "yield"); + this.stub(sc.lang.bytecode, "yieldAndReset"); + this.stub(sc.lang.bytecode, "yield"); test = instance.yieldAndReset(); expect(test).to.be.a("SCNil"); - expect(bytecode.yieldAndReset).to.be.calledWith(instance); - expect(bytecode.yield).to.be.not.called; + expect(sc.lang.bytecode.yieldAndReset).to.be.calledWith(instance); + expect(sc.lang.bytecode.yield).to.be.not.called; })); it("#yieldAndReset false", sinon.test(function() { var instance, test; instance = this.createInstance(); - this.stub(bytecode, "yieldAndReset"); - this.stub(bytecode, "yield"); + this.stub(sc.lang.bytecode, "yieldAndReset"); + this.stub(sc.lang.bytecode, "yield"); test = instance.yieldAndReset($$(false)); expect(test).to.be.a("SCNil"); - expect(bytecode.yieldAndReset).to.be.not.called; - expect(bytecode.yield).to.be.calledWith(instance); + expect(sc.lang.bytecode.yieldAndReset).to.be.not.called; + expect(sc.lang.bytecode.yield).to.be.calledWith(instance); })); it.skip("#idle", function() { }); @@ -1356,9 +1316,7 @@ }); it("#&", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.bitAnd = this.spy(sc.test.func()); @@ -1369,9 +1327,7 @@ })); it("#|", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.bitOr = this.spy(sc.test.func()); @@ -1382,9 +1338,7 @@ })); it("#%", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.mod = this.spy(sc.test.func()); @@ -1395,9 +1349,7 @@ })); it("#**", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.pow = this.spy(sc.test.func()); @@ -1408,9 +1360,7 @@ })); it("#<<", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.leftShift = this.spy(sc.test.func()); @@ -1421,9 +1371,7 @@ })); it("#>>", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.rightShift = this.spy(sc.test.func()); @@ -1434,9 +1382,7 @@ })); it("#+>>", sinon.test(function() { var instance, test; - var $that; - - $that = $$(); + var $that = $$(); instance = this.createInstance(); instance.unsignedRightShift = this.spy(sc.test.func()); @@ -1447,9 +1393,7 @@ })); it("#value", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -56,9 +52,7 @@ }); it("#get", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -67,9 +61,7 @@ }); it("#dereference", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -82,9 +74,7 @@ }); it("#valueArray", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -93,9 +83,7 @@ }); it("#valueEnvir", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -104,9 +92,7 @@ }); it("#valueArrayEnvir", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -115,9 +101,7 @@ }); it("#next", function() { var instance, test; - var $value; - - $value = $$(); + var $value = $$(); instance = this.createInstance($value); @@ -125,7 +109,9 @@ expect(test).to.equal($value); }); it("#asUGenInput", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asUGenInput).to.doNothing; }); it.skip("#printOn", function() { @@ -134,9 +120,7 @@ }); it("#at", sinon.test(function() { var instance, test; - var $value; - - $value = $$({ + var $value = $$({ at: this.spy(sc.test.func()) }); @@ -148,9 +132,7 @@ })); it("#put", sinon.test(function() { var instance, test; - var $value; - - $value = $$({ + var $value = $$({ put: this.spy(sc.test.func()) }); diff --git a/src/sc/classlib/Core/Symbol_test.js b/src/sc/classlib/Core/Symbol_test.js index b883948..a54c943 100644 --- a/src/sc/classlib/Core/Symbol_test.js +++ b/src/sc/classlib/Core/Symbol_test.js @@ -6,9 +6,7 @@ var $$ = sc.test.object; var testCase = sc.test.testCase; - var $ = sc.lang.$; - var klass = sc.lang.klass; - + var $ = sc.lang.$; var SCSymbol = $("Symbol"); describe("SCSymbol", function() { @@ -47,7 +45,9 @@ }).to.throw("should use literal"); }); it("#asSymbol", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.asSymbol).to.doNothing; }); it("#asInteger", function() { @@ -73,20 +73,14 @@ }); it("#ascii", sinon.test(function() { var instance, test; - var $obj; - - $obj = $$({ - ascii: sc.test.func() - }); + var SCString$ascii = this.spy(sc.test.func()); instance = this.createInstance(); - this.stub(instance, "asString", function() { - return $obj; - }); + this.stub(instance, "asString").returns($$({ ascii: SCString$ascii })); test = instance.ascii(); expect(instance.asString).to.be.called; - expect($obj.ascii).to.be.calledLastIn(test); + expect(SCString$ascii).to.be.calledLastIn(test); })); it.skip("#asCompileString", function() { }); @@ -123,70 +117,64 @@ }); it("#asSpec", sinon.test(function() { var instance, test; - var $at; + var SCArray$at = this.spy(sc.test.func()); - $at = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Spec").returns(sc.test.object({ + instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Spec").returns($$({ specs: function() { - return sc.test.object({ at: $at }); + return $$({ at: SCArray$at }); } })); - instance = this.createInstance(); test = instance.asSpec(); - expect($at).to.be.calledWith(instance); - expect($at).to.be.calledLastIn(test); + expect(SCArray$at).to.be.calledWith(instance); + expect(SCArray$at).to.be.calledLastIn(test); })); it("#asWarp", sinon.test(function() { var instance, test; - var $spec, $at, $new; + var $spec = $$(); + var SCArray$at = this.spy(function() { + return $$({ new: SCObject$new }); + }); + var SCObject$new = this.spy(sc.test.func()); - $spec = $$(); - this.stub(klass, "get").withArgs("Warp").returns(sc.test.object({ + this.stub(sc.lang.klass, "get").withArgs("Warp").returns($$({ warps: function() { - return sc.test.object({ - at: $at - }); + return $$({ at: SCArray$at }); } })); - $at = this.spy(function() { - return sc.test.object({ - new: $new - }); - }); - $new = this.spy(sc.test.func()); instance = this.createInstance(); test = instance.asWarp($spec); - expect($at).to.be.calledWith(instance); - expect($new).to.be.calledWith($spec); - expect($new).to.be.calledLastIn(test); + expect(SCArray$at).to.be.calledWith(instance); + expect(SCObject$new).to.be.calledWith($spec); + expect(SCObject$new).to.be.calledLastIn(test); })); it("#asTuning", sinon.test(function() { var instance, test; - var $at; + var SCTuning$at = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Tuning").returns(sc.test.object({ - at: ($at = this.spy(sc.test.func())) - })); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Tuning").returns($$({ + at: SCTuning$at + })); test = instance.asTuning(); - expect($at).to.be.calledWith(instance); - expect($at).to.be.calledLastIn(test); + expect(SCTuning$at).to.be.calledWith(instance); + expect(SCTuning$at).to.be.calledLastIn(test); })); it("#asScale", sinon.test(function() { var instance, test; - var $at; + var SCScale$at = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Scale").returns(sc.test.object({ - at: ($at = this.spy(sc.test.func())) - })); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Scale").returns($$({ + at: SCScale$at + })); test = instance.asScale(); - expect($at).to.be.calledWith(instance); - expect($at).to.be.calledLastIn(test); + expect(SCScale$at).to.be.calledWith(instance); + expect(SCScale$at).to.be.calledLastIn(test); })); it("#isSetter", function() { testCase(this, [ @@ -257,7 +245,9 @@ expect(test).to.be.a("SCInteger").that.equals(5678); })); it("#blend", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.blend).to.doNothing; }); it("#++", function() { @@ -273,10 +263,8 @@ }); it("#applyTo", function() { var instance, test; - var $a, $b; - - $a = $$(10); - $b = $$(20); + var $a = $$(10); + var $b = $$(20); instance = this.createInstance("*"); @@ -284,295 +272,95 @@ expect(test).to.be.a("SCInteger").that.equals(200); }); it("#performBinaryOpOnSomething", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.performBinaryOpOnSomething).to.doNothing; }); - it("#neg", function() { - var instance = this.createInstance(); - expect(instance.neg).to.doNothing; - }); - it("#bitNot", function() { - var instance = this.createInstance(); - expect(instance.bitNot).to.doNothing; - }); - it("#abs", function() { - var instance = this.createInstance(); - expect(instance.abs).to.doNothing; - }); - it("#ceil", function() { - var instance = this.createInstance(); - expect(instance.ceil).to.doNothing; - }); - it("#floor", function() { - var instance = this.createInstance(); - expect(instance.floor).to.doNothing; - }); - it("#frac", function() { - var instance = this.createInstance(); - expect(instance.frac).to.doNothing; - }); - it("#sign", function() { - var instance = this.createInstance(); - expect(instance.sign).to.doNothing; - }); - it("#sqrt", function() { - var instance = this.createInstance(); - expect(instance.sqrt).to.doNothing; - }); - it("#exp", function() { - var instance = this.createInstance(); - expect(instance.exp).to.doNothing; - }); - it("#midicps", function() { - var instance = this.createInstance(); - expect(instance.midicps).to.doNothing; - }); - it("#cpsmidi", function() { - var instance = this.createInstance(); - expect(instance.cpsmidi).to.doNothing; - }); - it("#midiratio", function() { - var instance = this.createInstance(); - expect(instance.midiratio).to.doNothing; - }); - it("#ratiomidi", function() { - var instance = this.createInstance(); - expect(instance.ratiomidi).to.doNothing; - }); - it("#ratiomidi", function() { - var instance = this.createInstance(); - expect(instance.ratiomidi).to.doNothing; - }); - it("#ampdb", function() { - var instance = this.createInstance(); - expect(instance.ampdb).to.doNothing; - }); - it("#dbamp", function() { - var instance = this.createInstance(); - expect(instance.dbamp).to.doNothing; - }); - it("#octcps", function() { - var instance = this.createInstance(); - expect(instance.octcps).to.doNothing; - }); - it("#cpsoct", function() { - var instance = this.createInstance(); - expect(instance.cpsoct).to.doNothing; - }); - it("#log", function() { - var instance = this.createInstance(); - expect(instance.log).to.doNothing; - }); - it("#log2", function() { - var instance = this.createInstance(); - expect(instance.log2).to.doNothing; - }); - it("#log10", function() { - var instance = this.createInstance(); - expect(instance.log10).to.doNothing; - }); - it("#sin", function() { - var instance = this.createInstance(); - expect(instance.sin).to.doNothing; - }); - it("#cos", function() { - var instance = this.createInstance(); - expect(instance.cos).to.doNothing; - }); - it("#tan", function() { - var instance = this.createInstance(); - expect(instance.tan).to.doNothing; - }); - it("#asin", function() { - var instance = this.createInstance(); - expect(instance.asin).to.doNothing; - }); - it("#acos", function() { - var instance = this.createInstance(); - expect(instance.acos).to.doNothing; - }); - it("#atan", function() { - var instance = this.createInstance(); - expect(instance.atan).to.doNothing; - }); - it("#sinh", function() { - var instance = this.createInstance(); - expect(instance.sinh).to.doNothing; - }); - it("#cosh", function() { - var instance = this.createInstance(); - expect(instance.cosh).to.doNothing; - }); - it("#tanh", function() { - var instance = this.createInstance(); - expect(instance.tanh).to.doNothing; - }); - it("#rand", function() { - var instance = this.createInstance(); - expect(instance.rand).to.doNothing; - }); - it("#rand2", function() { - var instance = this.createInstance(); - expect(instance.rand2).to.doNothing; - }); - it("#linrand", function() { - var instance = this.createInstance(); - expect(instance.linrand).to.doNothing; - }); - it("#bilinrand", function() { - var instance = this.createInstance(); - expect(instance.bilinrand).to.doNothing; - }); - it("#sum3rand", function() { - var instance = this.createInstance(); - expect(instance.sum3rand).to.doNothing; - }); - it("#distort", function() { - var instance = this.createInstance(); - expect(instance.distort).to.doNothing; - }); - it("#softclip", function() { - var instance = this.createInstance(); - expect(instance.softclip).to.doNothing; - }); - it("#coin", function() { - var instance = this.createInstance(); - expect(instance.coin).to.doNothing; - }); - it("#even", function() { - var instance = this.createInstance(); - expect(instance.even).to.doNothing; - }); - it("#odd", function() { - var instance = this.createInstance(); - expect(instance.odd).to.doNothing; - }); - it("#rectWindow", function() { - var instance = this.createInstance(); - expect(instance.rectWindow).to.doNothing; - }); - it("#hanWindow", function() { - var instance = this.createInstance(); - expect(instance.hanWindow).to.doNothing; - }); - it("#welWindow", function() { - var instance = this.createInstance(); - expect(instance.welWindow).to.doNothing; - }); - it("#triWindow", function() { - var instance = this.createInstance(); - expect(instance.triWindow).to.doNothing; - }); - it("#scurve", function() { - var instance = this.createInstance(); - expect(instance.scurve).to.doNothing; - }); - it("#ramp", function() { - var instance = this.createInstance(); - expect(instance.ramp).to.doNothing; - }); - it("#+", function() { - var instance = this.createInstance(); - expect(instance["+"]).to.doNothing; - }); - it("#-", function() { - var instance = this.createInstance(); - expect(instance["-"]).to.doNothing; - }); - it("#*", function() { - var instance = this.createInstance(); - expect(instance["*"]).to.doNothing; - }); - it("#/", function() { - var instance = this.createInstance(); - expect(instance["/"]).to.doNothing; - }); - it("#mod", function() { - var instance = this.createInstance(); - expect(instance.mod).to.doNothing; - }); - it("#min", function() { - var instance = this.createInstance(); - expect(instance.min).to.doNothing; - }); - it("#max", function() { - var instance = this.createInstance(); - expect(instance.max).to.doNothing; - }); - it("#bitAnd", function() { - var instance = this.createInstance(); - expect(instance.bitAnd).to.doNothing; - }); - it("#bitOr", function() { - var instance = this.createInstance(); - expect(instance.bitOr).to.doNothing; - }); - it("#bitXor", function() { - var instance = this.createInstance(); - expect(instance.bitXor).to.doNothing; - }); - it("#bitHammingDistance", function() { - var instance = this.createInstance(); - expect(instance.bitHammingDistance).to.doNothing; + + _.each([ + "#neg", + "#bitNot", + "#abs", + "#ceil", + "#floor", + "#frac", + "#sign", + "#sqrt", + "#exp", + "#midicps", + "#cpsmidi", + "#midiratio", + "#ratiomidi", + "#ratiomidi", + "#ampdb", + "#dbamp", + "#octcps", + "#cpsoct", + "#log", + "#log2", + "#log10", + "#sin", + "#cos", + "#tan", + "#asin", + "#acos", + "#atan", + "#sinh", + "#cosh", + "#tanh", + "#rand", + "#rand2", + "#linrand", + "#bilinrand", + "#sum3rand", + "#distort", + "#softclip", + "#coin", + "#even", + "#odd", + "#rectWindow", + "#hanWindow", + "#welWindow", + "#triWindow", + "#scurve", + "#ramp", + "#+", + "#-", + "#*", + "#/", + "#mod", + "#min", + "#max", + "#bitAnd", + "#bitOr", + "#bitXor", + "#bitHammingDistance", + "#lcm", + "#gcd", + "#round", + "#roundUp", + "#trunc", + "#atan2", + "#hypot", + "#hypotApx", + "#pow", + "#leftShift", + "#rightShift", + "#unsignedRightShift", + "#rrand", + "#exprand" + ], function(methodName) { + it(methodName, function() { + var instance; + + instance = this.createInstance(); + expect(instance.neg).to.doNothing; + }); }); + it.skip("#hammingDistance", function() { }); - it("#lcm", function() { - var instance = this.createInstance(); - expect(instance.lcm).to.doNothing; - }); - it("#gcd", function() { - var instance = this.createInstance(); - expect(instance.gcd).to.doNothing; - }); - it("#round", function() { - var instance = this.createInstance(); - expect(instance.round).to.doNothing; - }); - it("#roundUp", function() { - var instance = this.createInstance(); - expect(instance.roundUp).to.doNothing; - }); - it("#trunc", function() { - var instance = this.createInstance(); - expect(instance.trunc).to.doNothing; - }); - it("#atan2", function() { - var instance = this.createInstance(); - expect(instance.atan2).to.doNothing; - }); - it("#hypot", function() { - var instance = this.createInstance(); - expect(instance.hypot).to.doNothing; - }); - it("#hypotApx", function() { - var instance = this.createInstance(); - expect(instance.hypotApx).to.doNothing; - }); - it("#pow", function() { - var instance = this.createInstance(); - expect(instance.pow).to.doNothing; - }); - it("#leftShift", function() { - var instance = this.createInstance(); - expect(instance.leftShift).to.doNothing; - }); - it("#rightShift", function() { - var instance = this.createInstance(); - expect(instance.rightShift).to.doNothing; - }); - it("#unsignedRightShift", function() { - var instance = this.createInstance(); - expect(instance.unsignedRightShift).to.doNothing; - }); - it("#rrand", function() { - var instance = this.createInstance(); - expect(instance.rrand).to.doNothing; - }); - it("#exprand", function() { - var instance = this.createInstance(); - expect(instance.exprand).to.doNothing; - }); it("#<", function() { testCase(this, [ [ "b", [ "\\a" ], false ], @@ -602,36 +390,47 @@ ]); }); it("#degreeToKey", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.degreeToKey).to.doNothing; }); it("#degrad", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.degrad).to.doNothing; }); it("#raddeg", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.raddeg).to.doNothing; }); it("#doNumberOp", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.doNumberOp).to.doNothing; }); it("#doComplexOp", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.doComplexOp).to.doNothing; }); it("#doSignalOp", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.doSignalOp).to.doNothing; }); it("#doListOp", sinon.test(function() { var instance, test; - var $aSelector, $item1, $item2; + var $aSelector = $$(); + var $item1 = $$({ perform: this.spy() }); + var $item2 = $$({ perform: this.spy() }); - $aSelector = $$(); - $item1 = $$({ perform: this.spy() }); - $item2 = $$({ perform: this.spy() }); instance = this.createInstance(); test = instance.doListOp($aSelector, $$([ $item1, $item2 ])); @@ -676,11 +475,15 @@ expect(test).to.be.a("SCString").that.equals("sym"); }); it("#shallowCopy", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.shallowCopy).to.doNothing; }); it("#performBinaryOpOnSimpleNumber", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.performBinaryOpOnSimpleNumber).to.doNothing; }); }); diff --git a/src/sc/classlib/Core/Thread_test.js b/src/sc/classlib/Core/Thread_test.js index 1e54a2f..e73f392 100644 --- a/src/sc/classlib/Core/Thread_test.js +++ b/src/sc/classlib/Core/Thread_test.js @@ -6,7 +6,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var SCThread = $("Thread"); var SCRoutine = $("Routine"); @@ -53,7 +52,9 @@ it.skip("#init", function() { }); it("#copy", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.copy).to.doNothing; }); it.skip("#clock_", function() { @@ -97,15 +98,21 @@ it.skip("#handleError", function() { }); it("#next", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.next).to.doNothing; }); it("#value", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.value).to.doNothing; }); it("#valueArray", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.valueArray).to.doNothing; }); it.skip("#$primitiveError", function() { @@ -150,9 +157,7 @@ }); it("#next", function() { var instance; - var $inval; - - $inval = $$(); + var $inval = $$(); instance = this.createInstance([ function($inval) { @@ -196,19 +201,27 @@ expect(instance.next($inval), 8).to.be.a("SCNil"); }); it("#value", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.value).to.equal(instance.next); }); it("#resume", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.resume).to.equal(instance.next); }); it("#run", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.run).to.equal(instance.next); }); it("#valueArray", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.valueArray).to.equal(instance.value); }); it("#reset", function() { diff --git a/src/sc/classlib/Math/Float_test.js b/src/sc/classlib/Math/Float_test.js index 31aea77..ce4c44a 100644 --- a/src/sc/classlib/Math/Float_test.js +++ b/src/sc/classlib/Math/Float_test.js @@ -7,8 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var iterator = sc.lang.iterator; - var SCFloat = $("Float"); describe("SCFloat", function() { @@ -67,7 +65,9 @@ ]); }); it("#asFloat", function() { - var instance = this.createInstance(0); + var instance; + + instance = this.createInstance(0); expect(instance.asFloat).to.doNothing; }); it("#+", function() { @@ -382,40 +382,31 @@ ]); }); it("#do", sinon.test(function() { - var instance, test, iter; - var $function; - - iter = []; - $function = $$(); - this.stub(iterator, "float$do", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = []; + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "float$do").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.do($function); - expect(iterator.float$do).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.float$do).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#reverseDo", sinon.test(function() { - var instance, test, iter; - var $function; - - iter = {}; - $function = $$(); - - this.stub(iterator, "float$reverseDo", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "float$reverseDo").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.reverseDo($function); - expect(iterator.float$reverseDo).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.float$reverseDo).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#bitNot", function() { diff --git a/src/sc/classlib/Math/Integer_test.js b/src/sc/classlib/Math/Integer_test.js index 04c2b4a..3c76580 100644 --- a/src/sc/classlib/Math/Integer_test.js +++ b/src/sc/classlib/Math/Integer_test.js @@ -7,8 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var iterator = sc.lang.iterator; - var SCInteger = $("Integer"); describe("SCInteger", function() { @@ -384,12 +382,8 @@ }); it("#degreeToKey", sinon.test(function() { var instance, test; - var $scale, $stepsPerOctave; - - $scale = $$({ - performDegreeToKey: this.spy(sc.test.func()) - }); - $stepsPerOctave = $$(); + var $scale = $$({ performDegreeToKey: this.spy(sc.test.func()) }); + var $stepsPerOctave = $$(); instance = this.createInstance(); @@ -398,29 +392,22 @@ expect($scale.performDegreeToKey).to.be.calledLastIn(test); })); it("#do", sinon.test(function() { - var instance, test, iter; - var $function; - - iter = {}; - $function = $$(); - - this.stub(iterator, "integer$do", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "integer$do").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.do($function); - expect(iterator.integer$do).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.integer$do).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#generate", sinon.test(function() { var instance, test; - var $function; - - $function = $$({ value: this.spy() }); + var $function = $$({ value: this.spy() }); instance = this.createInstance(); test = instance.generate($function); @@ -448,9 +435,7 @@ }); it("#collect", sinon.test(function() { var instance, test; - var $function; - - $function = $$(); + var $function = $$(); instance = this.createInstance(); this.stub(instance, "collectAs", sc.test.func()); @@ -460,42 +445,32 @@ expect(instance.collectAs).to.be.calledLastIn(test); })); it("#reverseDo", sinon.test(function() { - var instance, test, iter; - var $function; - - iter = {}; - $function = $$(); - - this.stub(iterator, "integer$reverseDo", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "integer$reverseDo").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.reverseDo($function); - expect(iterator.integer$reverseDo).to.be.calledWith(instance); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.integer$reverseDo).to.be.calledWith(instance); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#for", sinon.test(function() { - var instance, test, iter; - var $endval, $function; - - iter = {}; - $endval = $$(); - $function = $$(); - - this.stub(iterator, "integer$for", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $endval = $$(); + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "integer$for").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.for($endval, $function); - expect(iterator.integer$for).to.be.calledWith(instance, $endval); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.integer$for).to.be.calledWith(instance, $endval); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#forBy", sinon.test(function() { @@ -505,33 +480,29 @@ var $stepval = $$(); var $function = $$(); - this.stub(iterator, "integer$forBy", function() { - return iter; - }); - this.stub(iterator, "execute"); - instance = this.createInstance(); + this.stub(sc.lang.iterator, "integer$forBy").returns(iter); + this.stub(sc.lang.iterator, "execute"); + test = instance.forBy($endval, $stepval, $function); - expect(iterator.integer$forBy).to.be.calledWith(instance, $endval, $stepval); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.integer$forBy).to.be.calledWith(instance, $endval, $stepval); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#to", sinon.test(function() { - var instance, test, spy; - var $hi, $step; + var instance, test; + var $hi = $$(); + var $step = $$(); + var SCInterval$new = this.spy(sc.test.func()); - spy = this.spy(sc.test.func()); - $hi = $$(); - $step = $$(); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("Interval").returns($$({ - new: spy + new: SCInterval$new })); - instance = this.createInstance(); - test = instance.to($hi, $step); - expect(spy).to.be.calledWith(instance, $hi, $step); - expect(spy).to.be.calledLastIn(test); + expect(SCInterval$new).to.be.calledWith(instance, $hi, $step); + expect(SCInterval$new).to.be.calledLastIn(test); })); it("#asAscii", function() { testCase(this, [ diff --git a/src/sc/classlib/Math/Number_test.js b/src/sc/classlib/Math/Number_test.js index a7d2684..1f94556 100644 --- a/src/sc/classlib/Math/Number_test.js +++ b/src/sc/classlib/Math/Number_test.js @@ -6,7 +6,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var iterator = sc.lang.iterator; describe("SCNumber", function() { before(function() { @@ -53,18 +52,14 @@ }); it("#performBinaryOpOnSeqColl", sinon.test(function() { var instance, test; - var $elem, $aSelector, $aSeqColl, $adverb; - - $elem = $$({ - perform: this.spy(sc.test.func()) - }); - $aSelector = $$(); - $aSeqColl = $$({ + var $elem = $$({ perform: this.spy(sc.test.func()) }); + var $aSelector = $$(); + var $aSeqColl = $$({ collect: function($func) { return $func.value($elem); } }); - $adverb = $$(); + var $adverb = $$(); instance = this.createInstance(); @@ -75,7 +70,9 @@ it.skip("#performBinaryOpOnPoint", function() { }); it("#rho", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.rho).to.doNothing; }); it("#theta", function() { @@ -87,7 +84,9 @@ expect(test).to.be.a("SCFloat").that.equal(0.0); }); it("#real", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.real).to.doNothing; }); it("#imag", function() { @@ -99,64 +98,50 @@ expect(test).to.be.a("SCFloat").that.equal(0.0); }); it("#for", sinon.test(function() { - var instance, test, iter; - var $endValue, $function; - - iter = {}; - $endValue = $$(); - $function = $$(); - this.stub(iterator, "number$for", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $endValue = $$(); + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "number$for").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.for($endValue, $function); - expect(iterator.number$for).to.be.calledWith(instance, $endValue); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.number$for).to.be.calledWith(instance, $endValue); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#forBy", sinon.test(function() { - var instance, test, iter = {}; - var $endValue, $stepValue, $function; - - iter = {}; - $endValue = $$(); - $stepValue = $$(); - $function = $$(); - - this.stub(iterator, "number$forBy", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $endValue = $$(); + var $stepValue = $$(); + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "number$forBy").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.forBy($endValue, $stepValue, $function); - expect(iterator.number$forBy).to.be.calledWith(instance, $endValue, $stepValue); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.number$forBy).to.be.calledWith(instance, $endValue, $stepValue); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); it("#forSeries", sinon.test(function() { - var instance, test, iter; - var $second, $last, $function; - - iter = {}; - $second = $$(); - $last = $$(); - $function = $$(); - - this.stub(iterator, "number$forSeries", function() { - return iter; - }); - this.stub(iterator, "execute"); + var instance, test; + var iter = {}; + var $second = $$(); + var $last = $$(); + var $function = $$(); instance = this.createInstance(); + this.stub(sc.lang.iterator, "number$forSeries").returns(iter); + this.stub(sc.lang.iterator, "execute"); test = instance.forSeries($second, $last, $function); - expect(iterator.number$forSeries).to.be.calledWith(instance, $second, $last); - expect(iterator.execute).to.be.calledWith(iter, $function); + expect(sc.lang.iterator.number$forSeries).to.be.calledWith(instance, $second, $last); + expect(sc.lang.iterator.execute).to.be.calledWith(iter, $function); expect(test).to.equal(instance); })); }); diff --git a/src/sc/classlib/Math/SimpleNumber_test.js b/src/sc/classlib/Math/SimpleNumber_test.js index d68c65f..a3ce9f7 100644 --- a/src/sc/classlib/Math/SimpleNumber_test.js +++ b/src/sc/classlib/Math/SimpleNumber_test.js @@ -7,7 +7,6 @@ var testCase = sc.test.testCase; var $ = sc.lang.$; - var klass = sc.lang.klass; describe("SCSimpleNumber", function() { before(function() { @@ -64,6 +63,7 @@ var instance, test; instance = $$(2014); + test = instance.__num__(); expect(test).to.be.a("JSNumber").that.equals(2014); }); @@ -650,8 +650,10 @@ ]); }); it("#performBinaryOpOnSimpleNumber", function() { - var instance = this.createInstance(); + var instance; var $aSelecor = $$("\\+"); + + instance = this.createInstance(); expect(function() { instance.performBinaryOpOnSimpleNumber($aSelecor); }).to.throw("failed"); @@ -659,8 +661,10 @@ it("#performBinaryOpOnComplex", function() { }); it("#performBinaryOpOnSignal", function() { - var instance = this.createInstance(); + var instance; var $aSelecor = $$("\\+"); + + instance = this.createInstance(); expect(function() { instance.performBinaryOpOnSignal($aSelecor); }).to.throw("failed"); @@ -839,30 +843,32 @@ var instance, test; instance = this.createInstance(); + test = instance.rate(); expect(test).to.be.a("SCSymbol").that.equals("scalar"); }); it("#asAudioRateInput", sinon.test(function() { - var instance, test, spy1, spy2; + var instance, test; - spy1 = this.spy(sc.test.func()); - spy2 = this.spy(sc.test.func()); - this.stub(sc.lang.klass, "get") - .withArgs("Silent").returns($$({ ar: spy1 })) - .withArgs("DC" ).returns($$({ ar: spy2 })); + var SCSilent$ar = this.spy(sc.test.func()); + var SCDC$ar = this.spy(sc.test.func()); instance = this.createInstance(0); + this.stub(sc.lang.klass, "get") + .withArgs("Silent").returns($$({ ar: SCSilent$ar })) + .withArgs("DC" ).returns($$({ ar: SCDC$ar })); + test = instance.asAudioRateInput(); - expect(spy1).to.be.calledLastIn(test); - expect(spy2).to.be.not.called; - spy1.reset(); - spy2.reset(); + expect(SCSilent$ar).to.be.calledLastIn(test); + expect(SCDC$ar).to.be.not.called; + SCSilent$ar.reset(); + SCDC$ar.reset(); instance = this.createInstance(1); test = instance.asAudioRateInput(); - expect(spy1).to.be.not.called; - expect(spy2).to.be.calledWith(instance); - expect(spy2).to.be.calledLastIn(test); + expect(SCSilent$ar).to.be.not.called; + expect(SCDC$ar).to.be.calledWith(instance); + expect(SCDC$ar).to.be.calledLastIn(test); })); it("#madd", function() { testCase(this, [ @@ -870,27 +876,39 @@ ]); }); it("#lag", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.lag).to.doNothing; }); it("#lag2", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.lag2).to.doNothing; }); it("#lag3", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.lag3).to.doNothing; }); it("#lagud", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.lagud).to.doNothing; }); it("#lag2ud", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.lag2ud).to.doNothing; }); it("#lag3ud", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.lag3ud).to.doNothing; }); it.skip("#writeInputSpec", function() { @@ -1006,10 +1024,10 @@ ]); }); it("#partition", function() { - sc.libs.random.setSeed(0); var instance, test; instance = this.createInstance(5.0); + sc.libs.random.setSeed(0); test = instance.partition($$(10), $$(8)); expect(test).to.be.a("SCArray").that.eqls([ @@ -1018,11 +1036,10 @@ }); it("#nextTimeOnGrid", sinon.test(function() { var instance, test; - var $clock; - - $clock = sc.test.object({ + var $clock = sc.test.object({ nextTimeOnGrid: this.spy(sc.test.func()) }); + instance = this.createInstance(); test = instance.nextTimeOnGrid($clock); @@ -1035,16 +1052,16 @@ }); it("#asQuant", sinon.test(function() { var instance, test; - var $new; + var SCQuant$new = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Quant").returns({ - new: ($new = this.spy(sc.test.func())) - }); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Quant").returns({ + new: SCQuant$new + }); test = instance.asQuant(); - expect($new).to.be.calledWith(instance); - expect($new).to.be.calledLastIn(test); + expect(SCQuant$new).to.be.calledWith(instance); + expect(SCQuant$new).to.be.calledLastIn(test); })); it.skip("#asTimeString", function() { }); @@ -1055,7 +1072,9 @@ it.skip("#schedBundleArrayOnClock", function() { }); it("#shallowCopy", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.shallowCopy).to.doNothing; }); }); diff --git a/src/sc/classlib/Streams/ListPatterns_test.js b/src/sc/classlib/Streams/ListPatterns_test.js index 8c2af22..f14ddef 100644 --- a/src/sc/classlib/Streams/ListPatterns_test.js +++ b/src/sc/classlib/Streams/ListPatterns_test.js @@ -24,9 +24,7 @@ }); it("#copy", function() { var instance, test; - var $list; - - $list = $$([ 1, 2, 3, 4, 5 ]); + var $list = $$([ 1, 2, 3, 4, 5 ]); instance = this.createInstance($list); diff --git a/src/sc/classlib/Streams/Patterns_test.js b/src/sc/classlib/Streams/Patterns_test.js index 83f3e48..658d02e 100644 --- a/src/sc/classlib/Streams/Patterns_test.js +++ b/src/sc/classlib/Streams/Patterns_test.js @@ -7,8 +7,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var klass = sc.lang.klass; - var SCPattern = $("Pattern"); var SCPseq = $("Pseq"); @@ -26,46 +24,40 @@ }); it("#++", sinon.test(function() { var instance, test; - var $aPattern, $new; - - $aPattern = $$(); - $new = this.spy(sc.test.func()); + var $aPattern = $$(); + var SCPseq$new = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Pseq").returns($$({ - new: $new - })); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pseq").returns($$({ + new: SCPseq$new + })); test = instance ["++"] ($aPattern); - expect($new.args[0]).to.eqls($$([ [ instance, $aPattern ] ])._); - expect($new).to.be.calledLastIn(test); + expect(SCPseq$new.args[0]).to.eqls($$([ [ instance, $aPattern ] ])._); + expect(SCPseq$new).to.be.calledLastIn(test); })); it("#<>", sinon.test(function() { var instance, test; - var $aPattern, $new; + var $aPattern = $$(); + var SCPchain$new = this.spy(sc.test.func()); - $aPattern = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pchain").returns($$({ - new: $new + this.stub(sc.lang.klass, "get").withArgs("Pchain").returns($$({ + new: SCPchain$new })); instance = this.createInstance(); test = instance ["<>"] ($aPattern); - expect($new).to.be.calledWith(instance, $aPattern); - expect($new).to.be.calledLastIn(test); + expect(SCPchain$new).to.be.calledWith(instance, $aPattern); + expect(SCPchain$new).to.be.calledLastIn(test); })); it("#play", sinon.test(function() { var instance, test; - var $clock, $protoEvent, $quant, $play; - - $clock = $$(); - $protoEvent = $$(); - $quant = $$(); - $play = this.spy(sc.test.func()); + var $clock = $$(); + var $protoEvent = $$(); + var $quant = $$(); + var $play = this.spy(sc.test.func()); instance = this.createInstance(); this.stub(instance, "asEventStreamPlayer", this.spy(function() { @@ -104,29 +96,24 @@ })); it("#asEventStreamPlayer", sinon.test(function() { var instance, test; - var $protoEvent, $stream, $new; - - $protoEvent = $$(); - $stream = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("EventStreamPlayer").returns({ - new: $new - }); + var $protoEvent = $$(); + var $stream = $$(); + var SCEventStreamPlayer$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("EventStreamPlayer").returns({ + new: SCEventStreamPlayer$new + }); this.stub(instance, "asStream").returns($stream); test = instance.asEventStreamPlayer($protoEvent); - expect($new).to.be.calledWith($stream, $protoEvent); - expect($new).to.be.calledLastIn(test); + expect(SCEventStreamPlayer$new).to.be.calledWith($stream, $protoEvent); + expect(SCEventStreamPlayer$new).to.be.calledLastIn(test); })); it("#embedInStream", sinon.test(function() { var instance, test; - var $inval, $stream; - - $inval = $$(); - $stream = $$({ embedInStream: this.spy() }); + var $inval = $$(); + var $stream = $$({ embedInStream: this.spy() }); instance = this.createInstance(); this.stub(instance, "asStream").returns($stream); @@ -137,10 +124,8 @@ })); it("#do", sinon.test(function() { var instance, test; - var $function, $stream; - - $function = $$(); - $stream = $$({ do: this.spy() }); + var $function = $$(); + var $stream = $$({ do: this.spy() }); instance = this.createInstance(); this.stub(instance, "asStream").returns($stream); @@ -151,469 +136,391 @@ })); it("#collect", sinon.test(function() { var instance, test; - var $function, $new; - - $function = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pcollect").returns($$({ - new: $new - })); + var $function = $$(); + var SCPcollect$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pcollect").returns($$({ + new: SCPcollect$new + })); test = instance.collect($function); - expect($new).to.be.calledWith($function, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPcollect$new).to.be.calledWith($function, instance); + expect(SCPcollect$new).to.be.calledLastIn(test); })); it("#select", sinon.test(function() { var instance, test; - var $function, $new; - - $function = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pselect").returns($$({ - new: $new - })); + var $function = $$(); + var SCPselect$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pselect").returns($$({ + new: SCPselect$new + })); test = instance.select($function); - expect($new).to.be.calledWith($function, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPselect$new).to.be.calledWith($function, instance); + expect(SCPselect$new).to.be.calledLastIn(test); })); it("#reject", sinon.test(function() { var instance, test; - var $function, $new; - - $function = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Preject").returns($$({ - new: $new - })); + var $function = $$(); + var SCPreject$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Preject").returns($$({ + new: SCPreject$new + })); test = instance.reject($function); - expect($new).to.be.calledWith($function, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPreject$new).to.be.calledWith($function, instance); + expect(SCPreject$new).to.be.calledLastIn(test); })); it("#composeUnaryOp", sinon.test(function() { var instance, test; - var $operator, $new; - - $operator = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Punop").returns($$({ - new: $new - })); + var $operator = $$(); + var SCPunop$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Punop").returns($$({ + new: SCPunop$new + })); test = instance.composeUnaryOp($operator); - expect($new).to.be.calledWith($operator, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPunop$new).to.be.calledWith($operator, instance); + expect(SCPunop$new).to.be.calledLastIn(test); })); it("#composeBinaryOp", sinon.test(function() { var instance, test; - var $operator, $pattern, $adverb, $new; - - $operator = $$(); - $pattern = $$(); - $adverb = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pbinop").returns($$({ - new: $new - })); + var $operator = $$(); + var $pattern = $$(); + var $adverb = $$(); + var SCPbinop$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pbinop").returns($$({ + new: SCPbinop$new + })); test = instance.composeBinaryOp($operator, $pattern, $adverb); - expect($new).to.be.calledWith($operator, instance, $pattern, $adverb); - expect($new).to.be.calledLastIn(test); + expect(SCPbinop$new).to.be.calledWith($operator, instance, $pattern, $adverb); + expect(SCPbinop$new).to.be.calledLastIn(test); })); it("#reverseComposeBinaryOp", sinon.test(function() { var instance, test; - var $operator, $pattern, $adverb, $new; + var $operator = $$(); + var $pattern = $$(); + var $adverb = $$(); + var SCPbinop$new = this.spy(sc.test.func()); - $operator = $$(); - $pattern = $$(); - $adverb = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pbinop").returns($$({ - new: $new + this.stub(sc.lang.klass, "get").withArgs("Pbinop").returns($$({ + new: SCPbinop$new })); instance = this.createInstance(); test = instance.reverseComposeBinaryOp($operator, $pattern, $adverb); - expect($new).to.be.calledWith($operator, $pattern, instance, $adverb); - expect($new).to.be.calledLastIn(test); + expect(SCPbinop$new).to.be.calledWith($operator, $pattern, instance, $adverb); + expect(SCPbinop$new).to.be.calledLastIn(test); })); it("#composeNAryOp", sinon.test(function() { var instance, test; - var $selector, $argList, $new; - - $selector = $$(); - $argList = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pnaryop").returns($$({ - new: $new - })); + var $selector = $$(); + var $argList = $$(); + var SCPnaryop$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pnaryop").returns($$({ + new: SCPnaryop$new + })); test = instance.composeNAryOp($selector, $argList); - expect($new).to.be.calledWith($selector, instance, $argList); - expect($new).to.be.calledLastIn(test); + expect(SCPnaryop$new).to.be.calledWith($selector, instance, $argList); + expect(SCPnaryop$new).to.be.calledLastIn(test); })); it("#mtranspose", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Paddp").returns($$({ - new: $new - })); + var $n = $$(); + var SCPaddp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Paddp").returns($$({ + new: SCPaddp$new + })); test = instance.mtranspose($n); - expect($new).to.be.calledWith($$("\\mtranspose"), $n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPaddp$new).to.be.calledWith($$("\\mtranspose"), $n, instance); + expect(SCPaddp$new).to.be.calledLastIn(test); })); it("#ctranspose", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); + var $n = $$(); + var SCPaddp$new = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Paddp").returns($$({ - new: $new + this.stub(sc.lang.klass, "get").withArgs("Paddp").returns($$({ + new: SCPaddp$new })); instance = this.createInstance(); test = instance.ctranspose($n); - expect($new).to.be.calledWith($$("\\ctranspose"), $n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPaddp$new).to.be.calledWith($$("\\ctranspose"), $n, instance); + expect(SCPaddp$new).to.be.calledLastIn(test); })); it("#gtranspose", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Paddp").returns($$({ - new: $new - })); + var $n = $$(); + var SCPaddp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Paddp").returns($$({ + new: SCPaddp$new + })); test = instance.gtranspose($n); - expect($new).to.be.calledWith($$("\\gtranspose"), $n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPaddp$new).to.be.calledWith($$("\\gtranspose"), $n, instance); + expect(SCPaddp$new).to.be.calledLastIn(test); })); it("#detune", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Paddp").returns($$({ - new: $new - })); + var $n = $$(); + var SCPaddp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Paddp").returns($$({ + new: SCPaddp$new + })); test = instance.detune($n); - expect($new).to.be.calledWith($$("\\detune"), $n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPaddp$new).to.be.calledWith($$("\\detune"), $n, instance); + expect(SCPaddp$new).to.be.calledLastIn(test); })); it("#scaleDur", sinon.test(function() { var instance, test; - var $x, $new; - - $x = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pmulp").returns($$({ - new: $new - })); + var $x = $$(); + var SCPmulp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pmulp").returns($$({ + new: SCPmulp$new + })); test = instance.scaleDur($x); - expect($new).to.be.calledWith($$("\\dur"), $x, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPmulp$new).to.be.calledWith($$("\\dur"), $x, instance); + expect(SCPmulp$new).to.be.calledLastIn(test); })); it("#addDur", sinon.test(function() { var instance, test; - var $x, $new; - - $x = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Paddp").returns($$({ - new: $new - })); + var $x = $$(); + var SCPaddp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Paddp").returns($$({ + new: SCPaddp$new + })); test = instance.addDur($x); - expect($new).to.be.calledWith($$("\\dur"), $x, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPaddp$new).to.be.calledWith($$("\\dur"), $x, instance); + expect(SCPaddp$new).to.be.calledLastIn(test); })); it("#stretch", sinon.test(function() { var instance, test; - var $x, $new; - - $x = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pmulp").returns($$({ - new: $new - })); + var $x = $$(); + var SCPmulp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pmulp").returns($$({ + new: SCPmulp$new + })); test = instance.stretch($x); - expect($new).to.be.calledWith($$("\\stretch"), $x, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPmulp$new).to.be.calledWith($$("\\stretch"), $x, instance); + expect(SCPmulp$new).to.be.calledLastIn(test); })); it("#lag", sinon.test(function() { var instance, test; - var $t, $new; - - $t = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Plag").returns($$({ - new: $new - })); + var $t = $$(); + var SCPlag$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Plag").returns($$({ + new: SCPlag$new + })); test = instance.lag($t); - expect($new).to.be.calledWith($t, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPlag$new).to.be.calledWith($t, instance); + expect(SCPlag$new).to.be.calledLastIn(test); })); it("#legato", sinon.test(function() { var instance, test; - var $x, $new; - - $x = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pmulp").returns($$({ - new: $new - })); + var $x = $$(); + var SCPmulp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pmulp").returns($$({ + new: SCPmulp$new + })); test = instance.legato($x); - expect($new).to.be.calledWith($$("\\legato"), $x, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPmulp$new).to.be.calledWith($$("\\legato"), $x, instance); + expect(SCPmulp$new).to.be.calledLastIn(test); })); it("#db", sinon.test(function() { var instance, test; - var $db, $new; - - $db = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Paddp").returns($$({ - new: $new - })); + var $db = $$(); + var SCPaddp$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Paddp").returns($$({ + new: SCPaddp$new + })); test = instance.db($db); - expect($new).to.be.calledWith($$("\\db"), $db, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPaddp$new).to.be.calledWith($$("\\db"), $db, instance); + expect(SCPaddp$new).to.be.calledLastIn(test); })); it("#clump", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pclump").returns($$({ - new: $new - })); + var $n = $$(); + var SCPclump$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pclump").returns($$({ + new: SCPclump$new + })); test = instance.clump($n); - expect($new).to.be.calledWith($n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPclump$new).to.be.calledWith($n, instance); + expect(SCPclump$new).to.be.calledLastIn(test); })); it("#flatten", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pflatten").returns($$({ - new: $new - })); + var $n = $$(); + var SCPflatten$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pflatten").returns($$({ + new: SCPflatten$new + })); test = instance.flatten($n); - expect($new).to.be.calledWith($n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPflatten$new).to.be.calledWith($n, instance); + expect(SCPflatten$new).to.be.calledLastIn(test); })); it("#repeat", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pn").returns($$({ - new: $new - })); + var $n = $$(); + var SCPn$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pn").returns($$({ + new: SCPn$new + })); test = instance.repeat($n); - expect($new).to.be.calledWith(instance, $n); - expect($new).to.be.calledLastIn(test); + expect(SCPn$new).to.be.calledWith(instance, $n); + expect(SCPn$new).to.be.calledLastIn(test); })); it("#keep", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pfin").returns($$({ - new: $new - })); + var $n = $$(); + var SCPfin$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pfin").returns($$({ + new: SCPfin$new + })); test = instance.keep($n); - expect($new).to.be.calledWith($n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPfin$new).to.be.calledWith($n, instance); + expect(SCPfin$new).to.be.calledLastIn(test); })); it("#drop", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pdrop").returns($$({ - new: $new - })); + var $n = $$(); + var SCPdrop$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pdrop").returns($$({ + new: SCPdrop$new + })); test = instance.drop($n); - expect($new).to.be.calledWith($n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPdrop$new).to.be.calledWith($n, instance); + expect(SCPdrop$new).to.be.calledLastIn(test); })); it("#stutter", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); + var $n = $$(); + var SCPstutter$new = this.spy(sc.test.func()); - this.stub(klass, "get").withArgs("Pstutter").returns($$({ - new: $new + this.stub(sc.lang.klass, "get").withArgs("Pstutter").returns($$({ + new: SCPstutter$new })); instance = this.createInstance(); test = instance.stutter($n); - expect($new).to.be.calledWith($n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPstutter$new).to.be.calledWith($n, instance); + expect(SCPstutter$new).to.be.calledLastIn(test); })); it("#finDur", sinon.test(function() { var instance, test; - var $dur, $tolerance, $new; - - $dur = $$(); - $tolerance = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pfindur").returns($$({ - new: $new - })); + var $dur = $$(); + var $tolerance = $$(); + var SCPfindur$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pfindur").returns($$({ + new: SCPfindur$new + })); test = instance.finDur($dur, $tolerance); - expect($new).to.be.calledWith($dur, instance, $tolerance); - expect($new).to.be.calledLastIn(test); + expect(SCPfindur$new).to.be.calledWith($dur, instance, $tolerance); + expect(SCPfindur$new).to.be.calledLastIn(test); })); it("#fin", sinon.test(function() { var instance, test; - var $n, $new; - - $n = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pfin").returns($$({ - new: $new - })); + var $n = $$(); + var SCPfin$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pfin").returns($$({ + new: SCPfin$new + })); test = instance.fin($n); - expect($new).to.be.calledWith($n, instance); - expect($new).to.be.calledLastIn(test); + expect(SCPfin$new).to.be.calledWith($n, instance); + expect(SCPfin$new).to.be.calledLastIn(test); })); it("#trace", sinon.test(function() { var instance, test; - var $key, $printStream, $prefix, $new; - - $key = $$(); - $printStream = $$(); - $prefix = $$(); - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Ptrace").returns($$({ - new: $new - })); + var $key = $$(); + var $printStream = $$(); + var $prefix = $$(); + var SCPtrace$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Ptrace").returns($$({ + new: SCPtrace$new + })); test = instance.trace($key, $printStream, $prefix); - expect($new).to.be.calledWith(instance, $key, $printStream, $prefix); - expect($new).to.be.calledLastIn(test); + expect(SCPtrace$new).to.be.calledWith(instance, $key, $printStream, $prefix); + expect(SCPtrace$new).to.be.calledLastIn(test); })); it("#differentiate", sinon.test(function() { var instance, test; - var $new; - - $new = this.spy(sc.test.func()); - - this.stub(klass, "get").withArgs("Pdiff").returns($$({ - new: $new - })); + var SCPdiff$new = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pdiff").returns($$({ + new: SCPdiff$new + })); test = instance.differentiate(); - expect($new).to.be.calledWith(instance); - expect($new).to.be.calledLastIn(test); + expect(SCPdiff$new).to.be.calledWith(instance); + expect(SCPdiff$new).to.be.calledLastIn(test); })); it.skip("#integrate", function() { }); diff --git a/src/sc/classlib/Streams/Stream_test.js b/src/sc/classlib/Streams/Stream_test.js index 4d759fa..a504f02 100644 --- a/src/sc/classlib/Streams/Stream_test.js +++ b/src/sc/classlib/Streams/Stream_test.js @@ -6,7 +6,6 @@ var $$ = sc.test.object; var $ = sc.lang.$; - var SCStream = $("Stream"); var SCOneShotStream = $("OneShotStream"); var SCFuncStream = $("FuncStream"); @@ -36,11 +35,15 @@ expect(test).to.be.a("SCNil"); }); it("#next", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.next.__errorType).to.equal("subclassResponsibility"); }); it("#iter", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.iter).to.doNothing; }); it("#value", function() { @@ -79,14 +82,14 @@ expect(test).to.be.a("SCArray").that.eqls([ 1, 2, 3, 4, 5 ]); }); it("#put", function() { - var instance = this.createInstance(); + var instance; + + instance = this.createInstance(); expect(instance.put.__errorType).to.equal("subclassResponsibility"); }); it("#putN", sinon.test(function() { var instance, test; - var $item; - - $item = $$(); + var $item = $$(); instance = this.createInstance(); this.stub(instance, "put"); @@ -100,9 +103,7 @@ })); it("#putAll", sinon.test(function() { var instance, test; - var $collection; - - $collection = $$([ 1, 2, 3 ]); + var $collection = $$([ 1, 2, 3 ]); instance = this.createInstance(); this.stub(instance, "put"); @@ -285,9 +286,7 @@ })); it("#++", sinon.test(function() { var instance, test; - var $stream; - - $stream = $$(); + var $stream = $$(); instance = this.createInstance(); this.stub(instance, "appendStream", sc.test.func()); @@ -338,83 +337,71 @@ })); it("#<>", sinon.test(function() { var instance, test; - var $obj, $new, $asStream; - - $obj = $$(); - $new = this.spy(function() { - return $$({ asStream: $asStream }); + var $obj = $$(); + var SCPchain$new = this.spy(function() { + return $$({ asStream: SCPchain$asStream }); }); - $asStream = this.spy(sc.test.func()); - this.stub(sc.lang.klass, "get").withArgs("Pchain").returns($$({ - new: $new - })); + var SCPchain$asStream = this.spy(sc.test.func()); instance = this.createInstance(); + this.stub(sc.lang.klass, "get").withArgs("Pchain").returns($$({ + new: SCPchain$new + })); test = instance ["<>"] ($obj); - expect($new.firstCall).to.be.calledWith(instance, $obj); - expect($asStream).to.be.calledLastIn(test); + expect(SCPchain$new.firstCall).to.be.calledWith(instance, $obj); + expect(SCPchain$asStream).to.be.calledLastIn(test); })); it("#composeUnaryOp", sinon.test(function() { var instance, test; - var $argSelector, $new; + var $argSelector = $$(); + var SCUnaryOpStream$new = this.spy(sc.test.func()); - $argSelector = $$(); - $new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("UnaryOpStream").returns($$({ - new: $new + new: SCUnaryOpStream$new })); - instance = this.createInstance(); - test = instance.composeUnaryOp($argSelector); - expect($new.firstCall).to.be.calledWith($argSelector, instance); - expect($new).to.be.calledLastIn(test); + expect(SCUnaryOpStream$new.firstCall).to.be.calledWith($argSelector, instance); + expect(SCUnaryOpStream$new).to.be.calledLastIn(test); })); it("#composeBinaryOp", sinon.test(function() { var instance, test; - var $argSelector, $argStream, $new; - - $argSelector = $$(); - $argStream = SCStream.new(); - $new = this.spy(sc.test.func()); + var $argSelector = $$(); + var $argStream = SCStream.new(); + var SCBinaryOpStream$new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("BinaryOpStream").returns($$({ - new: $new + new: SCBinaryOpStream$new })); - instance = this.createInstance(); - test = instance.composeBinaryOp($argSelector, $argStream); - expect($new.firstCall).to.be.calledWith($argSelector, instance, $argStream); - expect($new).to.be.calledLastIn(test); + expect(SCBinaryOpStream$new.firstCall).to.be.calledWith($argSelector, instance, $argStream); + expect(SCBinaryOpStream$new).to.be.calledLastIn(test); })); it("#composeBinaryOp with adverb 'x'", sinon.test(function() { var instance, test; - var $argSelector, $argStream, $adverb, $new; - - $argSelector = $$(); - $argStream = $$(SCStream.new()); - $adverb = $$("\\x"); - $new = this.spy(sc.test.func()); + var $argSelector = $$(); + var $argStream = $$(SCStream.new()); + var $adverb = $$("\\x"); + var SCBinaryOpXStream$new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("BinaryOpXStream").returns($$({ - new: $new + new: SCBinaryOpXStream$new })); - instance = this.createInstance(); - test = instance.composeBinaryOp($argSelector, $argStream, $adverb); - expect($new.firstCall).to.be.calledWith($argSelector, instance, $argStream); - expect($new).to.be.calledLastIn(test); + expect(SCBinaryOpXStream$new.firstCall).to.be.calledWith($argSelector, instance, $argStream); + expect(SCBinaryOpXStream$new).to.be.calledLastIn(test); })); it("#composeBinaryOp with unknown adverb", function() { var instance, test; - var $argSelector, $argStream, $adverb; - - $argSelector = $$(); - $argStream = $$(SCStream.new()); - $adverb = $$("\\unknown"); + var $argSelector = $$(); + var $argStream = $$(SCStream.new()); + var $adverb = $$("\\unknown"); instance = this.createInstance(); @@ -423,48 +410,40 @@ }); it("#reverseComposeBinaryOp", sinon.test(function() { var instance, test; - var $argSelector, $argStream, $new; - - $argSelector = $$(); - $argStream = $$(SCStream.new()); - $new = this.spy(sc.test.func()); + var $argSelector = $$(); + var $argStream = $$(SCStream.new()); + var SCBinaryOpStream$new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("BinaryOpStream").returns($$({ - new: $new + new: SCBinaryOpStream$new })); - instance = this.createInstance(); - test = instance.reverseComposeBinaryOp($argSelector, $argStream); - expect($new.firstCall).to.be.calledWith($argSelector, $argStream, instance); - expect($new).to.be.calledLastIn(test); + expect(SCBinaryOpStream$new.firstCall).to.be.calledWith($argSelector, $argStream, instance); + expect(SCBinaryOpStream$new).to.be.calledLastIn(test); })); it("#reverseComposeBinaryOp with adverb 'x'", sinon.test(function() { var instance, test; - var $argSelector, $argStream, $adverb, $new; - - $argSelector = $$(); - $argStream = $$(SCStream.new()); - $adverb = $$("\\x"); - $new = this.spy(sc.test.func()); + var $argSelector = $$(); + var $argStream = $$(SCStream.new()); + var $adverb = $$("\\x"); + var SCBinaryOpXStream$new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("BinaryOpXStream").returns($$({ - new: $new + new: SCBinaryOpXStream$new })); - instance = this.createInstance(); - test = instance.reverseComposeBinaryOp($argSelector, $argStream, $adverb); - expect($new.firstCall).to.be.calledWith($argSelector, $argStream, instance); - expect($new).to.be.calledLastIn(test); + expect(SCBinaryOpXStream$new.firstCall).to.be.calledWith($argSelector, $argStream, instance); + expect(SCBinaryOpXStream$new).to.be.calledLastIn(test); })); it("#reverseComposeBinaryOp with unknown adverb", function() { var instance, test; - var $argSelector, $argStream, $adverb; - - $argSelector = $$(); - $argStream = $$(SCStream.new()); - $adverb = $$("\\unknown"); + var $argSelector = $$(); + var $argStream = $$(SCStream.new()); + var $adverb = $$("\\unknown"); instance = this.createInstance(); @@ -473,20 +452,17 @@ }); it("#composeNAryOp", sinon.test(function() { var instance, test; - var $argSelector, $anArgList, $new; + var $argSelector = $$(); + var $anArgList = $$([ 1, 2 ]); + var SCNAryOpStream$new = this.spy(sc.test.func()); - $argSelector = $$(); - $anArgList = $$([ 1, 2 ]); - - $new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("NAryOpStream").returns($$({ - new: $new + new: SCNAryOpStream$new })); - instance = this.createInstance(); - test = instance.composeNAryOp($argSelector, $anArgList); - expect($new.args[0]).to.eql($$([ $argSelector, instance, [ 1, 2 ] ])._); + expect(SCNAryOpStream$new.args[0]).to.eql($$([ $argSelector, instance, [ 1, 2 ] ])._); })); it("#embedInStream", function() { var instance = this.createInstance(sc.test.routine([ 2, 3, 4 ])); @@ -518,29 +494,24 @@ }); it("#asEventStreamPlayer", sinon.test(function() { var instance, test; - var $protoEvent, $new; - - $protoEvent = $$(); + var $protoEvent = $$(); + var SCEventStreamPlayer$new = this.spy(sc.test.func()); - $new = this.spy(sc.test.func()); + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("EventStreamPlayer").returns($$({ - new: $new + new: SCEventStreamPlayer$new })); - instance = this.createInstance(); - test = instance.asEventStreamPlayer($protoEvent); - expect($new.args[0]).to.eql([ instance, $protoEvent ]); + expect(SCEventStreamPlayer$new.args[0]).to.eql([ instance, $protoEvent ]); })); it("#play case1", sinon.test(function() { var instance, test; - var $clock, $quant, $asQuant; - - $clock = $$({ play: this.spy() }); - $quant = $$({ asQuant: this.spy(function() { + var $clock = $$({ play: this.spy() }); + var $quant = $$({ asQuant: this.spy(function() { return $asQuant; }) }); - $asQuant = $$(); + var $asQuant = $$(); instance = this.createInstance(); @@ -550,22 +521,20 @@ })); it("#play case2", sinon.test(function() { var instance, test; - var $clock, $quant, $asQuant, $tempoClock; - - $clock = $$(null); - $quant = $$({ asQuant: this.spy(function() { + var $clock = $$(null); + var $quant = $$({ asQuant: this.spy(function() { return $asQuant; }) }); - $asQuant = $$(); - $tempoClock = $$({ play: this.spy() }); + var $asQuant = $$(); + var $tempoClock = $$({ play: this.spy() }); + + instance = this.createInstance(); this.stub(sc.lang.klass, "get").withArgs("TempoClock").returns($$({ default: function() { return $tempoClock; } })); - instance = this.createInstance(); - test = instance.play($clock, $quant); expect(test).to.equal(instance); expect($tempoClock.play).to.be.calledWith(instance, $asQuant); @@ -671,6 +640,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.equal(instance); }); @@ -730,6 +700,7 @@ var instance, test; instance = this.createInstance(); + test = instance.valueOf(); expect(test).to.equal(instance); }); From f187f8b5cc7c18b60692bf833ae2e346486660a3 Mon Sep 17 00:00:00 2001 From: mohayonao Date: Thu, 3 Jul 2014 13:33:28 +0900 Subject: [PATCH 5/6] :boom: fix typo --- src/sc/lang/iterator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sc/lang/iterator.js b/src/sc/lang/iterator.js index b8855af..a856b41 100644 --- a/src/sc/lang/iterator.js +++ b/src/sc/lang/iterator.js @@ -25,7 +25,7 @@ }; nop$iter(nop$iter); - function once$iter(value) { + var once$iter = function(value) { var iter = { hasNext: true, next: function() { @@ -37,7 +37,7 @@ } }; return iter; - } + }; iterator.execute = function(iter, $function) { $function._bytecode.setIterator(iter).run(); From d55375b342bb49e028d092faa324ec2a50917b11 Mon Sep 17 00:00:00 2001 From: mohayonao Date: Thu, 3 Jul 2014 15:02:42 +0900 Subject: [PATCH 6/6] :muscle: fix typo checker to be able to easily add rules like eslint --- tools/grunt-tasks/typo.js | 164 +++++++------------------------- tools/grunt-tasks/typo/args.js | 63 ++++++++++++ tools/grunt-tasks/typo/const.js | 30 ++++++ 3 files changed, 130 insertions(+), 127 deletions(-) create mode 100644 tools/grunt-tasks/typo/args.js create mode 100644 tools/grunt-tasks/typo/const.js diff --git a/tools/grunt-tasks/typo.js b/tools/grunt-tasks/typo.js index cd8577a..47864a7 100644 --- a/tools/grunt-tasks/typo.js +++ b/tools/grunt-tasks/typo.js @@ -1,15 +1,15 @@ module.exports = function(grunt) { "use strict"; + var _ = require("underscore"); + var path = require("path"); var esprima = require("esprima"); var estraverse = require("estraverse"); + var EventEmitter = require("events").EventEmitter; var reqUtils = require("./assets/require"); - var Syntax = esprima.Syntax; - grunt.registerTask("-typo", function(filter) { var src = grunt.file._expand("src").applyFilter(filter); - var constVariables, hasTypo; if (!src.length) { return; @@ -17,156 +17,66 @@ module.exports = function(grunt) { reqUtils.clearCache(); - constVariables = require("../../src/const"); + var checker = new TypoChecker(); - var detector = new Detector(constVariables); + _.each(grunt.file.expand("tools/grunt-tasks/typo/*.js"), function(filename) { + checker.addRule(path.resolve(filename)); + }); - src.forEach(function(fileName) { - if (detector.check(fileName)) { - hasTypo = true; - } + _.chain(src).each(function(filename) { + checker.verify(filename); }); - if (!hasTypo) { + if (!checker.hasTypo) { grunt.log.ok(src.length + " files typo free."); } - return !hasTypo; + return !checker.hasTypo; }); - function Detector(constVariables) { - this.constVariables = constVariables; + function TypoChecker() { + this.filename = ""; + this.sourceCode = ""; this.hasTypo = false; + this.emitter = new EventEmitter(); } - Detector.detectors = []; - Detector.addChecker = function(callback) { - Detector.detectors.push(callback); - return Detector; + TypoChecker.prototype.addRule = function(filepath) { + var rule = require(filepath); + + _.each(rule(this), function(func, name) { + this.emitter.on(name, func); + }, this); }; - Detector.prototype.check = function(fileName) { - this.fileName = fileName; - this.sourceCode = grunt.file.read(fileName); - this.hasTypo = false; - var that = this, ast = esprima.parse(this.sourceCode, { loc: true }); + TypoChecker.prototype.verify = function(filename) { + this.filename = filename; + this.sourceCode = grunt.file.read(filename); + + var ast = esprima.parse(this.sourceCode, { loc: true }); + var emitter = this.emitter; + estraverse.traverse(ast, { - enter: function(node, parent) { - Detector.detectors.forEach(function(callback) { - callback.call(that, node, parent); - }); + enter: function(node) { + emitter.emit(node.type, node); + }, + leave: function(node) { + emitter.emit(node.type + ":exit", node); } }); - return this.hasTypo; }; - Detector.prototype.showError = function(node, message) { + TypoChecker.prototype.report = function(node, message) { var lines = this.sourceCode.split("\n"); var lineNum = node.loc.start.line; var lineCol = node.loc.start.column; - grunt.log.subhead(" " + this.fileName); + + grunt.log.subhead(" " + this.filename); grunt.log.write(String(lineNum).rightAlign(7) + "|"); grunt.log.writeln(lines[lineNum - 1].grey); grunt.log.write(" ".repeat(lineCol + 8)); grunt.log.writeln("^ " + message); - }; - Detector.addChecker(function(node) { // camelcase - if (node.type !== Syntax.Identifier) { - return; - } - if (node.name.indexOf("_") === -1 || node.name === "_") { - return; - } - if (/^_*[$a-zA-Z][$a-zA-Z0-9]*_*$/.test(node.name)) { - return; - } - if (/^[A-Z]+(_[A-Z0-9]+)+$/.test(node.name)) { - return; - } - this.showError(node, String.format("#{0} is not in camelCase.", node.name)); this.hasTypo = true; - }); - - Detector.addChecker(function(node, parent) { // constVariables check - if (node.type !== Syntax.Identifier) { - return; - } - if (parent.type !== Syntax.MemberExpression) { - return; - } - if (parent.object.type !== Syntax.Identifier) { - return; - } - if (parent.object.name !== "sc") { - return; - } - if (!/^[A-Z0-9_]+$/.test(node.name)) { - return; - } - if (node.name !== "VERSION" && !this.constVariables.hasOwnProperty(node.name)) { - this.showError(node, String.format("#{0} is not defined.", node.name)); - this.hasTypo = true; - } - }); - - function getArgumentDefinition(list) { - for (var i = 0, imax = list.length; i < imax; ++i) { - var node = list[i]; - if (node && node.type === Syntax.Property) { - if (node.key.name === "args" && node.value.type === Syntax.Literal) { - return node.value.value; - } - } - } - return null; - } - - Detector.addChecker(function(node) { // arguments check - if (node.type !== Syntax.CallExpression) { - return; - } - if (node.callee.type !== Syntax.MemberExpression) { - return; - } - if (node.callee.property.type !== Syntax.Identifier) { - return; - } - if (!/^add(?:Class)?Method$/.test(node.callee.property.name)) { - return; - } - if (node.arguments.length < 3) { - return; - } - if (node.arguments[1].type !== Syntax.ObjectExpression) { - return; - } - if (node.arguments[2].type !== Syntax.FunctionExpression) { - return; - } - var args = getArgumentDefinition(node.arguments[1].properties); - if (!args) { - return; - } - var expected = args.split(";").map(function(x) { - return "$" + x.split("=")[0].replace("*", "$").trim(); - }); - var actual = node.arguments[2].params; - for (var i = 0, imax = Math.max(expected.length, actual.length); i < imax; ++i) { - if (!actual[i]) { - this.showError( - actual[i - 1], String.format("expect #{0}, but got None", expected[i]) - ); - this.hasTypo = true; - break; - } - if (expected[i] !== actual[i].name) { - this.showError( - actual[i], String.format("expect #{0}, but got #{1}", expected[i], actual[i].name) - ); - this.hasTypo = true; - break; - } - } - }); + }; }; diff --git a/tools/grunt-tasks/typo/args.js b/tools/grunt-tasks/typo/args.js new file mode 100644 index 0000000..2528005 --- /dev/null +++ b/tools/grunt-tasks/typo/args.js @@ -0,0 +1,63 @@ +module.exports = function(context) { + "use strict"; + + function getArgumentDefinition(list) { + for (var i = 0, imax = list.length; i < imax; ++i) { + var node = list[i]; + if (node && node.type === "Property") { + if (node.key.name === "args" && node.value.type === "Literal") { + return node.value.value; + } + } + } + return null; + } + + return { + CallExpression: function(node) { + if (node.callee.type !== "MemberExpression") { + return; + } + if (node.callee.property.type !== "Identifier") { + return; + } + if (!/^add(?:Class)?Method$/.test(node.callee.property.name)) { + return; + } + if (node.arguments.length < 3) { + return; + } + if (node.arguments[1].type !== "ObjectExpression") { + return; + } + if (node.arguments[2].type !== "FunctionExpression") { + return; + } + + var args = getArgumentDefinition(node.arguments[1].properties); + if (!args) { + return; + } + + var actual = node.arguments[2].params; + var expected = args.split(";").map(function(x) { + return "$" + x.split("=")[0].replace("*", "$").trim(); + }); + + for (var i = 0, imax = Math.max(expected.length, actual.length); i < imax; ++i) { + if (!actual[i]) { + context.report( + actual[i - 1], String.format("expect #{0}, but got None", expected[i]) + ); + break; + } + if (expected[i] !== actual[i].name) { + context.report( + actual[i], String.format("expect #{0}, but got #{1}", expected[i], actual[i].name) + ); + break; + } + } + } + }; +}; diff --git a/tools/grunt-tasks/typo/const.js b/tools/grunt-tasks/typo/const.js new file mode 100644 index 0000000..074bfbb --- /dev/null +++ b/tools/grunt-tasks/typo/const.js @@ -0,0 +1,30 @@ +module.exports = function(context) { + "use strict"; + + var constVariables = require("../../../src/const"); + + return { + MemberExpression: function(node) { + if (node.object.type !== "Identifier") { + return; + } + if (node.property.type !== "Identifier") { + return; + } + if (node.object.name !== "sc") { + return; + } + if (node.property.name === "VERSION") { + return; + } + if (!/^[A-Z0-9_]+$/.test(node.property.name)) { + return; + } + if (!constVariables.hasOwnProperty(node.property.name)) { + context.report( + node.property, String.format("#{0} is not defined.", node.property.name) + ); + } + } + }; +};