File: a_spec.rb

package info (click to toggle)
ruby2.5 2.5.5-3%2Bdeb10u4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,532 kB
  • sloc: ruby: 732,598; ansic: 669,262; xml: 25,363; yacc: 20,963; javascript: 6,680; sh: 3,610; lisp: 2,627; makefile: 596; python: 198; sed: 76; perl: 62; awk: 36; asm: 35
file content (59 lines) | stat: -rw-r--r-- 1,890 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
58
59
# -*- encoding: ascii-8bit -*-
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
require File.expand_path('../shared/basic', __FILE__)
require File.expand_path('../shared/string', __FILE__)

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

  it "adds all the bytes to the output when passed the '*' modifier" do
    ["abc"].pack("A*").should == "abc"
  end

  it "padds the output with spaces when the count exceeds the size of the String" do
    ["abc"].pack("A6").should == "abc   "
  end

  it "adds a space when the value is nil" do
    [nil].pack("A").should == " "
  end

  it "pads the output with spaces when the value is nil" do
    [nil].pack("A3").should == "   "
  end

  it "does not pad with spaces when passed the '*' modifier and the value is nil" do
    [nil].pack("A*").should == ""
  end
end

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

  it "adds all the bytes to the output when passed the '*' modifier" do
    ["abc"].pack("a*").should == "abc"
  end

  it "padds the output with NULL bytes when the count exceeds the size of the String" do
    ["abc"].pack("a6").should == "abc\x00\x00\x00"
  end

  it "adds a NULL byte when the value is nil" do
    [nil].pack("a").should == "\x00"
  end

  it "pads the output with NULL bytes when the value is nil" do
    [nil].pack("a3").should == "\x00\x00\x00"
  end

  it "does not pad with NULL bytes when passed the '*' modifier and the value is nil" do
    [nil].pack("a*").should == ""
  end
end