Skip to content

Commit d033697

Browse files
committed
fix: search for empty string
1 parent 2356f65 commit d033697

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Init/Data/String/Pattern/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ inductive SearchStep (s : Slice) where
3838
The subslice starting at {name}`startPos` and ending at {name}`endPos` matches the pattern.
3939
-/
4040
| matched (startPos endPos : s.Pos)
41-
deriving Inhabited
41+
deriving Inhabited, BEq
4242

4343
/--
4444
Provides a conversion from a pattern to an iterator of {name}`SearchStep` that searches for matches

tests/lean/run/string_slice.lean

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,25 @@ Tests for `String.Slice` functions
210210

211211
#guard "abc".toSlice.back = 'c'
212212
#guard "".toSlice.back = (default : Char)
213+
214+
section
215+
open String.Slice.Pattern
216+
217+
instance [Monad n]{s : String.Slice} : Std.Iterators.IteratorCollect (ForwardSliceSearcher s) Id n :=
218+
.defaultImplementation
219+
220+
#guard (ToForwardSearcher.toSearcher "".toSlice "").toList == [.matched "".toSlice.startPos "".toSlice.startPos]
221+
#guard (ToForwardSearcher.toSearcher "abc".toSlice "").toList == [
222+
.matched ("abc".toSlice.pos ⟨0⟩ (by decide)) ("abc".toSlice.pos ⟨0⟩ (by decide)),
223+
.rejected ("abc".toSlice.pos ⟨0⟩ (by decide)) ("abc".toSlice.pos ⟨1⟩ (by decide)),
224+
.matched ("abc".toSlice.pos ⟨1⟩ (by decide)) ("abc".toSlice.pos ⟨1⟩ (by decide)),
225+
.rejected ("abc".toSlice.pos ⟨1⟩ (by decide)) ("abc".toSlice.pos ⟨2⟩ (by decide)),
226+
.matched ("abc".toSlice.pos ⟨2⟩ (by decide)) ("abc".toSlice.pos ⟨2⟩ (by decide)),
227+
.rejected ("abc".toSlice.pos ⟨2⟩ (by decide)) ("abc".toSlice.pos ⟨3⟩ (by decide)),
228+
.matched ("abc".toSlice.pos ⟨3⟩ (by decide)) ("abc".toSlice.pos ⟨3⟩ (by decide)),
229+
]
230+
231+
end
232+
233+
#guard ("".toSlice.split "").toList == ["".toSlice, "".toSlice]
234+
#guard ("abc".toSlice.split "").toList == ["".toSlice, "a".toSlice, "b".toSlice, "c".toSlice, "".toSlice]

0 commit comments

Comments
 (0)