-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from JamesxX/developer
Merge developer branch
- Loading branch information
Showing
4 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
|
||
} | ||
|
||
}); | ||
|
||
}); | ||
|