File: lzw_spec.rb

package info (click to toggle)
ruby-pdf-reader 2.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,544 kB
  • sloc: ruby: 11,993; sh: 46; makefile: 11
file content (28 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (2)
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
# typed: false
# coding: utf-8

describe PDF::Reader::LZW do
  describe "#decode" do
    it "decodes a lzw compress string" do
      content = %w{ 80 0B 60 50 22 0C 0C 85 01 }.map { |byte|
        byte.to_i(16)
      }.pack("C*")

      expect(PDF::Reader::LZW.decode(content)).to eq('-----A---B')
    end

    it "decodes another lzw compressed string" do
      content = binread(File.dirname(__FILE__) + "/data/lzw_compressed2.dat")

      expect(PDF::Reader::LZW.decode(content)).to match(/\ABT/)
    end

    it "raises PDF::Reader::MalformedPDFError when the stream isn't valid lzw" do
      content = binread(File.dirname(__FILE__) + "/data/lzw_compressed_corrupt.dat")

      expect {
        PDF::Reader::LZW.decode(content)
      }.to raise_error(PDF::Reader::MalformedPDFError)
    end
  end
end