Skip to content

Commit 58b7494

Browse files
committed
spec: Add spec
1 parent fe81158 commit 58b7494

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

spec/binary_parser_spec.cr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "./spec_helper"
2+
require "./fixture/*"
3+
4+
describe BinaryParser do
5+
describe "uint32" do
6+
it "parse correct" do
7+
parser = UInt32Parser.new.load(UINT32_FIXTURE)
8+
expect(parser.value).to eq(42)
9+
end
10+
end
11+
12+
describe "uint8" do
13+
it "parse correct" do
14+
parser = UInt8Parser.new.load(UINT8_FIXTURE)
15+
expect(parser.value).to eq(42)
16+
end
17+
end
18+
end
19+

spec/fixture/uint32.cr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "../../src/binary_parser"
2+
3+
class UInt32Parser < BinaryParser
4+
uint32 :value
5+
end
6+
7+
UINT32_FIXTURE = IO::Memory.new(sizeof(UInt32))
8+
UINT32_FIXTURE.write_bytes(42u32)
9+
UINT32_FIXTURE.rewind

spec/fixture/uint8.cr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require "../../src/binary_parser"
2+
3+
class UInt8Parser < BinaryParser
4+
uint8 :value
5+
end
6+
7+
UINT8_FIXTURE = IO::Memory.new(sizeof(UInt8))
8+
UINT8_FIXTURE.write_bytes(42u8)
9+
UINT8_FIXTURE.rewind

spec/spec_helper.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require "spec"
2+
require "expect"
3+
require "../src/binary_parser"
4+

0 commit comments

Comments
 (0)