You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2009/07/10 16:17:54 UTC

svn commit: r792959 - /couchdb/trunk/share/www/script/test/basics.js

Author: jan
Date: Fri Jul 10 14:17:54 2009
New Revision: 792959

URL: http://svn.apache.org/viewvc?rev=792959&view=rev
Log:
fix whitespace

Modified:
    couchdb/trunk/share/www/script/test/basics.js

Modified: couchdb/trunk/share/www/script/test/basics.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/basics.js?rev=792959&r1=792958&r2=792959&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/basics.js (original)
+++ couchdb/trunk/share/www/script/test/basics.js Fri Jul 10 14:17:54 2009
@@ -12,166 +12,166 @@
 
 // Do some basic tests.
 couchTests.basics = function(debug) {
-    var result = JSON.parse(CouchDB.request("GET", "/").responseText);
-    T(result.couchdb == "Welcome");
+  var result = JSON.parse(CouchDB.request("GET", "/").responseText);
+  T(result.couchdb == "Welcome");
 
-    var db = new CouchDB("test_suite_db");
-    db.deleteDb();
+  var db = new CouchDB("test_suite_db");
+  db.deleteDb();
 
-    // bug COUCHDB-100: DELETE on non-existent DB returns 500 instead of 404
-    db.deleteDb();
+  // bug COUCHDB-100: DELETE on non-existent DB returns 500 instead of 404
+  db.deleteDb();
 
-    db.createDb();
+  db.createDb();
 
-    // PUT on existing DB should return 412 instead of 500
-    xhr = CouchDB.request("PUT", "/test_suite_db/");
-    T(xhr.status == 412);
-    if (debug) debugger;
+  // PUT on existing DB should return 412 instead of 500
+  xhr = CouchDB.request("PUT", "/test_suite_db/");
+  T(xhr.status == 412);
+  if (debug) debugger;
 
-    // creating a new DB should return Location header
-    xhr = CouchDB.request("DELETE", "/test_suite_db");
-    xhr = CouchDB.request("PUT", "/test_suite_db");
-    TEquals("/test_suite_db",
-      xhr.getResponseHeader("Location").substr(-14),
-      "should return Location header to newly created document");
+  // creating a new DB should return Location header
+  xhr = CouchDB.request("DELETE", "/test_suite_db");
+  xhr = CouchDB.request("PUT", "/test_suite_db");
+  TEquals("/test_suite_db",
+    xhr.getResponseHeader("Location").substr(-14),
+    "should return Location header to newly created document");
 
-    TEquals("http://",
-      xhr.getResponseHeader("Location").substr(0, 7),
-      "should return absolute Location header to newly created document");
+  TEquals("http://",
+    xhr.getResponseHeader("Location").substr(0, 7),
+    "should return absolute Location header to newly created document");
 
-    // Get the database info, check the db_name
-    T(db.info().db_name == "test_suite_db");
+  // Get the database info, check the db_name
+  T(db.info().db_name == "test_suite_db");
 
-    // Get the database info, check the doc_count
-    T(db.info().doc_count == 0);
+  // Get the database info, check the doc_count
+  T(db.info().doc_count == 0);
 
-    // create a document and save it to the database
-    var doc = {_id:"0",a:1,b:1};
-    var result = db.save(doc);
+  // create a document and save it to the database
+  var doc = {_id:"0",a:1,b:1};
+  var result = db.save(doc);
 
-    T(result.ok==true); // return object has an ok member with a value true
-    T(result.id); // the _id of the document is set.
-    T(result.rev); // the revision id of the document is set.
+  T(result.ok==true); // return object has an ok member with a value true
+  T(result.id); // the _id of the document is set.
+  T(result.rev); // the revision id of the document is set.
 
-    // Verify the input doc is now set with the doc id and rev
-    // (for caller convenience).
-    T(doc._id == result.id && doc._rev == result.rev);
+  // Verify the input doc is now set with the doc id and rev
+  // (for caller convenience).
+  T(doc._id == result.id && doc._rev == result.rev);
 
-    var id = result.id; // save off the id for later
+  var id = result.id; // save off the id for later
 
-    // make sure the revs_info status is good
-    var doc = db.open(id, {revs_info:true});
-    T(doc._revs_info[0].status == "available");
+  // make sure the revs_info status is good
+  var doc = db.open(id, {revs_info:true});
+  T(doc._revs_info[0].status == "available");
 
-    // make sure you can do a seq=true option
-    var doc = db.open(id, {local_seq:true});
-    T(doc._local_seq == 1);
+  // make sure you can do a seq=true option
+  var doc = db.open(id, {local_seq:true});
+  T(doc._local_seq == 1);
 
 
-    // Create some more documents.
-    // Notice the use of the ok member on the return result.
-    T(db.save({_id:"1",a:2,b:4}).ok);
-    T(db.save({_id:"2",a:3,b:9}).ok);
-    T(db.save({_id:"3",a:4,b:16}).ok);
+  // Create some more documents.
+  // Notice the use of the ok member on the return result.
+  T(db.save({_id:"1",a:2,b:4}).ok);
+  T(db.save({_id:"2",a:3,b:9}).ok);
+  T(db.save({_id:"3",a:4,b:16}).ok);
 
-    // Check the database doc count
-    T(db.info().doc_count == 4);
+  // Check the database doc count
+  T(db.info().doc_count == 4);
 
-    // Test a simple map functions
+  // Test a simple map functions
 
-    // create a map function that selects all documents whose "a" member
-    // has a value of 4, and then returns the document's b value.
-    var mapFunction = function(doc){
-      if (doc.a==4)
-        emit(null, doc.b);
-    };
-
-    results = db.query(mapFunction);
-
-    // verify only one document found and the result value (doc.b).
-    T(results.total_rows == 1 && results.rows[0].value == 16);
-
-    // reopen document we saved earlier
-    existingDoc = db.open(id);
-
-    T(existingDoc.a==1);
-
-    //modify and save
-    existingDoc.a=4;
-    db.save(existingDoc);
-
-    // redo the map query
-    results = db.query(mapFunction);
-
-    // the modified document should now be in the results.
-    T(results.total_rows == 2);
-
-    // write 2 more documents
-    T(db.save({a:3,b:9}).ok);
-    T(db.save({a:4,b:16}).ok);
+  // create a map function that selects all documents whose "a" member
+  // has a value of 4, and then returns the document's b value.
+  var mapFunction = function(doc){
+    if (doc.a==4)
+      emit(null, doc.b);
+  };
 
-    results = db.query(mapFunction);
+  results = db.query(mapFunction);
 
-    // 1 more document should now be in the result.
-    T(results.total_rows == 3);
-    T(db.info().doc_count == 6);
+  // verify only one document found and the result value (doc.b).
+  T(results.total_rows == 1 && results.rows[0].value == 16);
 
-    var reduceFunction = function(keys, values){
-      return sum(values);
-    };
+  // reopen document we saved earlier
+  existingDoc = db.open(id);
 
-    results = db.query(mapFunction, reduceFunction);
+  T(existingDoc.a==1);
 
-    T(results.rows[0].value == 33);
+  //modify and save
+  existingDoc.a=4;
+  db.save(existingDoc);
 
-    // delete a document
-    T(db.deleteDoc(existingDoc).ok);
+  // redo the map query
+  results = db.query(mapFunction);
 
-    // make sure we can't open the doc
-    T(db.open(existingDoc._id) == null);
+  // the modified document should now be in the results.
+  T(results.total_rows == 2);
 
-    results = db.query(mapFunction);
+  // write 2 more documents
+  T(db.save({a:3,b:9}).ok);
+  T(db.save({a:4,b:16}).ok);
 
-    // 1 less document should now be in the results.
-    T(results.total_rows == 2);
-    T(db.info().doc_count == 5);
+  results = db.query(mapFunction);
 
-    // make sure we can still open the old rev of the deleted doc
-    T(db.open(existingDoc._id, {rev: existingDoc._rev}) != null);
-    // make sure restart works
-    T(db.ensureFullCommit().ok);
-    restartServer();
+  // 1 more document should now be in the result.
+  T(results.total_rows == 3);
+  T(db.info().doc_count == 6);
 
-    // make sure we can still open
-    T(db.open(existingDoc._id, {rev: existingDoc._rev}) != null);
+  var reduceFunction = function(keys, values){
+    return sum(values);
+  };
 
-    // test that the POST response has a Location header
-    var xhr = CouchDB.request("POST", "/test_suite_db", {
-      body: JSON.stringify({"foo":"bar"})
-    });
-    var resp = JSON.parse(xhr.responseText);
-    T(resp.ok);
-    var loc = xhr.getResponseHeader("Location");
-    T(loc, "should have a Location header");
-    var locs = loc.split('/');
-    T(locs[4] == resp.id);
-    T(locs[3] == "test_suite_db");
+  results = db.query(mapFunction, reduceFunction);
 
-    // document put's should return a Location header
-    var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {
-      body: JSON.stringify({"a":1})
-    });
-    TEquals("/test_suite_db/newdoc",
-      xhr.getResponseHeader("Location").substr(-21),
-      "should return Location header to newly created document");
+  T(results.rows[0].value == 33);
 
