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