Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Caret arguments ordering #313

Merged
merged 5 commits into from Nov 20, 2021
Merged

fix Caret arguments ordering #313

merged 5 commits into from Nov 20, 2021

Conversation

hugo-vrijswijk
Copy link
Contributor

line was filled with offset, col was filled with line and offset with col.

I'm guessing at one point Caret was Caret(offset, line, column), but was changed to Caret(line, column, offset) without re-examing argument order.

This caused this behavior:

val p = (Parser.caret.with1 <* Parser.anyChar).rep

val pattern = """aaa"""

val parsed = p.parseAll(pattern).right.get
// parsed: cats.data.NonEmptyList[Caret] = NonEmptyList(Caret(0, 0, 0), List(Caret(1, 0, 1), Caret(2, 0, 2)))

Expected:

// parsed: cats.data.NonEmptyList[Caret] = NonEmptyList(Caret(0, 0, 0), List(Caret(0, 1, 1), Caret(0, 2, 2)))

`line` was filled with `offset`, `col` was filled with `line` and `offset` with `col`.

I'm guessing at one point Caret was `Caret(offset, line, column)`, but was changed to `Caret(line, column, offset)` without re-examing argument order.

This caused this behavior:

```scala
val p = (Parser.caret.with1 <* Parser.anyChar).rep

val pattern = """aaa"""

val parsed = p.parseAll(pattern).right.get
// parsed: cats.data.NonEmptyList[Caret] = NonEmptyList(Caret(0, 0, 0), List(Caret(1, 0, 1), Caret(2, 0, 2)))
```

Expected:
```scala
// parsed: cats.data.NonEmptyList[Caret] = NonEmptyList(Caret(0, 0, 0), List(Caret(0, 1, 1), Caret(0, 2, 2)))
```
@@ -226,7 +226,7 @@ class LocationMapTest extends munit.ScalaCheckSuite {
val lc = lm.toLineCol(offset)

assertEquals(oc, Some(c))
assertEquals(lc, oc.map { case Caret(_, r, c) => (r, c) })
assertEquals(lc, oc.map { case c => (c.line, c.col) })
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we remove the case and the extra space here?

I think you want to run fmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah forgot to run formatting

@@ -226,7 +226,7 @@ class LocationMapTest extends munit.ScalaCheckSuite {
val lc = lm.toLineCol(offset)

assertEquals(oc, Some(c))
assertEquals(lc, oc.map { case Caret(_, r, c) => (r, c) })
assertEquals(lc, oc.map { case c => (c.line, c.col) })
Copy link
Collaborator

Choose a reason for hiding this comment

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

reminder: can we remove the case now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2021

Codecov Report

Merging #313 (f93a66b) into main (95ce42a) will increase coverage by 0.28%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #313      +/-   ##
==========================================
+ Coverage   96.28%   96.56%   +0.28%     
==========================================
  Files           9        9              
  Lines        1049     1049              
  Branches       94       94              
==========================================
+ Hits         1010     1013       +3     
+ Misses         39       36       -3     
Impacted Files Coverage Δ
...shared/src/main/scala/cats/parse/LocationMap.scala 100.00% <100.00%> (ø)
core/shared/src/main/scala/cats/parse/Parser.scala 96.41% <0.00%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95ce42a...f93a66b. Read the comment docs.

Copy link
Collaborator

@johnynek johnynek left a comment

Choose a reason for hiding this comment

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

thanks! sorry I let this bug slip through.

@@ -226,7 +226,7 @@ class LocationMapTest extends munit.ScalaCheckSuite {
val lc = lm.toLineCol(offset)

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually while we are at it can we add: assertEquals(c.offset, offset) to make sure we pass through the offset?

@johnynek johnynek merged commit 00362b4 into typelevel:main Nov 20, 2021
@hugo-vrijswijk hugo-vrijswijk deleted the fix/caret-lines branch November 20, 2021 01:09
@regadas
Copy link
Collaborator

regadas commented Nov 21, 2021

dang it, I actually feel a bit responsible for this issue ... I should have caught it! Sorry about this!

@johnynek
Copy link
Collaborator

No need to apologize!

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.

None yet

4 participants