blob: 144859abc92a8c3c157b30cd6dc85860633bd094 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# encoding: binary
require_relative '../../spec_helper'
require 'strscan'
describe "StringScanner#get_byte" do
it "scans one byte and returns it" do
s = StringScanner.new('abc5.')
s.get_byte.should == 'a'
s.get_byte.should == 'b'
s.get_byte.should == 'c'
s.get_byte.should == '5'
s.get_byte.should == '.'
end
it "is not multi-byte character sensitive" do
s = StringScanner.new("\244\242")
s.get_byte.should == "\244"
s.get_byte.should == "\242"
end
it "returns nil at the end of the string" do
# empty string case
s = StringScanner.new('')
s.get_byte.should == nil
s.get_byte.should == nil
# non-empty string case
s = StringScanner.new('a')
s.get_byte # skip one
s.get_byte.should == nil
end
describe "#[] successive call with a capture group name" do
# https://github.com/ruby/strscan/issues/139
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil" do
s = StringScanner.new("This is a test")
s.get_byte
s.should.matched?
s[:a].should be_nil
end
end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError" do
s = StringScanner.new("This is a test")
s.get_byte
s.should.matched?
-> { s[:a] }.should raise_error(IndexError)
end
end
it "returns a matching character when given Integer index" do
s = StringScanner.new("This is a test")
s.get_byte
s[0].should == "T"
end
# https://github.com/ruby/strscan/issues/135
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("This is a test")
s.exist?(/(?<a>This)/)
s.should.matched?
s[:a].should == "This"
s.get_byte
s.should.matched?
s[:a].should be_nil
end
end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("This is a test")
s.exist?(/(?<a>This)/)
s.should.matched?
s[:a].should == "This"
s.get_byte
s.should.matched?
-> { s[:a] }.should raise_error(IndexError)
end
end
end
end
|