diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f435c42 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: node_js + +# test on two node.js versions: 0.6 and 0.8 +node_js: + - 4.4.5 + +before_install: + - npm install -g mocha + - npm install -g chai + +branches: + only: + - master + - developer +script: mocha diff --git a/README.md b/README.md index 9e221b9..f088ec2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,11 @@ Swift-Cardinal Object Notation (SCON) A minimal node module allowing the reading and writing of data in the SCON format. The SCON format, created by Aritz J Beobide-Cardinal (ARitz Cracker) and James R Swift, is an extendable binary file format that was created to store data more efficiantly than the popular JSON standard. -Get the module here [![npm version](https://badge.fury.io/js/scon.svg)](https://badge.fury.io/js/scon) +[![NPM Version][npm-image]][npm-url] +[![NPM Downloads][downloads-image]][downloads-url] +[![Node.js Version][node-version-image]][node-version-url] +[![Build status][build-status-image]][build-status-url] +[![License][license-image]][license-url] ## Installation @@ -28,9 +32,25 @@ Add unit tests for any new or changed functionality. Lint and test your code. ## Release History +* 1.0.3 Added TravisCI intergration and tests * 1.0.2 Added support for NaN and 64 bit floats * 1.0.0 Added support for arrays, booleans, and nulls! * 0.9.2 ??? * 0.9.0 Major update in module structure, and added error handling. * 0.8.2 Removed left over tests. * 0.8.0 Initial release + +[npm-image]: https://img.shields.io/npm/v/scon.svg +[npm-url]: https://npmjs.org/package/scon + +[downloads-image]: https://img.shields.io/npm/dm/scon.svg +[downloads-url]: https://npmjs.org/package/scon + +[node-version-image]: https://img.shields.io/node/v/scon.svg +[node-version-url]: https://nodejs.org/en/download/ + +[build-status-image]: https://travis-ci.org/JamesxX/scon.svg +[build-status-url]: https://travis-ci.org/JamesxX/scon + +[license-image]: https://img.shields.io/npm/l/scon.svg?maxAge=2592000 +[license-url]: LICENSE \ No newline at end of file diff --git a/package.json b/package.json index 59ddf3c..1f9fb9f 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "scon", - "version": "1.0.2", + "version": "1.0.3", "description": "Read and write scon files", "main": "index.js", "scripts": { - "test": "mocha" + "test": "./node_modules/mocha/bin/mocha" }, "repository": { "type": "git", diff --git a/test/index.js b/test/index.js index 6137a9c..30365d6 100644 --- a/test/index.js +++ b/test/index.js @@ -1,10 +1,76 @@ var expect = require('chai').expect; var scon = require('../index.js'); -describe("Swift Binary Tag file format", function() { +function testKeyValueEquality( key, obj1, obj2 ){ + + if ( typeof obj1[ key ] == "object" ){ + + describe( "Testing member object '" + key + "'", function(){ + + for (var subkey in obj1[key]) { + testKeyValueEquality( subkey, obj1[key], obj2[key] ); + } + + }); + + } else if ( typeof obj1[ key ] == "number" && isNaN( obj1[ key ] ) ) { + + it( "Key " + key + " should have the same value in both objects (NaN)", function(){ + expect( obj2[ key ] ).to.be.NaN; + }); + + }else { + + it( "Key " + key + " should have the same value in both objects", function(){ + expect( obj1[ key ] ).to.equal( obj2[ key ] ); + }); + + } + +} + +describe("Swift-Cardinal Object Notation file format", function() { + + var testCase = { + hello: "world!!", + hi: "bye", + five: NaN, + pi: 3.14159, + object: { + amazing:true, + ['true']: { + mind:"fuck" + } + }, + six: 6, + arr: ["wan","too","free",{"for":4},[1,2,3,4,5]] + }; + + it( "should not throw errors when encoding", function(){ + expect( function(){scon.encode( testCase )} ).to.not.throw( scon.Exception ); + }); + + var encoded = scon.encode( testCase ); it("should write the magic number", function(){ - expect(scon.encode( {} ).result.substring( 0, scon.magicNumber.length ) ).to.equal( scon.magicNumber ); - }) + expect( encoded.result.substring( 0, scon.magicNumber.length ) ).to.equal( scon.magicNumber ); + }); + + it( "should not throw errors when decoding", function(){ + expect( function(){scon.decode( encoded.result )} ).to.not.throw( scon.Exception ); + }); + + var decoded = scon.decode( encoded.result ); + + describe( "testing equality of testCase and decoded object", function(){ + + for (var key in testCase) { + + testKeyValueEquality( key, testCase, decoded.result ); + + } + + }); }); +