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

Implement toBe(LITERAL), not just toBe_TODO() #49

Merged
merged 6 commits into from
Dec 27, 2023
Merged

Conversation

nedtwigg
Copy link
Member

No description provided.

@nedtwigg
Copy link
Member Author

So this test passes

fun toBe_writeTODO() {
ut_mirror().lineWith("expectSelfie").setContent(" expectSelfie(1234).toBe_TODO()")
gradleReadSSFail()
gradleWriteSS()
ut_mirror().lineWith("expectSelfie").content() shouldBe " expectSelfie(1234).toBe(1234)"
gradleReadSS()
}

And this one fails

@Test @Order(3)
fun toBe_writeLiteral() {
ut_mirror().lineWith("expectSelfie").setContent(" expectSelfie(7777).toBe(1234)")
gradleReadSSFail()
gradleWriteSS()
ut_mirror().lineWith("expectSelfie").content() shouldBe " expectSelfie(7777).toBe(7777)"
gradleReadSS()
}

Because

  • SourceFile::parseToBe_TODO is implemented, but SourceFile::parseToBe is not implemented yet
    • fun parseToBe_TODO(lineOneIndexed: Int): ToBeLiteral {
      val lineContent = contentSlice.unixLine(lineOneIndexed)
      val idx = lineContent.indexOf(".toBe_TODO()")
      if (idx == -1) {
      throw AssertionError(
      "Expected to find `.toBe_TODO()` on line $lineOneIndexed, but there was only `${lineContent}`")
      }
      return ToBeLiteral(lineContent.subSequence(idx, idx + ".toBe_TODO()".length))
      }
      fun parseToBe(lineOneIndexed: Int): ToBeLiteral {
      TODO("More complicated because we have to actually parse the literal")
      }
  • SourceFile.ToBeLiteral::parseLiteral is not implemented yet
    • /**
      * Parses the current value of the value within `.toBe()`. This method should not be called on
      * `toBe_TODO()`.
      */
      fun <T : Any> parseLiteral(literalFormat: LiteralFormat<T>): T {
      // this won't work, because we need to find the `.toBe` and parens
      TODO("return literalFormat.parse(slice.toString())")
      }

@jknack can you take a whack at finishing this PR sometime this week if you have time? Once you do, we should be able to run through the rest of the roadmap without much obstacle:

@nedtwigg
Copy link
Member Author

I just fixed up this branch with all the changes on main, but the tasks above are unchanged.

@nedtwigg nedtwigg closed this Dec 21, 2023
@nedtwigg nedtwigg deleted the feat/inline-tobe branch December 21, 2023 23:58
@nedtwigg nedtwigg restored the feat/inline-tobe branch December 22, 2023 18:09
@nedtwigg nedtwigg reopened this Dec 22, 2023
@nedtwigg
Copy link
Member Author

Sorry @jknack, I deleted this branch on accident, it's still a needed WIP and the next piece of work I have for you if you end up having any more time in 2023.

@jknack
Copy link
Collaborator

jknack commented Dec 27, 2023

@nedtwigg implemented handling of () while parsing .toBe

- parse '()' to extract literal values
- TODO: do we need to handle nested '()'
- TODO: handle '()' inside string literal
Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
var opened = 0
val startIndex = idx + prefix.length
var endIndex = -1
// TODO: do we need to detect paired parenthesis ( ( ) )?
Copy link
Member Author

@nedtwigg nedtwigg Dec 27, 2023

Choose a reason for hiding this comment

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

Cases we need to handle:

.toBe("""
(((
"
(((
""")
// or
.toBe(
  "(((\n" +
  "\"\n" +
   "(((")

Cases we do not need to handle

.toBe(("a" + "b") + "c")

We should add support for these in future PRs, there are many hard cases, we should do the easy stuff first (""" literals) and then solve problems as they come.

Copy link
Member Author

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

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

Huzzah!!

@nedtwigg nedtwigg mentioned this pull request Dec 27, 2023
10 tasks
@nedtwigg
Copy link
Member Author

Happy holidays @jknack, great to have you back! I will merge this, it's great! Next up you can burn through this list:

For testing on many of them, I think we don't need the overhead of the SomeClass extends Harness / UT_SomeClass stuff, we should be able to just operate on plain-old strings.

@nedtwigg nedtwigg merged commit 0e9a3a4 into main Dec 27, 2023
6 checks passed
@nedtwigg nedtwigg deleted the feat/inline-tobe branch December 28, 2023 03:31
nedtwigg added a commit that referenced this pull request Apr 4, 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.

None yet

2 participants