From 838aa9065a19c64b09cffcaf13655aa9e6a49b1e Mon Sep 17 00:00:00 2001 From: Edgar O Silva Date: Thu, 24 Oct 2013 16:25:42 -0500 Subject: [PATCH] Added colors to example. --- dist/adaptor.js | 27 ++++ dist/connection.js | 76 +++++++++++ dist/cylon.js | 78 +++++++++++ dist/device.js | 85 ++++++++++++ dist/driver.js | 32 +++++ dist/logger.js | 113 ++++++++++++++++ dist/loopback.js | 42 ++++++ dist/port.js | 55 ++++++++ dist/robot.js | 200 +++++++++++++++++++++++++++++ dist/utils.js | 27 ++++ examples/no_such_method.coffee | 21 +++ examples/sphero.coffee | 7 +- test/dist/specs/adaptor.spec.js | 20 +++ test/dist/specs/connection.spec.js | 61 +++++++++ test/dist/specs/cylon.spec.js | 38 ++++++ test/dist/specs/device.spec.js | 60 +++++++++ test/dist/specs/driver.spec.js | 17 +++ test/dist/specs/logger.spec.js | 37 ++++++ test/dist/specs/port.spec.js | 86 +++++++++++++ test/dist/specs/robot.spec.js | 42 ++++++ test/dist/specs/utils.spec.js | 18 +++ 21 files changed, 1141 insertions(+), 1 deletion(-) create mode 100644 dist/adaptor.js create mode 100644 dist/connection.js create mode 100644 dist/cylon.js create mode 100644 dist/device.js create mode 100644 dist/driver.js create mode 100644 dist/logger.js create mode 100644 dist/loopback.js create mode 100644 dist/port.js create mode 100644 dist/robot.js create mode 100644 dist/utils.js create mode 100644 examples/no_such_method.coffee create mode 100644 test/dist/specs/adaptor.spec.js create mode 100644 test/dist/specs/connection.spec.js create mode 100644 test/dist/specs/cylon.spec.js create mode 100644 test/dist/specs/device.spec.js create mode 100644 test/dist/specs/driver.spec.js create mode 100644 test/dist/specs/logger.spec.js create mode 100644 test/dist/specs/port.spec.js create mode 100644 test/dist/specs/robot.spec.js create mode 100644 test/dist/specs/utils.spec.js diff --git a/dist/adaptor.js b/dist/adaptor.js new file mode 100644 index 0000000..9d01faa --- /dev/null +++ b/dist/adaptor.js @@ -0,0 +1,27 @@ +/* + * adaptor + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Adaptor; + + module.exports = Adaptor = (function() { + function Adaptor(opts) { + this.name = opts.name; + } + + Adaptor.prototype.commands = function() { + return ['smile', 'laugh', 'help']; + }; + + return Adaptor; + + })(); + +}).call(this); diff --git a/dist/connection.js b/dist/connection.js new file mode 100644 index 0000000..5509c37 --- /dev/null +++ b/dist/connection.js @@ -0,0 +1,76 @@ +/* + * connection + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Connection, EventEmitter, Port, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice; + + require("./robot"); + + Port = require("./port"); + + EventEmitter = require('events').EventEmitter; + + module.exports = Connection = (function(_super) { + __extends(Connection, _super); + + function Connection(opts) { + if (opts == null) { + opts = {}; + } + this.self = this; + this.robot = opts.robot; + this.name = opts.name; + this.adaptor = this.requireAdaptor(opts.adaptor); + this.addCommands(this.adaptor); + this.port = new Port(opts.port); + } + + Connection.prototype.connect = function() { + Logger.info("Connecting to '" + this.name + "' on port '" + (this.port.toString()) + "'..."); + return this.adaptor.connect(this.self); + }; + + Connection.prototype.disconnect = function() { + Logger.info("Disconnecting from '" + this.name + "' on port '" + (this.port.toString()) + "'..."); + return this.adaptor.disconnect(this.self); + }; + + Connection.prototype.requireAdaptor = function(adaptorName) { + Logger.info("dynamic load adaptor"); + return this.robot.requireAdaptor(adaptorName, this.self); + }; + + Connection.prototype.addCommands = function(object) { + var method, _i, _len, _ref, _results; + _ref = object.commands(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + method = _ref[_i]; + _results.push(this.addProxy(object, method)); + } + return _results; + }; + + Connection.prototype.addProxy = function(object, method) { + return this[method] = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return object[method].apply(object, args); + }; + }; + + return Connection; + + })(EventEmitter); + +}).call(this); diff --git a/dist/cylon.js b/dist/cylon.js new file mode 100644 index 0000000..5a83cba --- /dev/null +++ b/dist/cylon.js @@ -0,0 +1,78 @@ +/* + * cylon + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Cylon, Robot, + __slice = [].slice, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + Robot = require("./robot"); + + require('./utils'); + + require('./logger'); + + Logger.setup(); + + Cylon = (function() { + var Master, instance; + + function Cylon() {} + + instance = null; + + Cylon.getInstance = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return instance != null ? instance : instance = (function(func, args, ctor) { + ctor.prototype = func.prototype; + var child = new ctor, result = func.apply(child, args); + return Object(result) === result ? result : child; + })(Master, args, function(){}); + }; + + Master = (function() { + var robots; + + function Master() { + this.robot = __bind(this.robot, this); + } + + robots = []; + + Master.prototype.robot = function(opts) { + var robot; + opts.master = this; + robot = new Robot(opts); + robots.push(robot); + return robot; + }; + + Master.prototype.start = function() { + var robot, _i, _len, _results; + _results = []; + for (_i = 0, _len = robots.length; _i < _len; _i++) { + robot = robots[_i]; + _results.push(robot.start()); + } + return _results; + }; + + return Master; + + })(); + + return Cylon; + + }).call(this); + + module.exports = Cylon.getInstance(); + +}).call(this); diff --git a/dist/device.js b/dist/device.js new file mode 100644 index 0000000..7ea6f63 --- /dev/null +++ b/dist/device.js @@ -0,0 +1,85 @@ +/* + * device + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Device, EventEmitter, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __slice = [].slice; + + require('./cylon'); + + EventEmitter = require('events').EventEmitter; + + module.exports = Device = (function(_super) { + __extends(Device, _super); + + function Device(opts) { + if (opts == null) { + opts = {}; + } + this.self = this; + this.robot = opts.robot; + this.name = opts.name; + this.connection = this.determineConnection(opts.connection) || this.defaultConnection(); + this.driver = this.requireDriver(opts.driver); + this.addCommands(this.driver); + } + + Device.prototype.start = function() { + return Logger.info("started"); + }; + + Device.prototype.determineConnection = function(c) { + if (c) { + return this.robot.connections[c]; + } + }; + + Device.prototype.defaultConnection = function() { + var first, k, v, _ref; + first = 0; + _ref = this.robot.connections; + for (k in _ref) { + v = _ref[k]; + first || (first = v); + } + return first; + }; + + Device.prototype.requireDriver = function(driverName) { + Logger.info("dynamic load driver"); + return this.robot.requireDriver(driverName, this.self); + }; + + Device.prototype.addCommands = function(object) { + var method, _i, _len, _ref, _results; + _ref = object.commands(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + method = _ref[_i]; + _results.push(this.addProxy(object, method)); + } + return _results; + }; + + Device.prototype.addProxy = function(object, method) { + return this.self[method] = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return object[method].apply(object, args); + }; + }; + + return Device; + + })(EventEmitter); + +}).call(this); diff --git a/dist/driver.js b/dist/driver.js new file mode 100644 index 0000000..e9f7e48 --- /dev/null +++ b/dist/driver.js @@ -0,0 +1,32 @@ +/* + * driver + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Driver; + + module.exports = Driver = (function() { + function Driver(opts) { + this.self = this; + this.name = opts.name; + } + + Driver.prototype.start = function() { + return Logger.info("started"); + }; + + Driver.prototype.commands = function() { + return ['smile', 'laugh', 'help']; + }; + + return Driver; + + })(); + +}).call(this); diff --git a/dist/logger.js b/dist/logger.js new file mode 100644 index 0000000..915fd82 --- /dev/null +++ b/dist/logger.js @@ -0,0 +1,113 @@ +/* + * logger + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + var BasicLogger, NullLogger, + __slice = [].slice; + + global.Logger = { + setup: function(logger) { + if (logger == null) { + logger = new BasicLogger; + } + return this.logger = logger === false ? new NullLogger : logger; + }, + toString: function() { + return this.logger.toString(); + }, + debug: function() { + var args, _ref; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return (_ref = this.logger).debug.apply(_ref, args); + }, + info: function() { + var args, _ref; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return (_ref = this.logger).info.apply(_ref, args); + }, + warn: function() { + var args, _ref; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return (_ref = this.logger).warn.apply(_ref, args); + }, + error: function() { + var args, _ref; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return (_ref = this.logger).error.apply(_ref, args); + }, + fatal: function() { + var args, _ref; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return (_ref = this.logger).fatal.apply(_ref, args); + } + }; + + BasicLogger = (function() { + function BasicLogger() {} + + BasicLogger.prototype.toString = function() { + return "BasicLogger"; + }; + + BasicLogger.prototype.debug = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return console.log.apply(console, args); + }; + + BasicLogger.prototype.info = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return console.log.apply(console, args); + }; + + BasicLogger.prototype.warn = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return console.log.apply(console, args); + }; + + BasicLogger.prototype.error = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return console.log.apply(console, args); + }; + + BasicLogger.prototype.fatal = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return console.log.apply(console, args); + }; + + return BasicLogger; + + })(); + + NullLogger = (function() { + function NullLogger() {} + + NullLogger.prototype.debug = function() {}; + + NullLogger.prototype.info = function() {}; + + NullLogger.prototype.warn = function() {}; + + NullLogger.prototype.error = function() {}; + + NullLogger.prototype.fatal = function() {}; + + NullLogger.prototype.toString = function() { + return "NullLogger"; + }; + + return NullLogger; + + })(); + +}).call(this); diff --git a/dist/loopback.js b/dist/loopback.js new file mode 100644 index 0000000..f3ae01e --- /dev/null +++ b/dist/loopback.js @@ -0,0 +1,42 @@ +/* + * adaptor + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Loopback; + + module.exports = { + adaptor: function(opts) { + if (opts == null) { + opts = {}; + } + return new Loopback(opts); + } + }; + + Loopback = (function() { + function Loopback(opts) { + this.self = this; + this.name = opts.name; + } + + Loopback.prototype.connect = function() { + Logger.info("Connecting to adaptor '" + this.name + "'..."); + return this.self; + }; + + Loopback.prototype.disconnect = function() { + return Logger.info("Disconnecting from adaptor '" + this.name + "'..."); + }; + + return Loopback; + + })(); + +}).call(this); diff --git a/dist/port.js b/dist/port.js new file mode 100644 index 0000000..b7aa252 --- /dev/null +++ b/dist/port.js @@ -0,0 +1,55 @@ +/* + * port + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Port; + + module.exports = Port = (function() { + function Port(data) { + this.self = this; + this.isTcp = this.isSerial = this.isPortless = false; + this.parse(data); + } + + Port.prototype.parse = function(data) { + var match; + if (data === void 0) { + this.port = void 0; + return this.isPortless = true; + } else if (match = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/.exec(data)) { + this.port = match[2]; + this.host = match[1]; + return this.isTcp = true; + } else if (/^[0-9]{1,5}$/.exec(data)) { + this.port = data; + this.host = "localhost"; + return this.isTcp = true; + } else { + this.port = data; + this.host = void 0; + return this.isSerial = true; + } + }; + + Port.prototype.toString = function() { + if (this.isPortless) { + return "none"; + } else if (this.isSerial) { + return this.port; + } else { + return "" + this.host + ":" + this.port; + } + }; + + return Port; + + })(); + +}).call(this); diff --git a/dist/robot.js b/dist/robot.js new file mode 100644 index 0000000..8791360 --- /dev/null +++ b/dist/robot.js @@ -0,0 +1,200 @@ +/* + * robot + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + 'use strict'; + var Connection, Device, Robot, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + __slice = [].slice; + + require('./cylon'); + + Connection = require("./connection"); + + Device = require("./device"); + + module.exports = Robot = (function() { + var self, + _this = this; + + self = Robot; + + Robot.adaptors = {}; + + Robot.drivers = {}; + + function Robot(opts) { + if (opts == null) { + opts = {}; + } + this.startDevices = __bind(this.startDevices, this); + this.startConnections = __bind(this.startConnections, this); + this.initDevices = __bind(this.initDevices, this); + this.initConnections = __bind(this.initConnections, this); + this.name = opts.name || this.constructor.randomName(); + this.master = opts.master; + this.connections = {}; + this.devices = {}; + this.registerAdaptor("./loopback", "loopback"); + this.initConnections(opts.connection || opts.connections); + this.initDevices(opts.device || opts.devices); + this.work = opts.work || function() { + return Logger.info("No work yet"); + }; + } + + Robot.randomName = function() { + return "Robot " + (Math.floor(Math.random() * 100000)); + }; + + Robot.prototype.initConnections = function(connections) { + var connection, _i, _len, _results; + Logger.info("Initializing connections..."); + if (connections == null) { + return; + } + connections = [].concat(connections); + _results = []; + for (_i = 0, _len = connections.length; _i < _len; _i++) { + connection = connections[_i]; + Logger.info("Initializing connection '" + connection.name + "'..."); + connection['robot'] = this; + _results.push(this.connections[connection.name] = new Connection(connection)); + } + return _results; + }; + + Robot.prototype.initDevices = function(devices) { + var device, _i, _len, _results; + Logger.info("Initializing devices..."); + if (devices == null) { + return; + } + devices = [].concat(devices); + _results = []; + for (_i = 0, _len = devices.length; _i < _len; _i++) { + device = devices[_i]; + Logger.info("Initializing device '" + device.name + "'..."); + device['robot'] = this; + _results.push(this.devices[device.name] = new Device(device)); + } + return _results; + }; + + Robot.prototype.start = function() { + this.startConnections(); + this.startDevices(); + return this.work.call(self, self); + }; + + Robot.prototype.startConnections = function() { + var connection, n, _ref, _results; + Logger.info("Starting connections..."); + _ref = this.connections; + _results = []; + for (n in _ref) { + connection = _ref[n]; + Logger.info("Starting connection '" + connection.name + "'..."); + connection.connect(); + _results.push(this[connection.name] = connection); + } + return _results; + }; + + Robot.prototype.startDevices = function() { + var device, n, _ref, _results; + Logger.info("Starting devices..."); + _ref = this.devices; + _results = []; + for (n in _ref) { + device = _ref[n]; + Logger.info("Starting device '" + device.name + "'..."); + device.start(); + _results.push(self[device.name] = device); + } + return _results; + }; + + Robot.requireAdaptor = function(adaptorName, connection) { + if (Robot.adaptors[adaptorName] != null) { + if (typeof Robot.adaptors[adaptorName] === 'string') { + Robot.adaptors[adaptorName] = require(Robot.adaptors[adaptorName]).adaptor({ + name: adaptorName, + connection: connection + }); + } + } else { + require("cylon-" + adaptorName).register(Robot); + Robot.adaptors[adaptorName] = require("cylon-" + adaptorName).adaptor({ + name: adaptorName, + connection: connection + }); + } + return Robot.adaptors[adaptorName]; + }; + + Robot.prototype.requireAdaptor = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return self.requireAdaptor.apply(self, args); + }; + + Robot.registerAdaptor = function(moduleName, adaptorName) { + if (self.adaptors[adaptorName] != null) { + return; + } + return self.adaptors[adaptorName] = moduleName; + }; + + Robot.prototype.registerAdaptor = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return self.registerAdaptor.apply(self, args); + }; + + Robot.requireDriver = function(driverName, device) { + if (Robot.drivers[driverName] != null) { + if (typeof Robot.drivers[driverName] === 'string') { + Robot.drivers[driverName] = require(Robot.drivers[driverName]).driver({ + device: device + }); + } + } else { + require("cylon-" + driverName).register(Robot); + Robot.drivers[driverName] = require("cylon-" + driverName).driver({ + device: device + }); + } + return Robot.drivers[driverName]; + }; + + Robot.prototype.requireDriver = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return self.requireDriver.apply(self, args); + }; + + Robot.registerDriver = function(moduleName, driverName) { + if (self.drivers[driverName] != null) { + return; + } + return self.drivers[driverName] = moduleName; + }; + + Robot.prototype.registerDriver = function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return self.registerDriver.apply(self, args); + }; + + return Robot; + + }).call(this); + +}).call(this); diff --git a/dist/utils.js b/dist/utils.js new file mode 100644 index 0000000..ffaa2df --- /dev/null +++ b/dist/utils.js @@ -0,0 +1,27 @@ +/* + * utils + * cylonjs.com + * + * Copyright (c) 2013 The Hybrid Group + * Licensed under the Apache 2.0 license. +*/ + + +(function() { + global.every = function(interval, action) { + return setInterval(action, interval); + }; + + global.after = function(delay, action) { + return setTimeout(action, delay); + }; + + Number.prototype.seconds = function() { + return this * 1000; + }; + + Number.prototype.second = function() { + return this.seconds(this); + }; + +}).call(this); diff --git a/examples/no_such_method.coffee b/examples/no_such_method.coffee new file mode 100644 index 0000000..cbceebc --- /dev/null +++ b/examples/no_such_method.coffee @@ -0,0 +1,21 @@ +class Person + constructor: (args = {}) -> + @name = args.name + @age = args.age + + noSuchMethod: (args) -> + console.log("You called method #{ args[0] } with params #{ args }, no such method exist") + + sayHi: (var1, var2, var3) -> + console.log("Saying Hi! #{var1}, #{var2}, #{var3}") + + execute: () -> + if typeof(this[arguments[0]]) is 'function' + this[arguments[0]].apply(this, Array.prototype.slice.call(arguments, 1)) + else + this.noSuchMethod(arguments) + +person = new Person({name: 'Leonidas', age:123}) + +person.execute('sayHi', 1, 2, 3) +person.execute('sayHello', 1, 2, 3) diff --git a/examples/sphero.coffee b/examples/sphero.coffee index b2fe699..237f106 100644 --- a/examples/sphero.coffee +++ b/examples/sphero.coffee @@ -23,6 +23,11 @@ Cylon.robot me.sphero.detectCollisions() - every 1.second(), -> me.sphero.roll(60, Math.floor(Math.random() * 360), 1) + color = 0x000050 + every 1.second(), -> + me.sphero.roll(60, Math.floor(Math.random() * 360), 1) + me.sphero.setRGB(color, true) + color += 0x005000 + color = 0x000050 if color > 0xFFFFFF .start() diff --git a/test/dist/specs/adaptor.spec.js b/test/dist/specs/adaptor.spec.js new file mode 100644 index 0000000..4324be4 --- /dev/null +++ b/test/dist/specs/adaptor.spec.js @@ -0,0 +1,20 @@ +(function() { + 'use strict'; + var Adaptor; + + Adaptor = source("adaptor"); + + describe("Adaptor", function() { + var adaptor; + adaptor = new Adaptor({ + name: "adaptive" + }); + it("should have a name", function() { + adaptor.should.have.keys('name'); + return adaptor.name.should.be.equal('adaptive'); + }); + it("should be able to connect"); + return it("should be able to disconnect"); + }); + +}).call(this); diff --git a/test/dist/specs/connection.spec.js b/test/dist/specs/connection.spec.js new file mode 100644 index 0000000..e678dbd --- /dev/null +++ b/test/dist/specs/connection.spec.js @@ -0,0 +1,61 @@ +(function() { + 'use strict'; + var Adaptor, Connection, Robot; + + Connection = source("connection"); + + Adaptor = source("adaptor"); + + Robot = source("robot"); + + describe("Connection", function() { + var adaptor, connection, requireAdaptor, robot; + robot = new Robot({ + name: 'me' + }); + adaptor = new Adaptor({ + name: 'loopback' + }); + requireAdaptor = sinon.stub(robot, 'requireAdaptor').returns(adaptor); + connection = new Connection({ + name: "connective", + adaptor: "loopback", + robot: robot + }); + it("should belong to a robot", function() { + return connection.robot.name.should.be.equal('me'); + }); + it("should have a name", function() { + return connection.name.should.be.equal('connective'); + }); + it("should have an adaptor", function() { + return connection.adaptor.name.should.be.equal('loopback'); + }); + it("should be able to require an external adaptor module"); + it("should be able to connect"); + it("should be able to disconnect"); + it('can alias methods with addProxy()', function() { + var proxyObject; + proxyObject = { + toString: function() { + return "[object ProxyObject]"; + } + }; + connection.addProxy(proxyObject, 'toString'); + assert(typeof connection.toString === 'function'); + return connection.toString().should.be.equal("[object ProxyObject]"); + }); + return it('can alias methods with arguments with addProxy()', function() { + var proxyObject; + proxyObject = { + returnString: function(string) { + return string; + } + }; + connection.addProxy(proxyObject, 'returnString'); + assert(typeof connection.returnString === 'function'); + return connection.returnString("testString").should.be.equal("testString"); + }); + }); + +}).call(this); diff --git a/test/dist/specs/cylon.spec.js b/test/dist/specs/cylon.spec.js new file mode 100644 index 0000000..d55d132 --- /dev/null +++ b/test/dist/specs/cylon.spec.js @@ -0,0 +1,38 @@ +(function() { + 'use strict'; + var cylon; + + cylon = source("cylon"); + + describe("Cylon", function() { + it("standard async test", function(done) { + var bool; + bool = false; + bool.should.be["false"]; + setTimeout(function() { + bool.should.be["false"]; + bool = true; + return bool.should.be["true"]; + }, 150); + return setTimeout(function() { + bool.should.be["true"]; + return done(); + }, 300); + }); + it("standard sync test", function() { + var data, obj; + data = []; + obj = { + id: 5, + name: 'test' + }; + data.should.be.empty; + data.push(obj); + data.should.have.length(1); + data[0].should.be.eql(obj); + return data[0].should.be.equal(obj); + }); + return it("should create a robot"); + }); + +}).call(this); diff --git a/test/dist/specs/device.spec.js b/test/dist/specs/device.spec.js new file mode 100644 index 0000000..4ba7b60 --- /dev/null +++ b/test/dist/specs/device.spec.js @@ -0,0 +1,60 @@ +(function() { + 'use strict'; + var Device, Driver, Robot; + + Device = source("device"); + + Driver = source("driver"); + + Robot = source("robot"); + + describe("Device", function() { + var device, driver, requireDriver, robot; + robot = new Robot({ + name: 'me' + }); + driver = new Driver({ + name: 'driving' + }); + requireDriver = sinon.stub(robot, 'requireDriver').returns(driver); + device = new Device({ + name: "devisive", + driver: 'driving', + robot: robot + }); + it("should belong to a robot", function() { + return device.robot.name.should.be.equal('me'); + }); + it("should have a name", function() { + return device.name.should.be.equal('devisive'); + }); + it("should use default connection if none specified"); + it("should use connection if one is specified"); + it("should require a driver", function() { + return requireDriver.should.be.called; + }); + it('can alias methods with addProxy()', function() { + var proxyObject; + proxyObject = { + toString: function() { + return "[object ProxyObject]"; + } + }; + device.addProxy(proxyObject, 'toString'); + assert(typeof device.toString === 'function'); + return device.toString().should.be.equal("[object ProxyObject]"); + }); + return it('can alias methods with arguments with addProxy()', function() { + var proxyObject; + proxyObject = { + returnString: function(string) { + return string; + } + }; + device.addProxy(proxyObject, 'returnString'); + assert(typeof device.returnString === 'function'); + return device.returnString("testString").should.be.equal("testString"); + }); + }); + +}).call(this); diff --git a/test/dist/specs/driver.spec.js b/test/dist/specs/driver.spec.js new file mode 100644 index 0000000..2338dad --- /dev/null +++ b/test/dist/specs/driver.spec.js @@ -0,0 +1,17 @@ +(function() { + 'use strict'; + var Driver; + + Driver = source("driver"); + + describe("Driver", function() { + var driver; + driver = new Driver({ + name: "driving" + }); + return it("should have a name", function() { + return driver.name.should.be.equal('driving'); + }); + }); + +}).call(this); diff --git a/test/dist/specs/logger.spec.js b/test/dist/specs/logger.spec.js new file mode 100644 index 0000000..1f3908a --- /dev/null +++ b/test/dist/specs/logger.spec.js @@ -0,0 +1,37 @@ +(function() { + 'use strict'; + source('logger'); + + describe('Logger', function() { + it("sets to NullLogger if false is provided", function() { + Logger.setup(false); + return Logger.toString().should.be.equal("NullLogger"); + }); + it("sets to BasicLogger if nothing is provided", function() { + Logger.setup(); + return Logger.toString().should.be.equal("BasicLogger"); + }); + it("allows for custom loggers", function() { + var logger; + logger = { + toString: function() { + return "CustomLogger"; + } + }; + Logger.setup(logger); + return Logger.toString().should.be.equal("CustomLogger"); + }); + return it('passes all received args to loggers', function() { + var logger; + logger = { + debug: function(message, level) { + return "Debug Level " + level + ": " + message; + } + }; + Logger.setup(logger); + Logger.debug("demo", 4).should.be.equal("Debug Level 4: demo"); + return Logger.setup(false); + }); + }); + +}).call(this); diff --git a/test/dist/specs/port.spec.js b/test/dist/specs/port.spec.js new file mode 100644 index 0000000..988eb38 --- /dev/null +++ b/test/dist/specs/port.spec.js @@ -0,0 +1,86 @@ +(function() { + 'use strict'; + var Port; + + Port = source("port"); + + describe("Port", function() { + describe("remote TCP port", function() { + var port; + port = new Port("192.168.0.1:8080"); + it("#port", function() { + return port.port.should.be.equal("8080"); + }); + it("#isTcp", function() { + return port.isTcp.should.be["true"]; + }); + it("#isSerial", function() { + return port.isSerial.should.be["false"]; + }); + it("#isPortless", function() { + return port.isPortless.should.be["false"]; + }); + return it("#toString", function() { + return port.toString().should.be.equal("192.168.0.1:8080"); + }); + }); + describe("local TCP port", function() { + var port; + port = new Port("5678"); + it("#port", function() { + return port.port.should.be.equal("5678"); + }); + it("#isTcp", function() { + return port.isTcp.should.be["true"]; + }); + it("#isSerial", function() { + return port.isSerial.should.be["false"]; + }); + it("#isPortless", function() { + return port.isPortless.should.be["false"]; + }); + return it("#toString", function() { + return port.toString().should.be.equal("localhost:5678"); + }); + }); + describe("serial port", function() { + var port; + port = new Port("/dev/tty.usb12345"); + it("#port", function() { + return port.port.should.be.equal("/dev/tty.usb12345"); + }); + it("#isTcp", function() { + return port.isTcp.should.be["false"]; + }); + it("#isSerial", function() { + return port.isSerial.should.be["true"]; + }); + it("#isPortless", function() { + return port.isPortless.should.be["false"]; + }); + return it("#toString", function() { + return port.toString().should.be.equal("/dev/tty.usb12345"); + }); + }); + return describe("portless", function() { + var port; + port = new Port; + it("#port", function() { + return assert(port.port === void 0); + }); + it("#isTcp", function() { + return port.isTcp.should.be["false"]; + }); + it("#isSerial", function() { + return port.isSerial.should.be["false"]; + }); + it("#isPortless", function() { + return port.isPortless.should.be["true"]; + }); + return it("#toString", function() { + return port.toString().should.be.equal("none"); + }); + }); + }); + +}).call(this); diff --git a/test/dist/specs/robot.spec.js b/test/dist/specs/robot.spec.js new file mode 100644 index 0000000..36c9368 --- /dev/null +++ b/test/dist/specs/robot.spec.js @@ -0,0 +1,42 @@ +(function() { + 'use strict'; + var Robot; + + Robot = source("robot"); + + source("logger"); + + Logger.setup(false); + + describe("Robot", function() { + var robot, testWork; + testWork = function() { + return Logger.info("hi"); + }; + robot = new Robot({ + name: "irobot", + work: testWork + }); + it("should have a name, if given", function() { + return robot.name.should.be.equal('irobot'); + }); + it("should have a random name, if not given", function() { + var r; + sinon.stub(Robot, 'randomName').returns('Electra'); + r = new Robot; + return r.name.should.be.equal('Electra'); + }); + it("should have work", function() { + return robot.work.should.be.equal(testWork); + }); + return it("should be able to start", function() { + var startConnections, startDevices; + startConnections = sinon.stub(robot, 'startConnections'); + startDevices = sinon.stub(robot, 'startDevices'); + robot.start(); + startConnections.should.have.been.called; + return startDevices.should.have.been.called; + }); + }); + +}).call(this); diff --git a/test/dist/specs/utils.spec.js b/test/dist/specs/utils.spec.js new file mode 100644 index 0000000..d2d3f8a --- /dev/null +++ b/test/dist/specs/utils.spec.js @@ -0,0 +1,18 @@ +(function() { + 'use strict'; + var utils; + + utils = source("utils"); + + describe("Utils", function() { + return describe("Monkeypatches Number", function() { + it("adds seconds() method", function() { + return 5..seconds().should.be.equal(5000); + }); + return it("adds second() method", function() { + return 1..second().should.be.equal(1000); + }); + }); + }); + +}).call(this);