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

Add support for quotation marks in JSON operators #203

Closed
r6q opened this issue May 12, 2022 · 3 comments
Closed

Add support for quotation marks in JSON operators #203

r6q opened this issue May 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@r6q
Copy link

r6q commented May 12, 2022

Problem:
We use different operators in JSONs which are then used for comparison. If we add regular operators to json string, e.g. Len, HasPrefix, etc, the JSON becomes invalid and formatters, validators cannot parse the string.

Proposal:
Add support for quotation marks for operators in JSON strings, similarly to currently it is being used for shortcut operators "$^NotEmpty". Ideally it could look similar "$^Len(10)"

@maxatome
Copy link
Owner

maxatome commented May 12, 2022

Interesting idea, but it is not as easy as it seems as you probably want the following works too:

"$^Bag(SuperMapOf({\"foo\":123}))"

for example, so the JSON parser has to be reentrant as when we get "$^" we are in the lexer

if firstRune == '^' {
and we should not loose the location, in case the user makes a mistake to help him/her to find the origin...

@r6q
Copy link
Author

r6q commented May 17, 2022

Ah, I see, seems relatively complicated. I might try implementing it, whenever I have free time.
Will start off by trying to branch of the logic in a file you mentioned. Thanks!

@maxatome maxatome added the enhancement New feature or request label Jun 1, 2022
@maxatome
Copy link
Owner

maxatome commented Aug 31, 2022

Hi @r6q, if you still need this feature could you review #217 please?

I also added the possibility to have raw string in JSON, useful to avoid escaping double-quotes for strings-in-strings:

// with raw string:
td.Cmp(t, got, td.JSON(`{"name": "$^Re(r<^Bob \\w+$>)"}`))
// without raw string:
td.Cmp(t, got, td.JSON(`{"name": "$^Re(\"^Bob \\\\w+$>\""}`))

Until I write the documentation, all raw strings cases are listed here.

maxatome added a commit that referenced this issue Oct 15, 2022
- introduction of raw strings;
- literal \n, \r & \t accepted in strings;
- $^Operator(params...) is possible;
- "$^Operator(params...)" is possible;
- Operator (without parenthesis) is possible;
- operator shortcuts reimplemented to not be handled specifically.

Closes #203.

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
maxatome added a commit that referenced this issue Oct 15, 2022
- introduction of raw strings;
- literal \n, \r & \t accepted in strings;
- $^Operator(params...) is possible;
- "$^Operator(params...)" is possible;
- Operator (without parenthesis) is possible;
- operator shortcuts reimplemented to not be handled specifically.

Closes #203.

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
maxatome added a commit that referenced this issue Oct 17, 2022
- introduction of raw strings;
- literal \n, \r & \t accepted in strings;
- $^Operator(params...) is possible;
- "$^Operator(params...)" is possible;
- Operator (without parenthesis) is possible;
- operator shortcuts reimplemented to not be handled specifically.

Closes #203.

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants