diff options
Diffstat (limited to 'spec/mspec/lib/mspec/guards/endian.rb')
-rw-r--r-- | spec/mspec/lib/mspec/guards/endian.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/mspec/lib/mspec/guards/endian.rb b/spec/mspec/lib/mspec/guards/endian.rb new file mode 100644 index 0000000000..6bb01263c7 --- /dev/null +++ b/spec/mspec/lib/mspec/guards/endian.rb @@ -0,0 +1,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 |