Skip to content

Add tests for getLines utility#365

Merged
miorel merged 5 commits intocode-chronicles-code:mainfrom
Ma-hawaj:getlinesUtilTest
Aug 24, 2024
Merged

Add tests for getLines utility#365
miorel merged 5 commits intocode-chronicles-code:mainfrom
Ma-hawaj:getlinesUtilTest

Conversation

@Ma-hawaj
Copy link
Contributor

closes #325

making it take into account other new line characters
@Ma-hawaj Ma-hawaj requested a review from miorel as a code owner August 21, 2024 10:16

import { getLines } from "../getLines";

describe("chunkBySize", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe("chunkBySize", () => {
describe("getLines", () => {

export function* getLines(text: string): Generator<string, void, void> {
for (const [line] of text.matchAll(/[^\n]+\n?|\n/g)) {
for (const [line] of text.matchAll(
/[^\n\v\f\r]+(\n|\r|\v|\f)?|(\n|\r|\v|\f)/g,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for thinking about different kinds of new lines. I think this is actually not entirely correct, because it won't do the right thing for Windows. On Windows new lines are usually not just one character, but two, specifically "\r\n". So "hello\r\nworld\r\n" is two lines, but I think this regex will break it into "hello\r", "\n", "world\r", and "\n" when we just wanted "hello\r\n" and "world\r\n". It might even be nice to have a test case testing exactly this.

Let's stick to only handling \n for now, using the old regex. If a need arises to handle other kinds of new lines, we can update it later.

@miorel miorel requested review from elimanzo and simona1 August 21, 2024 14:29
Copy link
Contributor

@miorel miorel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, thank you!

@miorel miorel merged commit 0ad30de into code-chronicles-code:main Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for getLines utility

2 participants