Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik committed Sep 19, 2013
1 parent a75b1ed commit efc8b23
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.DS_Store
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docs
test
.DS_Store
.editorconfig
.gitattributes
.jshintrc
.travis.yml
Gruntfile.js
56 changes: 56 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*global module:false*/
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
// Task configuration.
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
unused: true,
boss: true,
eqnull: true,
node: true,
globals: {
jQuery: true,
window: true,
}
},
gruntfile: {
src: 'Gruntfile.js'
},
lib_test: {
src: ['jsfuck.js', 'lib/**/*.js', 'test/**/*.js']
}
},
nodeunit: {
files: ['test/**/*_test.js']
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
lib_test: {
files: '<%= jshint.lib_test.src %>',
tasks: ['jshint:lib_test', 'nodeunit']
}
}
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');

// Default task.
grunt.registerTask('default', ['jshint', 'nodeunit']);

};
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
],
"bugs": {
"url": "https://github.com/aemkei/jsfuck/issues"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jshint": "~0.6.4"
}
}
57 changes: 57 additions & 0 deletions test/jsfuck_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*jshint -W061 */
'use strict';

var JSFuck = require('../jsfuck.js').JSFuck,
test_encode = function (test, value) {
var encoded = JSFuck.encode(value),
unencoded = eval(encoded);

test.strictEqual(value, unencoded, 'encoding "' + value + '" failed');
};

exports['encode_tests'] = {
'encode numbers': function(test) {
for (var i=0; i<=10; i++) {
test_encode(test, i+"");
}
test.done();
},
'encode "false"': function(test) {
test_encode(test, 'false');
test.done();
},
'encode "falsefalsetrue"': function(test) {
test_encode(test, 'falsefalsetrue');
test.done();
},
'encode "a"': function(test) {
test_encode(test, 'a');
test.done();
},
'encode "ABCDEFGHIJKLMNOPQRSTUVWXYZ"': function(test) {
test_encode(test, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
test.done();
},
'encode "abcdefghijklmnopqrstuvwxyz"': function(test) {
test_encode(test, 'abcdefghijklmnopqrstuvwxyz');
test.done();
}
};

exports['tests'] = {
'encode 1': function(test) {
var encoded = JSFuck.encode('1');
test.equal(encoded, '[+!+[]]+[]');
test.done();
},
'encode 2': function(test) {
var encoded = JSFuck.encode('2');
test.equal(encoded, '[!+[]+!+[]]+[]');
test.done();
},
'encode 3': function(test) {
var encoded = JSFuck.encode('3');
test.equal(encoded, '[!+[]+!+[]+!+[]]+[]');
test.done();
}
};

0 comments on commit efc8b23

Please sign in to comment.