-    TEquals("http://",
-      xhr.getResponseHeader("Location").substr(0, 7),
-      "should return absolute Location header to newly created document");
+  // delete a document
+  T(db.deleteDoc(existingDoc).ok);
 
-    // deleting a non-existent doc should be 404
-    xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist");
-    T(xhr.status == 404);
+  // make sure we can't open the doc
+  T(db.open(existingDoc._id) == null);
+
+  results = db.query(mapFunction);
+
+  // 1 less document should now be in the results.
+  T(results.total_rows == 2);
+  T(db.info().doc_count == 5);
+
+  // make sure we can still open the old rev of the deleted doc
+  T(db.open(existingDoc._id, {rev: existingDoc._rev}) != null);
+  // make sure restart works
+  T(db.ensureFullCommit().ok);
+  restartServer();
+
+  // make sure we can still open
+  T(db.open(existingDoc._id, {rev: existingDoc._rev}) != null);
+
+  // test that the POST response has a Location header
+  var xhr = CouchDB.request("POST", "/test_suite_db", {
+    body: JSON.stringify({"foo":"bar"})
+  });
+  var resp = JSON.parse(xhr.responseText);
+  T(resp.ok);
+  var loc = xhr.getResponseHeader("Location");
+  T(loc, "should have a Location header");
+  var locs = loc.split('/');
+  T(locs[4] == resp.id);
+  T(locs[3] == "test_suite_db");
+
+  // document put's should return a Location header
+  var xhr = CouchDB.request("PUT", "/test_suite_db/newdoc", {
+    body: JSON.stringify({"a":1})
+  });
+  TEquals("/test_suite_db/newdoc",
+    xhr.getResponseHeader("Location").substr(-21),
+    "should return Location header to newly created document");
+
+  TEquals("http://",
+    xhr.getResponseHeader("Location").substr(0, 7),
+    "should return absolute Location header to newly created document");
+
+  // deleting a non-existent doc should be 404
+  xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist");
+  T(xhr.status == 404);
 
   // Check for invalid document members
   bad_docs = [
@@ -195,31 +195,31 @@
   };
   bad_docs.forEach(test_doc);
 
