File: unix_to_unix_spec.rb

package info (click to toggle)
ruby-mail 2.7.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,732 kB
  • sloc: ruby: 71,628; makefile: 3
file content (57 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (3)
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
51
52
53
54
55
56
57
# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Encodings::UnixToUnix do
  def decode(str)
    Mail::Encodings::UnixToUnix.decode(str)
  end

  def encode(str)
    Mail::Encodings::UnixToUnix.encode(str)
  end

  it "is registered as uuencode" do
    expect(Mail::Encodings.get_encoding('uuencode')).to eq(Mail::Encodings::UnixToUnix)
  end

  it "is registered as x-uuencode" do
    expect(Mail::Encodings.get_encoding('x-uuencode')).to eq(Mail::Encodings::UnixToUnix)
  end

  it "is registered as x-uue" do
    expect(Mail::Encodings.get_encoding('x-uue')).to eq(Mail::Encodings::UnixToUnix)
  end

  it "can transport itself" do
    expect(Mail::Encodings::UnixToUnix.can_transport?(Mail::Encodings::UnixToUnix)).to be_truthy
  end

  it "decodes" do
    text = strip_heredoc(<<-TEXT)
      begin 644 Happy.txt
      M2&%P<'D@=&]D87D@9F]R('1O(&)E(&]N92!O9B!P96%C92!A;F0@<V5R96YE
      '('1I;64N"@``
      `
      end
    TEXT
    expect(decode(text)).to eq "Happy today for to be one of peace and serene time.\n"
  end

  it "encodes" do
    expect(encode("Happy today")).to eq "+2&%P<'D@=&]D87D`\n"
  end

  if RUBY_VERSION > "1.9"
    it "encodes / decodes non-ascii" do
      expect(encode("Happy ああr")).to eq "-2&%P<'D@XX&\"XX&\"<@``\n"
      expected = (RUBY_ENGINE == "jruby" ? "Happy ああr" : "Happy ああr".dup.force_encoding("binary"))
      expect(decode("-2&%P<'D@XX&\"XX&\"<@``\n")).to eq expected
    end
  end

  it "can read itself" do
    expect(decode(encode("Happy today"))).to eq "Happy today"
    expect(encode(decode("+2&%P<'D@=&]D87D`\n"))).to eq "+2&%P<'D@=&]D87D`\n"
  end
end