This repository has been archived by the owner on Nov 15, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now using tabs for indentation, following jQuery core style guidelines,
closes #82.
- Loading branch information
Showing
5 changed files
with
141 additions
and
130 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,11 @@ | ||
softTabs = false | ||
tabSize = 2 | ||
|
||
[ text.plain ] | ||
softWrap = true | ||
wrapColumn = "Use Window Frame" | ||
softTabs = true | ||
tabSize = 4 | ||
|
||
[ "*.md" ] | ||
fileType = "text.plain" |
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,24 +1,24 @@ | ||
var http = require('http'), | ||
url = require('url'), | ||
path = require('path'), | ||
fs = require('fs'); | ||
var http = require('http'); | ||
var url = require('url'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
http.createServer(function(request, response) { | ||
var uri = url.parse(request.url).pathname, | ||
filename = path.join(process.cwd(), uri); | ||
var uri = url.parse(request.url).pathname; | ||
var filename = path.join(process.cwd(), uri); | ||
|
||
fs.readFile(filename, 'binary', function(err, file) { | ||
if (err) { | ||
response.writeHead(500, { 'Content-Type': 'text/plain' }); | ||
response.write(err + '\n'); | ||
response.end(); | ||
return; | ||
} | ||
fs.readFile(filename, 'binary', function(err, file) { | ||
if (err) { | ||
response.writeHead(500, { 'Content-Type': 'text/plain' }); | ||
response.write(err + '\n'); | ||
response.end(); | ||
return; | ||
} | ||
|
||
response.writeHead(200); | ||
response.write(file, 'utf-8'); | ||
response.end(); | ||
}); | ||
response.writeHead(200); | ||
response.write(file, 'utf-8'); | ||
response.end(); | ||
}); | ||
}).listen(8124, '0.0.0.0'); | ||
|
||
console.log('Test suite at http://0.0.0.0:8124/test.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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>jquery.cookie Test Suite</title> | ||
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css"> | ||
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> | ||
<script src="http://code.jquery.com/qunit/qunit-git.js"></script> | ||
<script src="jquery.cookie.js"></script> | ||
<script src="test.js"></script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">jquery.cookie Test Suite</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>jquery.cookie Test Suite</title> | ||
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css"> | ||
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> | ||
<script src="http://code.jquery.com/qunit/qunit-git.js"></script> | ||
<script src="jquery.cookie.js"></script> | ||
<script src="test.js"></script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">jquery.cookie Test Suite</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</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 |
---|---|---|
@@ -1,126 +1,126 @@ | ||
var before = { | ||
setup: function () { | ||
cookies = document.cookie.split('; ') | ||
for (var i = 0, c; (c = (cookies)[i]) && (c = c.split('=')[0]); i++) { | ||
document.cookie = c + '=; expires=' + new Date(0).toUTCString(); | ||
} | ||
|
||
$.cookie.defaults = {}; | ||
} | ||
setup: function () { | ||
cookies = document.cookie.split('; ') | ||
for (var i = 0, c; (c = (cookies)[i]) && (c = c.split('=')[0]); i++) { | ||
document.cookie = c + '=; expires=' + new Date(0).toUTCString(); | ||
} | ||
|
||
$.cookie.defaults = {}; | ||
} | ||
}; | ||
|
||
|
||
module('read', before); | ||
|
||
test('simple value', 1, function () { | ||
document.cookie = 'c=v'; | ||
equal($.cookie('c'), 'v', 'should return value'); | ||
document.cookie = 'c=v'; | ||
equal($.cookie('c'), 'v', 'should return value'); | ||
}); | ||
|
||
test('empty value', 1, function () { | ||
// IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which | ||
// resulted in a bug while reading such a cookie. | ||
$.cookie('c', ''); | ||
equal($.cookie('c'), '', 'should return value'); | ||
// IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, which | ||
// resulted in a bug while reading such a cookie. | ||
$.cookie('c', ''); | ||
equal($.cookie('c'), '', 'should return value'); | ||
}); | ||
|
||
test('not existing', 1, function () { | ||
equal($.cookie('whatever'), null, 'should return null'); | ||
equal($.cookie('whatever'), null, 'should return null'); | ||
}); | ||
|
||
test('decode', 1, function () { | ||
document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); | ||
equal($.cookie(' c'), ' v', 'should decode key and value'); | ||
document.cookie = encodeURIComponent(' c') + '=' + encodeURIComponent(' v'); | ||
equal($.cookie(' c'), ' v', 'should decode key and value'); | ||
}); | ||
|
||
test('raw: true', 1, function () { | ||
document.cookie = 'c=%20v'; | ||
equal($.cookie('c', { raw: true }), '%20v', 'should not decode value'); | ||
document.cookie = 'c=%20v'; | ||
equal($.cookie('c', { raw: true }), '%20v', 'should not decode value'); | ||
}); | ||
|
||
test('[] used in name', 1, function () { | ||
document.cookie = 'c[999]=foo'; | ||
equal($.cookie('c[999]'), 'foo', 'should return value'); | ||
document.cookie = 'c[999]=foo'; | ||
equal($.cookie('c[999]'), 'foo', 'should return value'); | ||
}); | ||
|
||
test('embedded equals', 1, function () { | ||
$.cookie('c', 'foo=bar', { raw: true }); | ||
equal($.cookie('c', { raw: true }), 'foo=bar', 'should include the entire value'); | ||
$.cookie('c', 'foo=bar', { raw: true }); | ||
equal($.cookie('c', { raw: true }), 'foo=bar', 'should include the entire value'); | ||
}); | ||
|
||
test('defaults', 1, function () { | ||
document.cookie = 'c=%20v'; | ||
$.cookie.defaults.raw = true; | ||
equal($.cookie('c'), '%20v', 'should use raw from defaults'); | ||
document.cookie = 'c=%20v'; | ||
$.cookie.defaults.raw = true; | ||
equal($.cookie('c'), '%20v', 'should use raw from defaults'); | ||
}); | ||
|
||
|
||
module('write', before); | ||
|
||
test('String primitive', 1, function () { | ||
$.cookie('c', 'v'); | ||
equal($.cookie('c'), 'v', 'should write value'); | ||
$.cookie('c', 'v'); | ||
equal($.cookie('c'), 'v', 'should write value'); | ||
}); | ||
|
||
test('String object', 1, function () { | ||
$.cookie('c', new String('v')); | ||
equal($.cookie('c'), 'v', 'should write value'); | ||
$.cookie('c', new String('v')); | ||
equal($.cookie('c'), 'v', 'should write value'); | ||
}); | ||
|
||
test('value "[object Object]"', 1, function () { | ||
$.cookie('c', '[object Object]'); | ||
equal($.cookie('c'), '[object Object]', 'should write value'); | ||
$.cookie('c', '[object Object]'); | ||
equal($.cookie('c'), '[object Object]', 'should write value'); | ||
}); | ||
|
||
test('number', 1, function () { | ||
$.cookie('c', 1234); | ||
equal($.cookie('c'), '1234', 'should write value'); | ||
$.cookie('c', 1234); | ||
equal($.cookie('c'), '1234', 'should write value'); | ||
}); | ||
|
||
test('expires option as days from now', 1, function() { | ||
var sevenDaysFromNow = new Date(); | ||
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); | ||
equal($.cookie('c', 'v', { expires: 7 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), | ||
'should write the cookie string with expires'); | ||
var sevenDaysFromNow = new Date(); | ||
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); | ||
equal($.cookie('c', 'v', { expires: 7 }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), | ||
'should write the cookie string with expires'); | ||
}); | ||
|
||
test('expires option as Date instance', 1, function() { | ||
var sevenDaysFromNow = new Date(); | ||
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); | ||
equal($.cookie('c', 'v', { expires: sevenDaysFromNow }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), | ||
'should write the cookie string with expires'); | ||
var sevenDaysFromNow = new Date(); | ||
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7); | ||
equal($.cookie('c', 'v', { expires: sevenDaysFromNow }), 'c=v; expires=' + sevenDaysFromNow.toUTCString(), | ||
'should write the cookie string with expires'); | ||
}); | ||
|
||
test('invalid expires option (in the past)', 1, function() { | ||
var yesterday = new Date(); | ||
yesterday.setDate(yesterday.getDate() - 1); | ||
$.cookie('c', 'v', { expires: yesterday }); | ||
equal($.cookie('c'), null, 'should not save already expired cookie'); | ||
var yesterday = new Date(); | ||
yesterday.setDate(yesterday.getDate() - 1); | ||
$.cookie('c', 'v', { expires: yesterday }); | ||
equal($.cookie('c'), null, 'should not save already expired cookie'); | ||
}); | ||
|
||
test('return value', 1, function () { | ||
equal($.cookie('c', 'v'), 'c=v', 'should return written cookie string'); | ||
equal($.cookie('c', 'v'), 'c=v', 'should return written cookie string'); | ||
}); | ||
|
||
test('raw option set to true', 1, function () { | ||
equal($.cookie('c', ' v', { raw: true }).split('=')[1], | ||
' v', 'should not encode'); | ||
equal($.cookie('c', ' v', { raw: true }).split('=')[1], | ||
' v', 'should not encode'); | ||
}); | ||
|
||
test('defaults', 1, function () { | ||
$.cookie.defaults.raw = true; | ||
equal($.cookie('c', ' v').split('=')[1], ' v', 'should use raw from defaults'); | ||
$.cookie.defaults.raw = true; | ||
equal($.cookie('c', ' v').split('=')[1], ' v', 'should use raw from defaults'); | ||
}); | ||
|
||
|
||
module('delete', before); | ||
|
||
test('delete', 2, function () { | ||
document.cookie = 'c=v'; | ||
$.cookie('c', null); | ||
equal(document.cookie, '', 'should delete with null as value'); | ||
document.cookie = 'c=v'; | ||
$.cookie('c', null); | ||
equal(document.cookie, '', 'should delete with null as value'); | ||
|
||
document.cookie = 'c=v'; | ||
$.cookie('c', undefined); | ||
equal(document.cookie, '', 'should delete with undefined as value'); | ||
document.cookie = 'c=v'; | ||
$.cookie('c', undefined); | ||
equal(document.cookie, '', 'should delete with undefined as value'); | ||
}); |