-    // Check some common error responses.
-    // PUT body not an object
-    xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"});
-    T(xhr.status == 400);
-    result = JSON.parse(xhr.responseText);
-    T(result.error == "bad_request");
-    T(result.reason == "Document must be a JSON object");
-
-    // Body of a _bulk_docs is not an object
-    xhr = CouchDB.request("POST", "/test_suite_db/_bulk_docs", {body: "[]"});
-    T(xhr.status == 400);
-    result = JSON.parse(xhr.responseText);
-    T(result.error == "bad_request");
-    T(result.reason == "Request body must be a JSON object");
-
-    // Body of an _all_docs  multi-get is not a {"key": [...]} structure.
-    xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body: "[]"});
-    T(xhr.status == 400);
-    result = JSON.parse(xhr.responseText);
-    T(result.error == "bad_request");
-    T(result.reason == "Request body must be a JSON object");
-    var data = "{\"keys\": 1}";
-    xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body:data});
-    T(xhr.status == 400);
-    result = JSON.parse(xhr.responseText);
-    T(result.error == "bad_request");
-    T(result.reason == "`keys` member must be a array.");
-  };
+  // Check some common error responses.
+  // PUT body not an object
+  xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"});
+  T(xhr.status == 400);
+  result = JSON.parse(xhr.responseText);
+  T(result.error == "bad_request");
+  T(result.reason == "Document must be a JSON object");
+
+  // Body of a _bulk_docs is not an object
+  xhr = CouchDB.request("POST", "/test_suite_db/_bulk_docs", {body: "[]"});
+  T(xhr.status == 400);
+  result = JSON.parse(xhr.responseText);
+  T(result.error == "bad_request");
+  T(result.reason == "Request body must be a JSON object");
+
+  // Body of an _all_docs  multi-get is not a {"key": [...]} structure.
+  xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body: "[]"});
+  T(xhr.status == 400);
+  result = JSON.parse(xhr.responseText);
+  T(result.error == "bad_request");
+  T(result.reason == "Request body must be a JSON object");
+  var data = "{\"keys\": 1}";
+  xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body:data});
+  T(xhr.status == 400);
+  result = JSON.parse(xhr.responseText);
+  T(result.error == "bad_request");
+  T(result.reason == "`keys` member must be a array.");
+};