summaryrefslogtreecommitdiff
path: root/test/tc_parser.rb
blob: 89339f03e8fca3919312381704746509d203fbee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/ruby -w

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')

require 'test/unit'
require 'feed2imap/channel'

class ParserTest < Test::Unit::TestCase
  DATADIR = 'test/parserdata'
  def test_parser
    return if not File::exist?(DATADIR)
    Dir.foreach(DATADIR) do |f|
      next if f !~ /.xml$/
      str = File::read(DATADIR + '/' + f)
      chan = Channel::new(str)
      # for easier reading, go to ISO
      chanstr = chan.to_s
      chanstr = chanstr.unpack('U*').pack('C*')
      if File::exist?(DATADIR + '/' + f.gsub(/.xml$/, '.output'))
        output = File::read(DATADIR + '/' + f.gsub(/.xml$/, '.output'))
        File::open(DATADIR + '/' + f.gsub(/.xml$/, '.output.new'), "w") do |f|
          f.print(chanstr)
        end
        assert_equal(output, chanstr)
      else
        File::open(DATADIR + '/' + f.gsub(/.xml$/, '.output.new'), "w") do |f|
          f.print(chanstr)
        end
      end
    end
  end
end