From b870261adcd15b6ccd56f1ee15fd04cad14bc1a6 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sat, 7 Aug 2010 20:33:33 +0000 Subject: builtin reduce functions more forgiving about trailing whitespace and other characters git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.0.x@983307 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/reduce_builtin.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'share/www/script/test') diff --git a/share/www/script/test/reduce_builtin.js b/share/www/script/test/reduce_builtin.js index 0db6bc09..d9635688 100644 --- a/share/www/script/test/reduce_builtin.js +++ b/share/www/script/test/reduce_builtin.js @@ -72,6 +72,26 @@ couchTests.reduce_builtin = function(debug) { T(result.rows[0].value == 2*(summate(numDocs-i) - summate(i-1))); } + // test for trailing characters after builtin functions, desired behaviour + // is to disregard any trailing characters + // I think the behavior should be a prefix test, so that even "_statsorama" + // or "_stats\nare\awesome" should work just as "_stats" does. - JChris + + var trailing = ["\u000a", "orama", "\nare\nawesome", " ", " \n "]; + + for(var i=0; i < trailing.length; i++) { + result = db.query(map, "_sum" + trailing[i]); + T(result.rows[0].value == 2*summate(numDocs)); + result = db.query(map, "_count" + trailing[i]); + T(result.rows[0].value == 1000); + result = db.query(map, "_stats" + trailing[i]); + T(result.rows[0].value.sum == 2*summate(numDocs)); + T(result.rows[0].value.count == 1000); + T(result.rows[0].value.min == 1); + T(result.rows[0].value.max == 500); + T(result.rows[0].value.sumsqr == 2*sumsqr(numDocs)); + } + db.deleteDb(); db.createDb(); -- cgit v1.2.3