Permalink
Browse files

Testling start

  • Loading branch information...
1 parent 623c48b commit d35a51f977d09bee6f8d803224d51716612be79e @bvalosek committed Jan 17, 2014
Showing with 106 additions and 33 deletions.
  1. +0 −1 .gitignore
  2. +0 −2 .travis.yml
  3. +43 −22 README.md
  4. +4 −4 index.js
  5. +26 −4 package.json
  6. +33 −0 test/extends.js
View
@@ -1,3 +1,2 @@
node_modules
-test/bin
.tern-port
View
@@ -1,7 +1,5 @@
language: node_js
node_js:
- "0.10"
-before_script:
- - npm install -g grunt-cli
notifications:
email: false
View
@@ -5,18 +5,23 @@
Low-level type-centric utility functions for Javascript.
+[![browser support](https://ci.testling.com/bvalosek/typedef.png)](https://ci.testling.com/bvalosek/typedef)
+
## Installation
-**Typedef** is meant to be used with [Browserify](http://browserify.org/) on
-the client (or just as a normal Node module), so install it with npm:
+**Typedef** can be used on the server with NodeJS or on the client, built with
+[Browserify](http://browserify.org/), so install with npm:
```
npm install typedef
```
## Usage
-### extends
+### extends(`Child`, `Base`)
+
+While traditionally, favoring composition over inheritance in Javascript is
+typically the way to go, classic inheritance can be useful if used sparingly.
This is the `extends` function that is used in Typescript, Coffeescript, ES6
compilers, etc. It uses prototypes to setup something similar to to classical
@@ -71,34 +76,50 @@ foo instanceof Base;
// true
```
-## Tern Support
+### mixin(`Constructor`, `Mixin`)
-The library files are all decorated with [JSDoc](http://usejsdoc.org/)-style
-annotations that work great with the [Tern](http://ternjs.net/) code interence
-system. Combined with the Node plugin (see this project's `.tern-project`
-file), you can have intelligent autocomplete for methods in this library.
+Class composition method. Mixin methods into `Constructor.prototype`.
-## Testing
+If `Mixin` is a constructor function (class), then mixin all static properties
+into `Constructor`, and everything on `Mixin.prototype` to
+`Constructor.prototype`. If `Mixin` is just a Plain Old Object, then simply add
+the members of `Mixin` to `Contructor.prototype`.
-Unit testing is done by [QUnit](http://qunitjs.com/) and can be run from the
-command line via [Grunt](http://gruntjs.com/).
+### getArguments(`f`) and getName(`f`)
-Testing requires [node/npm](http://nodejs.org) and
-[grunt-cli](https://github.com/gruntjs/grunt-cli) to be installed on your
-system.
+Get the name of all the parameters or name for function `f`.
-To ensure you have the required apps:
+```javascript
+var getArguments = require('typedef').getArguments;
+var getName = require('typedef').getName;
-```
-npm install -g grunt-cli
-```
+function foo(a, b, c)
+{
+ ...
+}
-Then install all the dev dependencies and run the tests:
+getArguments(foo);
+// ['a', 'b', 'c']
+getName(foo);
+// 'foo'
```
-npm install
-grunt test
-```
+
+## Tern Support
+
+The library files are all decorated with [JSDoc3](http://usejsdoc.org/)-style
+annotations that work great with the [Tern](http://ternjs.net/) code inference
+system. Combined with the Node plugin (see this project's `.tern-project`
+file), you can have intelligent autocomplete for methods in this library.
+
+## Testing
+
+Testing is done with [Tape](http://github.com/substack/tape) and can be run
+with the command `npm test`.
+
+Automated CI cross-browser testing is provided by
+[Testling](http://ci.testling.com/bvalosek/typedef).
+
## License
Copyright 2014 Brandon Valosek
View
@@ -1,9 +1,9 @@
module.exports = {
- extends : require('./lib/extends.js'),
- mixin : require('./lib/mixin.js'),
- getArguments : require('./lib/getArguments.js'),
- getName : require('./lib/getName.js')
+ 'extends' : require('./lib/extends.js'),
+ 'mixin' : require('./lib/mixin.js'),
+ 'getArguments' : require('./lib/getArguments.js'),
+ 'getName' : require('./lib/getName.js')
};
View
@@ -10,17 +10,39 @@
"classes",
"mixins"
],
+ "author": {
+ "name": "Brandon Valosek",
+ "email": "bvalosek@gmail.com",
+ "url": "http://brandon.is/awesome"
+ },
"directories": {
"test": "test"
},
"scripts": {
- "test": "grunt test"
+ "test": "tape test/*.js"
+ },
+ "readmeFilename": "README.md",
+ "main": "index.js",
+ "license": "MIT",
+ "devDependencies": {
+ "tape": "~2.3.2"
},
"repository": {
"type": "git",
"url": "git@github.com:bvalosek/typedef.git"
},
- "author": "Brandon Valosek",
- "license": "MIT",
- "readmeFilename": "README.md"
+ "testling": {
+ "files": "test/*.js",
+ "browsers": [
+ "ie/6..latest",
+ "chrome/28..canary",
+ "firefox/23..nightly",
+ "safari/5.1..latest",
+ "opera/latest",
+ "opera/next",
+ "iphone/latest",
+ "ipad/latest",
+ "android-browser/latest"
+ ]
+ }
}
View
@@ -0,0 +1,33 @@
+var extends_ = require('../lib/extends.js');
+var test = require('tape');
+
+test('Operator instanceof semantics', function(t) {
+ t.plan(10);
+
+ function Parent() { }
+
+ function Child() { }
+ extends_(Child, Parent);
+
+ function Sibling() { }
+ extends_(Sibling, Parent);
+
+ function GrandChild() { }
+ extends_(GrandChild, Child);
+
+ function Cousin() { }
+ extends_(Cousin, Sibling);
+
+ t.ok(new Parent() instanceof Parent, 'parent is parent');
+ t.ok(new Child() instanceof Parent, 'child is parent');
+ t.ok(new Child() instanceof Child, 'child is child');
+ t.ok(new GrandChild() instanceof Parent, 'grandchild is parent');
+ t.ok(new GrandChild() instanceof Child, 'grandchild is child');
+ t.ok(new GrandChild() instanceof GrandChild, 'grandchild is grandchild');
+
+ t.notOk(new Sibling() instanceof Child, 'child is not sibling');
+ t.notOk(new Sibling() instanceof GrandChild, 'child is not granchild');
+ t.notOk(new Cousin() instanceof GrandChild, 'cousin is not granchild');
+ t.notOk(new Cousin() instanceof Child, 'cousin is not child');
+
+});

0 comments on commit d35a51f

Please sign in to comment.