Skip to content

Commit

Permalink
fix scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
thatstoasty committed Aug 28, 2024
1 parent a2ed7f0 commit 502e020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gojo/bufio/scan.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct Scanner[R: io.Reader, split: SplitFunction = scan_lines]():
# First, shift data to beginning of buffer if there's lots of empty space
# or space is needed.
if self.start > 0 and (self.end == len(self.buf) or self.start > int(len(self.buf) / 2)):
_ = copy(self.buf, self.as_bytes_slice()[self.start : self.end])
memcpy(self.buf.unsafe_ptr(), self.buf.unsafe_ptr().offset(self.start), self.end - self.start)
self.end -= self.start
self.start = 0

Expand Down
19 changes: 8 additions & 11 deletions tests/test_bufio_scanner.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fn test_scan_words():
var i = 0

while scanner.scan():
print(scanner.current_token(), expected_results[i])
test.assert_equal(scanner.current_token(), expected_results[i])
i += 1

Expand Down Expand Up @@ -59,8 +58,6 @@ fn scan_no_newline_test(test_case: String, result_lines: List[String], test: Moj
test.assert_equal(scanner.current_token(), result_lines[i])
i += 1

test.assert_equal(i, len(result_lines))


fn test_scan_lines_no_newline():
var test = MojoTest("Testing bufio.scan_lines with no final newline")
Expand Down Expand Up @@ -152,11 +149,11 @@ fn test_scan_runes():

fn main() raises:
test_scan_words()
# test_scan_lines()
# test_scan_lines_no_newline()
# test_scan_lines_cr_no_newline()
# test_scan_lines_empty_final_line()
# test_scan_lines_cr_empty_final_line()
# test_scan_bytes()
# test_file_wrapper_scanner()
# test_scan_runes()
test_scan_lines()
test_scan_lines_no_newline()
test_scan_lines_cr_no_newline()
test_scan_lines_empty_final_line()
test_scan_lines_cr_empty_final_line()
test_scan_bytes()
test_file_wrapper_scanner()
test_scan_runes()

0 comments on commit 502e020

Please sign in to comment.