summaryrefslogtreecommitdiff
path: root/spec/mspec/lib/mspec/guards/endian.rb
blob: 6bb01263c763bada9640b6198bfa9ad02ed86c41 (plain)
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
require 'mspec/guards/guard'

# Despite that these are inverses, the two classes are
# used to simplify MSpec guard reporting modes

class EndianGuard < SpecGuard
  def pattern
    @pattern ||= [1].pack('L')
  end
  private :pattern
end

class BigEndianGuard < EndianGuard
  def match?
    pattern[-1] == ?\001
  end
end

class Object
  def big_endian(&block)
    BigEndianGuard.new.run_if(:big_endian, &block)
  end

  def little_endian(&block)
    BigEndianGuard.new.run_unless(:little_endian, &block)
  end
end