From: William Morgan Date: Sat, 26 Apr 2008 21:25:27 +0000 (-0700) Subject: add unit tests for mbox parsing that currently fail OMG TEST-DRIVEN DEVELOPMENT X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=d0411362a605915c341204867effede135eb0326;p=sup add unit tests for mbox parsing that currently fail OMG TEST-DRIVEN DEVELOPMENT --- diff --git a/test/test_mbox_parsing.rb b/test/test_mbox_parsing.rb new file mode 100644 index 0000000..070b152 --- /dev/null +++ b/test/test_mbox_parsing.rb @@ -0,0 +1,114 @@ +#!/usr/bin/ruby + +require 'test/unit' +require 'sup' +require 'stringio' + +include Redwood + +class TestMessage < Test::Unit::TestCase + def setup + end + + def teardown + end + + def test_normal_headers + h = MBox.read_header StringIO.new(< +To: Sally +EOS + + assert_equal "Bob ", h["From"] + assert_equal "Sally ", h["To"] + assert_nil h["Message-Id"] + end + + ## this is shitty behavior in retrospect, but it's built in now. + def test_message_id_stripping + h = MBox.read_header StringIO.new("Message-Id: \n") + assert_equal "one@bob.com", h["Message-Id"] + + h = MBox.read_header StringIO.new("Message-Id: one@bob.com\n") + assert_equal "one@bob.com", h["Message-Id"] + end + + def test_multiline + h = MBox.read_header StringIO.new(< +Subject: one two three + four five six +To: Sally +References: seven + eight +Seven: Eight +EOS + + assert_equal "one two three four five six", h["Subject"] + assert_equal "Sally ", h["To"] + assert_equal "seven eight", h["References"] + end + + def test_ignore_spacing + variants = [ + "Subject:one two three end\n", + "Subject: one two three end\n", + "Subject: one two three end \n", + ] + variants.each do |s| + h = MBox.read_header StringIO.new(s) + assert_equal "one two three end", h["Subject"] + end + end + + def test_message_id_ignore_spacing + variants = [ + "Message-Id: \n", + "Message-Id: one@bob.com \n", + "Message-Id: \n", + "Message-Id:one@bob.com \n", + ] + variants.each do |s| + h = MBox.read_header StringIO.new(s) + assert_equal "one@bob.com", h["Message-Id"] + end + end + + def test_ignore_empty_lines + variants = [ + "", + "Message-Id: \n", + "Message-Id:\n", + ] + variants.each do |s| + h = MBox.read_header StringIO.new(s) + assert_nil h["Message-Id"] + end + end + + def test_detect_end_of_headers + h = MBox.read_header StringIO.new(< + +To: a dear friend +EOS + assert_equal "Bob ", h["From"] + assert_nil h["To"] + + h = MBox.read_header StringIO.new(< +\r +To: a dear friend +EOS + assert_equal "Bob ", h["From"] + assert_nil h["To"] + + h = MBox.read_header StringIO.new(< +\r\n\r +To: a dear friend +EOS + assert_equal "Bob ", h["From"] + assert_nil h["To"] + end +end