-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5efec84
commit be17e51
Showing
3 changed files
with
95 additions
and
0 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,13 @@ | ||
{ | ||
"boss": true, | ||
"undef": false, | ||
"white": false, | ||
"eqeqeq": false, | ||
"browser": true, | ||
"devel": true, | ||
"bitwise": false, | ||
"quotmark": false, | ||
"camelcase": false, | ||
"strict": false, | ||
"trailing": true | ||
} |
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Tests</title> | ||
<script src="../kwargs.js"></script> | ||
<script src="test.js"></script> | ||
</head> | ||
<body> | ||
Check the console for test results | ||
</body> | ||
</html> |
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,70 @@ | ||
(function(exports){ | ||
var success = 0; | ||
var fail = 0; | ||
exports.showComplete = function(){ | ||
if(fail === 0){ | ||
console.log('%c %s tests completed, all successful ', 'background:green;color:white;font-size:16px;font-weight:bold;', success); | ||
}else{ | ||
console.log('%c %s tests completed, %s failed ', 'background:red;color:white;font-size:16px;font-weight:bold;', success, fail); | ||
} | ||
}; | ||
|
||
exports.assertText = function(value, check, name){ | ||
if(value != check){ | ||
console.error('"%s" != "%s" Assertion Error on %s', value, check, name); | ||
fail++; | ||
}else{ | ||
console.log('passed: "%s".', name); | ||
success++; | ||
} | ||
}; | ||
|
||
})(this); | ||
|
||
/* regular arguments */ | ||
var test1 = function(arg1, arg2, arg3){ | ||
return arg1 + arg2 + arg3; | ||
}.kwargs(); | ||
|
||
assertText(test1('a','b','c'), 'abc', 'Regular arguments'); | ||
assertText(test1({ | ||
arg1: 'a', | ||
arg2: 'b', | ||
arg3: 'c' | ||
}), 'abc', 'Options method'); | ||
assertText(test1('a', { | ||
arg2: 'b', | ||
arg3: 'c' | ||
}), 'abc', 'Both regular and kwargs'); | ||
|
||
|
||
/* Defaults without kwargs */ | ||
var greeting = function(name){ | ||
return "Hello " + name; | ||
}.kwargs({ name: 'World' }); | ||
|
||
assertText(greeting('Frank'), "Hello Frank", 'Defaults with argument'); | ||
assertText(greeting(), "Hello World", 'Defaults without arguments'); | ||
|
||
/* complex example */ | ||
var printname = function(firstName, lastName, middleName, prefix, suffix){ | ||
var name = []; | ||
if(prefix){ | ||
name.push(prefix); | ||
} | ||
name.push(firstName); | ||
if(middleName){ | ||
name.push(middleName); | ||
} | ||
name.push(lastName); | ||
if(suffix){ | ||
name.push(suffix); | ||
} | ||
return name.join(' '); | ||
}.kwargs(); | ||
|
||
assertText(printname('John', 'Doe', { suffix:'Ph.D.' }), "John Doe Ph.D.", "Complex example 1"); | ||
assertText(printname('Max', 'Fightmaster', { prefix: 'Staff Sgt.' }), "Staff Sgt. Max Fightmaster", "Complex example 2"); | ||
assertText(printname('Isaac', 'Newton', { prefix: 'Sir', suffix: 'PRS MP'}), "Sir Isaac Newton PRS MP", "Complex example 3"); | ||
|
||
showComplete(); |