Re: [PATCH v4 09/16] index encrypted parts when asked.
[notmuch-archives.git] / 2e / 99c81cae1b0edf9213accfa38f81161d3bfe0f
1 Return-Path: <dme@ut.hh.sledj.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id B5D0641A541\r
6         for <notmuch@notmuchmail.org>; Tue, 30 Nov 2010 03:00:46 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.363\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.363 tagged_above=-999 required=5\r
12         tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id K1vhs5ea8AY8 for <notmuch@notmuchmail.org>;\r
16         Tue, 30 Nov 2010 03:00:45 -0800 (PST)\r
17 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
18         [81.149.164.25])\r
19         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 173DF41A54B\r
22         for <notmuch@notmuchmail.org>; Tue, 30 Nov 2010 03:00:44 -0800 (PST)\r
23 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
24         id EC52A594241; Tue, 30 Nov 2010 11:00:28 +0000 (GMT)\r
25 From: David Edmondson <dme@dme.org>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [PATCH 3/4] test: Add tests for JSON parsing of search results.\r
28 Date: Tue, 30 Nov 2010 11:00:24 +0000\r
29 Message-Id: <1291114825-3513-3-git-send-email-dme@dme.org>\r
30 X-Mailer: git-send-email 1.7.2.3\r
31 In-Reply-To: <1291026599-14795-4-git-send-email-dme@dme.org>\r
32 References: <1291026599-14795-4-git-send-email-dme@dme.org>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.13\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37         <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Tue, 30 Nov 2010 11:00:47 -0000\r
46 \r
47 Two cases:\r
48 - simple insertion of a record,\r
49 - insertion of a single record in two chunks.\r
50 ---\r
51  emacs/notmuch-test.el |   70 +++++++++++++++++++++++++++++++++++++++++++++++++\r
52  1 files changed, 70 insertions(+), 0 deletions(-)\r
53 \r
54 diff --git a/emacs/notmuch-test.el b/emacs/notmuch-test.el\r
55 index 8f76164..f08a53c 100644\r
56 --- a/emacs/notmuch-test.el\r
57 +++ b/emacs/notmuch-test.el\r
58 @@ -185,6 +185,76 @@ Presumes that the email corpus is already present."\r
59  \r
60  ;;\r
61  \r
62 +(require 'notmuch)\r
63 +\r
64 +(defvar notmuch-test-json-1\r
65 +  "[{\"thread\": \"XXX\",\r
66 +\"timestamp\": 946728000,\r
67 +\"date_relative\": \"2000-01-01\",\r
68 +\"matched\": 1,\r
69 +\"total\": 1,\r
70 +\"authors\": \"Notmuch Test Suite\",\r
71 +\"subject\": \"json-search-subject\",\r
72 +\"tags\": [\"inbox\", \"unread\"]}]\r
73 +")\r
74 +\r
75 +(defvar notmuch-test-json-1-result\r
76 +  "XXX:2000-01-01:Notmuch Test Suite:json-search-subject:946728000:1:1:inbox:unread\n")\r
77 +\r
78 +(defun notmuch-test-search-process-insert-object (object)\r
79 +  (insert\r
80 +   (concat\r
81 +    (mapconcat (lambda (field)\r
82 +                (plist-get object field))\r
83 +              '(:thread :date_relative :authors :subject)\r
84 +              ":")\r
85 +    ":"\r
86 +    (mapconcat (lambda (field)\r
87 +                (format "%d" (plist-get object field)))\r
88 +              '(:timestamp :matched :total)\r
89 +              ":")\r
90 +    ":"\r
91 +    (mapconcat 'identity\r
92 +              (plist-get object :tags)\r
93 +              ":")\r
94 +    "\n")))\r
95 +\r
96 +(ert-deftest notmuch-search-process-insert ()\r
97 +  ;; Fake out a few things that `notmuch-search-process-insert' uses.\r
98 +  (flet ((set-marker (proc pos))\r
99 +        (process-mark (proc) nil)\r
100 +        (notmuch-search-process-insert-object (object)\r
101 +                                              (notmuch-test-search-process-insert-object object)))\r
102 +\r
103 +    ;; Simplest case - a single record delivered in one chunk.\r
104 +    (should\r
105 +     (string= notmuch-test-json-1-result\r
106 +             (notmuch-temp-buffer-as-string\r
107 +              (let ((notmuch-search-parse-start (point-min)))\r
108 +                (notmuch-search-process-insert\r
109 +                 nil (current-buffer)\r
110 +                 notmuch-test-json-1)))))\r
111 +\r
112 +    ;; A single record delivered in two chunks.\r
113 +    (should\r
114 +     (string= notmuch-test-json-1-result\r
115 +             (notmuch-temp-buffer-as-string\r
116 +              (let ((notmuch-search-parse-start (point-min))\r
117 +                    (half (/ (length notmuch-test-json-1)\r
118 +                             2)))\r
119 +                ;; Insert first half.\r
120 +                (notmuch-search-process-insert\r
121 +                 nil (current-buffer)\r
122 +                 (substring notmuch-test-json-1 0 half))\r
123 +                ;; Insert second half.\r
124 +                (notmuch-search-process-insert\r
125 +                 nil (current-buffer)\r
126 +                 (substring notmuch-test-json-1 half))))))\r
127 +\r
128 +    ))\r
129 +\r
130 +;;\r
131 +\r
132  (defun notmuch-test-batch ()\r
133    "Run the notmuch ERT tests in batch mode."\r
134  \r
135 -- \r
136 1.7.2.3\r
137 \r