diff --git a/.gitignore b/.gitignore index 496ee2ca..28f1ba75 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +node_modules .DS_Store \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..11078e61 --- /dev/null +++ b/.npmignore @@ -0,0 +1,8 @@ +docs +test +.DS_Store +.editorconfig +.gitattributes +.jshintrc +.travis.yml +Gruntfile.js \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..8ea43cf7 --- /dev/null +++ b/Gruntfile.js @@ -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']); + +}; diff --git a/package.json b/package.json index 77f9c1e6..2630bf3b 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/jsfuck_test.js b/test/jsfuck_test.js new file mode 100644 index 00000000..5072759d --- /dev/null +++ b/test/jsfuck_test.js @@ -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(); + } +}; \ No newline at end of file