test/unit/test_nntp_article.rb in ruby-net-nntp-0.0.9 vs test/unit/test_nntp_article.rb in ruby-net-nntp-0.1.0
- old
+ new
@@ -1,8 +1,5 @@
-require 'test/unit'
-require 'net/nntp.rb'
-
class TestNNTPArticle < Test::Unit::TestCase
def setup
@article = Net::NNTP::Article.new
@article.overview_format = "215 Order of fields in overview database.\r\nSubject:\r\nFrom:\r\nDate:\r\nMessage-ID:\r\nReferences:\r\nBytes:\r\nLines:\r\nXref:full\r\n.\r\n"
@@ -10,13 +7,13 @@
def test_article_new
a = Net::NNTP::Article.new
end
- def test_article_id
- @article.id = 1
- assert_equal 1, @article.id
+ def test_article_number
+ @article.number = 1
+ assert_equal 1, @article.number
end
def test_article_messageid
m = '<bla.foo@some.host>'
@article.messageid = m
@@ -30,27 +27,64 @@
end
def test_from_xover
over = "1\tTesting\t\"abc\" abc@ide.invalid\t17 Aug 2004 14:00:00 GMT\t<this.post@is.invalid>\t\t200\t2\tXref: this.host.invalid alt.test:1"
@article.overview(over)
- assert_equal '1', @article.id
+ assert_equal '1', @article.number
assert_equal '<this.post@is.invalid>', @article.messageid
assert_equal 'Testing', @article.subject
assert_equal 200, @article.bytes.to_i
assert_equal 2, @article.lines.to_i
assert_equal '17 Aug 2004 14:00:00 GMT', @article.date
end
def test_overview_fmt=
-
@article.overview_format = "215 Order of fields in overview database.\r\nSubject:\r\nFrom:\r\nDate:\r\nMessage-ID:\r\nReferences:\r\nBytes:\r\nLines:\r\nXref:full\r\n.\r\n"
+ assert_equal 'number', @article.overview_format[0]
assert_equal 'subject', @article.overview_format[1]
assert_equal 'from', @article.overview_format[2]
assert_equal 'date', @article.overview_format[3]
assert_equal 'messageid', @article.overview_format[4]
assert_equal 'references', @article.overview_format[5]
assert_equal 'bytes', @article.overview_format[6]
assert_equal 'lines', @article.overview_format[7]
assert_equal 'xref', @article.overview_format[8]
+ end
+
+ def test_set_header
+ @article.set_header('Subject: Test')
+ assert_equal 'Test', @article.headers.subject
+ @article.set_header('Message-ID: <this.post@is.invalid>')
+ assert_equal '<this.post@is.invalid>', @article.headers.message_id
+ end
+
+ def test_parse
+ article = Net::NNTP::Article.parse(["220 1 article retrieved - text follows",
+ "Date: 17 Aug 2004 14:00:00 GMT",
+ "From: \"abc\" abc@ide.invalid",
+ "Message-ID: <this.post@is.invalid>",
+ "Subject: ignore test",
+ "",
+ "test please ignore",
+ "test ",
+ "."])
+ assert_equal '17 Aug 2004 14:00:00 GMT', article.headers.date
+ assert_equal '"abc" abc@ide.invalid', article.headers.from
+ assert_equal '<this.post@is.invalid>', article.headers.message_id
+ assert_equal 'ignore test', article.headers.subject
+ assert_equal 2, article.body.size
+ assert_equal 'test please ignore', article.body[0]
+ assert_equal 'test ', article.body[1]
+ article = Net::NNTP::Article.parse(["221 1 article retrieved - head follows", "Date: 17 Aug 2004 14:00:00 GMT", "From: \"abc\" abc@ide.invalid",
+ "Message-ID: <this.post@is.invalid>", "Subject: ignore test", "."])
+ assert_equal '17 Aug 2004 14:00:00 GMT', article.headers.date
+ assert_equal '"abc" abc@ide.invalid', article.headers.from
+ assert_equal '<this.post@is.invalid>', article.headers.message_id
+ assert_equal 'ignore test', article.headers.subject
+ assert_equal 0, article.body.size
+ article = Net::NNTP::Article.parse(["222 1 article retrieved - body follows", "test please ignore", "test ", "."])
+ assert_equal 2, article.body.size
+ assert_equal 'test please ignore', article.body[0]
+ assert_equal 'test ', article.body[1]
end
end