Sha256: 0eb657446d4723bb5090a21ef9a8934d617b2f4971a126dd1ee89ca25c157443

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require_relative '../../test_helper'

describe DMAPParser::Parser do
  it 'should raise a ParserError when given invalid data' do
    invalid = []
    invalid << (0..255).map { |c| c.chr }.join # random data
    invalid << "rand\x00\x00\x00\x01" # non correct size
    invalid << "msup\x00\x00\x00\x01\x01" # not a container!
    invalid << "rand\x00\x00\x00\x01\x01" # not a container!
    invalid.each do |data|
      lambda do
        DMAPParser::Parser.parse(data)
      end.must_raise(DMAPParser::Parser::ParseError)
    end
  end

  it 'should return nil if the string is empty' do
    DMAPParser::Parser.parse('').must_equal nil
  end

  it 'should ignore padding' do
    dmap = support_file('simple.dmap').read
    padded = DMAPParser::Parser.parse(dmap + 'I AM PADDING!!11!!')
    padded.to_dmap.must_equal dmap
  end

  it 'should parse an empty container' do
    data = "mcon\x00\x00\x00\x00"
    mcon = DMAPParser::Parser.parse(data)
    mcon.must_be_instance_of DMAPParser::TagContainer
    mcon.to_a.must_be_empty
  end

  it 'should accept IO objects' do
    data = DMAPParser::Parser.parse(support_file('simple.dmap'))
    data.mstt.must_equal 200
  end

  it 'should parse iTunes content-types' do
    data = DMAPParser::Parser.parse(support_file('content_codes.dmap'))
    data.type.tag.must_equal 'mccr'
    data.mstt.must_equal 200
    data.to_a.count.must_equal 184
  end

  it 'should parse unknown tags' do
    data = "mcon\x00\x00\x00\x15xkcd\x00\x00\x00\x0dis a webcomic"
    data = DMAPParser::Parser.parse(data)
    data.xkcd?.must_equal true
  end

  it 'should guess the type of unknown tags' do
    data = "mcon\x00\x00\x00\x15xkcd\x00\x00\x00\x0Dis a webcomic"
    data = DMAPParser::Parser.parse(data)
    data.xkcd.must_equal 'is a webcomic'
    data = "mcon\x00\x00\x00\x0Ajurp\x00\x00\x00\x02\x13\x37"
    data = DMAPParser::Parser.parse(data)
    data.jurp.must_equal 0x1337
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dmapparser-0.0.1 test/lib/dmapparser/parser_test.rb