[PATCH 3/4] test: Add tests for JSON parsing of search results.
authorDavid Edmondson <dme@dme.org>
Tue, 30 Nov 2010 11:00:24 +0000 (11:00 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:38 +0000 (09:37 -0800)
2e/99c81cae1b0edf9213accfa38f81161d3bfe0f [new file with mode: 0644]

diff --git a/2e/99c81cae1b0edf9213accfa38f81161d3bfe0f b/2e/99c81cae1b0edf9213accfa38f81161d3bfe0f
new file mode 100644 (file)
index 0000000..ab6172d
--- /dev/null
@@ -0,0 +1,137 @@
+Return-Path: <dme@ut.hh.sledj.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id B5D0641A541\r
+       for <notmuch@notmuchmail.org>; Tue, 30 Nov 2010 03:00:46 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.363\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.363 tagged_above=-999 required=5\r
+       tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id K1vhs5ea8AY8 for <notmuch@notmuchmail.org>;\r
+       Tue, 30 Nov 2010 03:00:45 -0800 (PST)\r
+Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
+       [81.149.164.25])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 173DF41A54B\r
+       for <notmuch@notmuchmail.org>; Tue, 30 Nov 2010 03:00:44 -0800 (PST)\r
+Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
+       id EC52A594241; Tue, 30 Nov 2010 11:00:28 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/4] test: Add tests for JSON parsing of search results.\r
+Date: Tue, 30 Nov 2010 11:00:24 +0000\r
+Message-Id: <1291114825-3513-3-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1291026599-14795-4-git-send-email-dme@dme.org>\r
+References: <1291026599-14795-4-git-send-email-dme@dme.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 30 Nov 2010 11:00:47 -0000\r
+\r
+Two cases:\r
+- simple insertion of a record,\r
+- insertion of a single record in two chunks.\r
+---\r
+ emacs/notmuch-test.el |   70 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 files changed, 70 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-test.el b/emacs/notmuch-test.el\r
+index 8f76164..f08a53c 100644\r
+--- a/emacs/notmuch-test.el\r
++++ b/emacs/notmuch-test.el\r
+@@ -185,6 +185,76 @@ Presumes that the email corpus is already present."\r
\r
+ ;;\r
\r
++(require 'notmuch)\r
++\r
++(defvar notmuch-test-json-1\r
++  "[{\"thread\": \"XXX\",\r
++\"timestamp\": 946728000,\r
++\"date_relative\": \"2000-01-01\",\r
++\"matched\": 1,\r
++\"total\": 1,\r
++\"authors\": \"Notmuch Test Suite\",\r
++\"subject\": \"json-search-subject\",\r
++\"tags\": [\"inbox\", \"unread\"]}]\r
++")\r
++\r
++(defvar notmuch-test-json-1-result\r
++  "XXX:2000-01-01:Notmuch Test Suite:json-search-subject:946728000:1:1:inbox:unread\n")\r
++\r
++(defun notmuch-test-search-process-insert-object (object)\r
++  (insert\r
++   (concat\r
++    (mapconcat (lambda (field)\r
++               (plist-get object field))\r
++             '(:thread :date_relative :authors :subject)\r
++             ":")\r
++    ":"\r
++    (mapconcat (lambda (field)\r
++               (format "%d" (plist-get object field)))\r
++             '(:timestamp :matched :total)\r
++             ":")\r
++    ":"\r
++    (mapconcat 'identity\r
++             (plist-get object :tags)\r
++             ":")\r
++    "\n")))\r
++\r
++(ert-deftest notmuch-search-process-insert ()\r
++  ;; Fake out a few things that `notmuch-search-process-insert' uses.\r
++  (flet ((set-marker (proc pos))\r
++       (process-mark (proc) nil)\r
++       (notmuch-search-process-insert-object (object)\r
++                                             (notmuch-test-search-process-insert-object object)))\r
++\r
++    ;; Simplest case - a single record delivered in one chunk.\r
++    (should\r
++     (string= notmuch-test-json-1-result\r
++            (notmuch-temp-buffer-as-string\r
++             (let ((notmuch-search-parse-start (point-min)))\r
++               (notmuch-search-process-insert\r
++                nil (current-buffer)\r
++                notmuch-test-json-1)))))\r
++\r
++    ;; A single record delivered in two chunks.\r
++    (should\r
++     (string= notmuch-test-json-1-result\r
++            (notmuch-temp-buffer-as-string\r
++             (let ((notmuch-search-parse-start (point-min))\r
++                   (half (/ (length notmuch-test-json-1)\r
++                            2)))\r
++               ;; Insert first half.\r
++               (notmuch-search-process-insert\r
++                nil (current-buffer)\r
++                (substring notmuch-test-json-1 0 half))\r
++               ;; Insert second half.\r
++               (notmuch-search-process-insert\r
++                nil (current-buffer)\r
++                (substring notmuch-test-json-1 half))))))\r
++\r
++    ))\r
++\r
++;;\r
++\r
+ (defun notmuch-test-batch ()\r
+   "Run the notmuch ERT tests in batch mode."\r
\r
+-- \r
+1.7.2.3\r
+\r