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

Partial key (#65) #4013

Merged
merged 3 commits into from May 20, 2024
Merged

Partial key (#65) #4013

merged 3 commits into from May 20, 2024

Conversation

AlexCue987
Copy link
Contributor

@AlexCue987 AlexCue987 commented May 10, 2024

If a key is missing in json, try finding a valid subpath:

   "Failure message states if key is missing, shows valid subpath" {
      shouldFail {
         json.shouldContainJsonKeyValue("$.store.bicycle.engine", "V2")
      }.message shouldBe """
         Expected given to contain json key <'$.store.bicycle.engine'> but key was not found. Found shorter valid subpath: <'$.store.bicycle'>
      """.trimIndent()
   }

I had to add a few public methods, as I couldn't invoke internal ones from a public inline function.

Also made sure that we distinguish between these two cases:

  • key not found
  • key found, the corresponding value is null

Ideally we short also find indexes out of bound such as

      json.shouldContainJsonKeyValue("$.store.book[2].author", "Evelyn Waugh")

saying <'$.store.book'> has only 2 elements

But that might be done later in another PR. WDYT @Kantis ?

@sksamuel
Copy link
Member

Can you add @KotestInternal to the classes you exposed. That's our way of saying they shouldn't be public but have to be.

@AlexCue987
Copy link
Contributor Author

Can you add @KotestInternal to the classes you exposed. That's our way of saying they shouldn't be public but have to be.

done

@Kantis
Copy link
Member

Kantis commented May 20, 2024

IMO I would prefer if the tests focused more on the matcher and less on the helper functions, but let's merge anyway

@Kantis Kantis added this pull request to the merge queue May 20, 2024
@Kantis
Copy link
Member

Kantis commented May 20, 2024

And yes, let's deal with array indices in a later PR :)

Merged via the queue into kotest:master with commit 6f371fb May 20, 2024
15 checks passed
@AlexCue987 AlexCue987 deleted the json-partial-path-match branch May 21, 2024 11:50
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

3 participants