Fix unions that includes enums and a default value #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We fixed the enums defaults in this PR: #87. All tests passed correctly but when we execute this code against Grafana cue files, the results isn't the expected one.
I didn't add tests because I don't know how to write the cue structure to reproduce the case from there 😞.Edit: We could find the way to reproduce the use case 😄. Also, because the test needs nested struct defaults to pass, I need to update the code to allow these defaults.
It happens when we set an Enum and a default value:
We expecting to have the following code:
But its generating:
Why was the reason? Because the struct that Cuetsy received is slightly different.
In our tests:
Grafana cue:
[] (string) ├── [.] (string) │ ├── (struct) │ ├── "#Enum" │ └── [ref:#Enum] │ └── [|] (string) @cuetsy(kind="enum") │ ├── "a" │ ├── "b" │ └── "c" └── [*] └── "a"
We can see that the second one doesn't have the "a" value and we weren't analyse the
cue.NoOp
case for this.So the solution is detecting the
Selector
operator from the first value (the Enum) to avoid to confusing it with values with validators that reaches this point (Ex:uint32 & >0 | *9
), and add the default value like an existing one.