Commit ffe800f

mokha <mokha@cisco.com>
2019-05-15 00:03:35
add specs for str
1 parent f5c5695
Changed files (4)
lib/mpeg/base.rb
@@ -1,7 +1,9 @@
 module Mpeg
   class Base
     def parse(string)
-      call(Input.new(string))
+      input = Input.new(string)
+      call(input)
+      input.end?
     end
 
     def repeat(min = 0, max = nil)
lib/mpeg/input.rb
@@ -14,5 +14,9 @@ module Mpeg
 
       Slice.new(position, slice)
     end
+
+    def end?
+      @scanner.eos?
+    end
   end
 end
lib/mpeg/str.rb
@@ -7,7 +7,7 @@ module Mpeg
 
     def call(input)
       if input.matches?(@regex)
-        input.consume(1)
+        input.consume(@length)
         return true
       end
       false
spec/str_spec.rb
@@ -0,0 +1,8 @@
+RSpec.describe Mpeg::Str do
+	context 'he' do
+		let(:subject) { described_class.new('he') }
+
+		specify { expect(subject.parse("hello")).to be(false) }
+		specify { expect(subject.parse("he")).to be(true) }
+	end
+end