summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringscanner/shared/bol.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/stringscanner/shared/bol.rb')
-rw-r--r--spec/ruby/library/stringscanner/shared/bol.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/ruby/library/stringscanner/shared/bol.rb b/spec/ruby/library/stringscanner/shared/bol.rb
new file mode 100644
index 0000000000..ec5c2051b5
--- /dev/null
+++ b/spec/ruby/library/stringscanner/shared/bol.rb
@@ -0,0 +1,25 @@
+describe :strscan_bol, shared: true do
+ it "returns true if the scan pointer is at the beginning of the line, false otherwise" do
+ s = StringScanner.new("This is a test")
+ s.send(@method).should == true
+ s.scan(/This/)
+ s.send(@method).should == false
+ s.terminate
+ s.send(@method).should == false
+
+ s = StringScanner.new("hello\nworld")
+ s.bol?.should == true
+ s.scan(/\w+/)
+ s.bol?.should == false
+ s.scan(/\n/)
+ s.bol?.should == true
+ s.unscan
+ s.bol?.should == false
+ end
+
+ it "returns true if the scan pointer is at the end of the line of an empty string." do
+ s = StringScanner.new('')
+ s.terminate
+ s.send(@method).should == true
+ end
+end