File: loca_spec.rb

package info (click to toggle)
ruby-ttfunk 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,472 kB
  • sloc: ruby: 7,954; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

require 'spec_helper'
require 'ttfunk/table/loca'

RSpec.describe TTFunk::Table::Loca do
  describe '.encode' do
    it 'properly encodes short aligned offsets' do
      result = described_class.encode([0, 2, 4])

      expect(result[:type]).to eq(0)
      expect(result[:table].bytes).to eq [
        0x00, 0x00,
        0x00, 0x01,
        0x00, 0x02,
      ]
    end

    it 'properly encodes short-is aligned offsets' do
      result = described_class.encode([0, 0x1FFFE])

      expect(result[:type]).to eq(0)
      expect(result[:table].bytes).to eq [
        0x00, 0x00,
        0xFF, 0xFF,
      ]
    end

    it 'properly encodes short misaligned offsets' do
      result = described_class.encode([0, 2, 3])

      expect(result[:type]).to eq(1)
      expect(result[:table].bytes).to eq [
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x02,
        0x00, 0x00, 0x00, 0x03,
      ]
    end

    it 'properly encodes long offsets' do
      result = described_class.encode([0, 0x1FFFF])

      expect(result[:type]).to eq(1)
      expect(result[:table].bytes).to eq [
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x01, 0xFF, 0xFF,
      ]
    end
  end
end