Permalink
Browse files

improving tests

  • Loading branch information...
1 parent a99349b commit 61114467f25ea5d28a8423dee1de1140da731f03 @aogriffiths committed Feb 7, 2013
@@ -0,0 +1 @@
+*.sw?
@@ -0,0 +1,8 @@
+.git
+.gitignore
+qunit.css
+qunit.js
+index.html
+test.js
+jslitmus.js
+jsonpatch.coffee
@@ -0,0 +1,27 @@
+Copyright (c) 2011 Byron Ruth
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of Django nor the names of its contributors may be used
+ to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,125 @@
+# jsonpatch.js
+
+Library to apply JSON Patches in JavaScript
+http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-08
+
+jsonpatch.js works as in the browser as a script, as a Node module and as an
+AMD module.
+
+## Install
+
+**Bower**
+
+```
+bower install json-patch
+```
+
+**NPM**
+
+```
+npm install json-patch
+```
+
+**Note: at this time, all operations are applied in-place.**
+
+## Methods
+
+**`jsonpatch.apply(document, patch)`**
+
+Applies a patch to the document
+
+**`jsonpatch.compile(patch)`**
+
+Compiles a patch and returns a function that takes a document to apply the patch to.
+
+## Patch Operations
+
+### Add
+
+Patch syntax: `{op: 'add', path: <path>, value: <value>}`
+
+```javascript
+// Add property, result: {foo: 'bar'}
+jsonpatch.apply({}, [{op: 'add', path: '/foo', value: 'bar'}]);
+
+// Add array element, result: {foo: [1, 2, 3]}
+jsonpatch.apply({foo: [1, 3]}, [{op: 'add', path: '/foo/1', value: 2}]);
+
+// Complex, result: {foo: [{bar: 'baz'}]}
+jsonpatch.apply({foo: [{}]}, [{op: 'add', path: '/foo/0/bar', value: 'baz'}]);
+```
+
+### Remove
+
+Patch syntax: `{op: 'remove', path: <path>}`
+
+```javascript
+// Remove property, result: {}
+jsonpatch.apply({foo: 'bar'}, [{op: 'remove', path: '/foo'}]);
+
+// Remove array element, result: {foo: [1, 3]}
+jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'remove', path: '/foo/1'}]);
+
+// Complex, result: {foo: [{}]}
+jsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'remove', path: '/foo/0/bar'}]);
+```
+
+### Replace
+
+Patch syntax: `{op: 'replace', path: <path>, value: <value>}`
+
+```javascript
+// Replace property, result: {foo: 1}
+jsonpatch.apply({foo: 'bar'}, [{op: 'replace', path: '/foo', value: 1}]);
+
+// Repalce array element, result: {foo: [1, 4, 3]}
+jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'replace', path: '/foo/1', value: 4}]);
+
+// Complex, result: {foo: [{bar: 1}]}
+jsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'replace', path: '/foo/0/bar', value: 1}]);
+```
+
+### Move
+
+Patch syntax: `{op: 'move', from: <path>, path: <path>}`
+
+```javascript
+// Move property, result {bar: [1, 2, 3]}
+jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'move', from: '/foo', path: '/bar'}]);
+```
+
+### Copy
+
+Patch syntax: `{op: 'copy', from: <path>, path: <path>}`
+
+```javascript
+// Copy property, result {foo: [1, 2, 3], bar: 2}
+jsonpatch.apply({foo: [1, 2, 3]}, [{op: 'copy', from: '/foo/1', path: '/bar'}]);
+```
+
+### Test
+
+Patch syntax: `{op: 'test', path: <path>, value: <value>}`
+
+```javascript
+// Test equality of property to value, result: true
+jsonpatch.apply({foo: 'bar'}, [{op: 'test', path: '/foo', value: 'bar'}]
+```
+
+## Error Types
+
+**`JSONPatchError`**
+
+Base error type which all patch errors extend from.
+
+**`InvalidPointerError`**
+
+Thrown when the pointer is invalid.
+
+**`InvalidPatchError`**
+
+Thrown when the patch itself has an invalid syntax.
+
+**`PatchConflictError`**
+
+Thrown when there is a conflic with applying the patch to the document.
@@ -0,0 +1,15 @@
+{
+ "name": "json-patch",
+ "version": "0.0.0",
+ "main": "./jsonpatch.js",
+ "gitHead": "12f9ea3a7b3aaa2b94fac746763bd7715863ac09",
+ "readme": "# jsonpatch.js\n\nLibrary to apply JSON Patches in JavaScript\nhttp://tools.ietf.org/html/draft-ietf-appsawg-json-patch-08\n\njsonpatch.js works as in the browser as a script, as a Node module and as an\nAMD module.\n\n## Install\n\n**Bower**\n\n```\nbower install json-patch\n```\n\n**NPM**\n\n```\nnpm install json-patch\n```\n\n**Note: at this time, all operations are applied in-place.**\n\n## Methods\n\n**`jsonpatch.apply(document, patch)`**\n\nApplies a patch to the document\n\n**`jsonpatch.compile(patch)`**\n\nCompiles a patch and returns a function that takes a document to apply the patch to.\n\n## Patch Operations\n\n### Add\n\nPatch syntax: `{op: 'add', path: <path>, value: <value>}`\n\n```javascript\n// Add property, result: {foo: 'bar'}\njsonpatch.apply({}, [{op: 'add', path: '/foo', value: 'bar'}]);\n\n// Add array element, result: {foo: [1, 2, 3]}\njsonpatch.apply({foo: [1, 3]}, [{op: 'add', path: '/foo/1', value: 2}]);\n\n// Complex, result: {foo: [{bar: 'baz'}]}\njsonpatch.apply({foo: [{}]}, [{op: 'add', path: '/foo/0/bar', value: 'baz'}]);\n```\n\n### Remove\n\nPatch syntax: `{op: 'remove', path: <path>}`\n\n```javascript\n// Remove property, result: {}\njsonpatch.apply({foo: 'bar'}, [{op: 'remove', path: '/foo'}]);\n\n// Remove array element, result: {foo: [1, 3]}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'remove', path: '/foo/1'}]);\n\n// Complex, result: {foo: [{}]}\njsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'remove', path: '/foo/0/bar'}]);\n```\n\n### Replace\n\nPatch syntax: `{op: 'replace', path: <path>, value: <value>}`\n\n```javascript\n// Replace property, result: {foo: 1}\njsonpatch.apply({foo: 'bar'}, [{op: 'replace', path: '/foo', value: 1}]);\n\n// Repalce array element, result: {foo: [1, 4, 3]}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'replace', path: '/foo/1', value: 4}]);\n\n// Complex, result: {foo: [{bar: 1}]}\njsonpatch.apply({foo: [{bar: 'baz'}]}, [{op: 'replace', path: '/foo/0/bar', value: 1}]);\n```\n\n### Move\n\nPatch syntax: `{op: 'move', from: <path>, path: <path>}`\n\n```javascript\n// Move property, result {bar: [1, 2, 3]}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'move', from: '/foo', path: '/bar'}]);\n```\n\n### Copy\n\nPatch syntax: `{op: 'copy', from: <path>, path: <path>}`\n\n```javascript\n// Copy property, result {foo: [1, 2, 3], bar: 2}\njsonpatch.apply({foo: [1, 2, 3]}, [{op: 'copy', from: '/foo/1', path: '/bar'}]);\n```\n\n### Test\n\nPatch syntax: `{op: 'test', path: <path>, value: <value>}`\n\n```javascript\n// Test equality of property to value, result: true\njsonpatch.apply({foo: 'bar'}, [{op: 'test', path: '/foo', value: 'bar'}]\n```\n\n## Error Types\n\n**`JSONPatchError`**\n\nBase error type which all patch errors extend from.\n\n**`InvalidPointerError`**\n\nThrown when the pointer is invalid.\n\n**`InvalidPatchError`**\n\nThrown when the patch itself has an invalid syntax.\n\n**`PatchConflictError`**\n\nThrown when there is a conflic with applying the patch to the document.\n",
+ "readmeFilename": "README.md",
+ "_id": "json-patch@0.3.0",
+ "description": "Library to apply JSON Patches in JavaScript http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-08",
+ "commit": "12f9ea3a7b3aaa2b94fac746763bd7715863ac09",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/bruth/jsonpatch-js"
+ }
+}
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="UTF-8" />
+ <title>QUnit Test Suite</title>
+ <link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
+ <script type="text/javascript" src="qunit.js"></script>
+ <script type="text/javascript" src="jsonpatch.js"></script>
+ <script type="text/javascript" src="jslitmus.js"></script>
+ <script type="text/javascript" src="test.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">QUnit Test Suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"></div>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit 6111446

Please sign in to comment.