Add simple tests for format

This commit is contained in:
Paul Holden 2016-11-25 22:54:14 -05:00
parent 2808f5d8a2
commit 790fa3cbab
4 changed files with 63 additions and 10 deletions

3
.babelrc Normal file
View file

@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}

View file

@ -6,7 +6,7 @@
"scripts": {
"build": "rollup -c",
"build-closure": "rollup -c && java -jar node_modules/google-closure-compiler/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --warning_level=VERBOSE --language_in=ECMASCRIPT6_STRICT --language_out=ECMASCRIPT5_STRICT --js build/n64.modules.js --js_output_file n64.min.js --source_map_format=V3 --create_source_map n64.min.js.map --externs js/externs/jquery-3.1.js --externs js/externs/localStorage.js --externs js/externs/stats.js --externs js/externs/webgl-debug.js && echo '//@ sourceMappingURL=n64.min.js.map' >> n64.min.js",
"test": "npm run compile && mocha --compilers js:babel-core/register"
"test": "mocha --compilers js:babel-core/register"
},
"repository": {
"type": "git",
@ -23,6 +23,8 @@
},
"homepage": "https://github.com/hulkholden/n64js",
"devDependencies": {
"babel-core": "^6.18.2",
"babel-preset-es2015": "^6.18.0",
"mocha": "^3.2.0",
"rollup": "^0.36.4"
},

57
test/format.js Normal file
View file

@ -0,0 +1,57 @@
import * as format from "../src/format.js";
const assert = require('assert');
describe('format', () => {
describe('padString', () => {
it('should pad the number to the correct length', () => {
assert.equal('7', format.padString(7, 1));
assert.equal('07', format.padString(7, 2));
assert.equal('007', format.padString(7, 3));
});
it('should not truncate values', () => {
assert.equal('700', format.padString(700, 1));
});
});
describe('toHex', () => {
it('should return correctly formatted strings', () => {
assert.equal('0', format.toHex(0));
assert.equal('1', format.toHex(0x1));
assert.equal('12', format.toHex(0x12));
assert.equal('123', format.toHex(0x123));
assert.equal('1234', format.toHex(0x1234));
assert.equal('12345', format.toHex(0x12345));
assert.equal('123456', format.toHex(0x123456));
assert.equal('1234567', format.toHex(0x1234567));
assert.equal('12345678', format.toHex(0x12345678));
assert.equal('deadbeef', format.toHex(0xdeadbeef));
});
});
describe('toString8', () => {
it('should return correctly formatted strings', () => {
assert.equal('0x00', format.toString8(0));
assert.equal('0xff', format.toString8(0xff));
});
});
describe('toString16', () => {
it('should return correctly formatted strings', () => {
assert.equal('0x0000', format.toString16(0));
assert.equal('0x00ff', format.toString16(0xff));
assert.equal('0xffff', format.toString16(0xffff));
});
});
describe('toString32', () => {
it('should return correctly formatted strings', () => {
assert.equal('0x00000000', format.toString32(0));
assert.equal('0x000000ff', format.toString32(0xff));
assert.equal('0xffffffff', format.toString32(0xffffffff));
});
});
describe('toString64', () => {
it('should return correctly formatted strings', () => {
assert.equal('0x0000000000000000', format.toString64(0, 0));
assert.equal('0x00000000000000ff', format.toString64(0, 0xff));
assert.equal('0xffffffffffffffff', format.toString64(0xffffffff, 0xffffffff));
});
});
});

View file

@ -1,9 +0,0 @@
const assert = require('assert');
describe('Array', () => {
describe('#indexOf()', () => {
it('should return -1 when the value is not present', () => {
assert.equal(-1, [1,2,3].indexOf(4));
});
});
});