File: x_spec.rb

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (65 lines) | stat: -rw-r--r-- 1,967 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'

describe "Array#pack with format 'x'" do
  it_behaves_like :array_pack_basic, 'x'
  it_behaves_like :array_pack_basic_non_float, 'x'
  it_behaves_like :array_pack_no_platform, 'x'

  it "adds a NULL byte with an empty array" do
    [].pack("x").should == "\x00"
  end

  it "adds a NULL byte without consuming an element" do
    [1, 2].pack("CxC").should == "\x01\x00\x02"
  end

  it "is not affected by a previous count modifier" do
    [].pack("x3x").should == "\x00\x00\x00\x00"
  end

  it "adds multiple NULL bytes when passed a count modifier" do
    [].pack("x3").should == "\x00\x00\x00"
  end

  it "does not add a NULL byte if the count modifier is zero" do
    [].pack("x0").should == ""
  end

  it "does not add a NULL byte when passed the '*' modifier" do
    [].pack("x*").should == ""
    [1, 2].pack("Cx*C").should == "\x01\x02"
  end
end

describe "Array#pack with format 'X'" do
  it_behaves_like :array_pack_basic, 'X'
  it_behaves_like :array_pack_basic_non_float, 'X'
  it_behaves_like :array_pack_no_platform, 'X'

  it "reduces the output string by one byte at the point it is encountered" do
    [1, 2, 3].pack("C2XC").should == "\x01\x03"
  end

  it "does not consume any elements" do
    [1, 2, 3].pack("CXC").should == "\x02"
  end

  it "reduces the output string by multiple bytes when passed a count modifier" do
    [1, 2, 3, 4, 5].pack("C2X2C").should == "\x03"
  end

  it "has no affect when passed the '*' modifier" do
    [1, 2, 3].pack("C2X*C").should == "\x01\x02\x03"
  end

  it "raises an ArgumentError if the output string is empty" do
    -> { [1, 2, 3].pack("XC") }.should raise_error(ArgumentError)
  end

  it "raises an ArgumentError if the count modifier is greater than the bytes in the string" do
    -> { [1, 2, 3].pack("C2X3") }.should raise_error(ArgumentError)
  end
end