File: binmode_spec.rb

package info (click to toggle)
ruby-tty-command 0.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 1,990; makefile: 4; sh: 4
file content (29 lines) | stat: -rw-r--r-- 994 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
# frozen_string_literal: true

RSpec.describe TTY::Command, "#run" do
  it "encodes output as unicode by default" do
    output = StringIO.new
    cmd = TTY::Command.new(output: output)
    out, = cmd.run("echo '昨夜のコンサートは'")

    expect(out.encoding).to eq(Encoding::UTF_8)
    # expect(out.chomp).to eq("昨夜のコンサートは")
  end

  it "encodes output as binary" do
    output = StringIO.new
    cmd = TTY::Command.new(output: output)
    out, = cmd.run("echo '昨夜のコンサートは'", binmode: true)

    expect(out.encoding).to eq(Encoding::BINARY)
    #expect(out.chomp).to eq("\xE6\x98\xA8\xE5\xA4\x9C\xE3\x81\xAE\xE3\x82\xB3\xE3\x83\xB3\xE3\x82\xB5\xE3\x83\xBC\xE3\x83\x88\xE3\x81\xAF".force_encoding(Encoding::BINARY))
  end

  it "encodes all commands output as binary" do
    output = StringIO.new
    cmd = TTY::Command.new(output: output, binmode: true)
    out, = cmd.run("echo 'hello'")

    expect(out.encoding).to eq(Encoding::BINARY)
  end
end