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

Unit tests #9

Open
gllmflndn opened this issue Jun 25, 2020 · 4 comments
Open

Unit tests #9

gllmflndn opened this issue Jun 25, 2020 · 4 comments

Comments

@gllmflndn
Copy link

Hi @Abdallah-Elshamy

Thanks for the comprehensive list of unit tests. They highlighted one difference between JSONio and jsonencode/jsondecode (test 22: b = instead of b = ) that I was not aware of.

Concerning the other points mentioned on the maintainers mailing list, for JSONio, I have added some extra options, Indent and ReplacementStyle, defaulting to Matlab. Perhaps a similar approach could be taken for Octave?

@Abdallah-Elshamy
Copy link
Owner

Hello @gllmflndn

I am glad that the unit tests were helpful to you.

A human-readable format ("pretty" indentation) for JSON is already on the list for jsonencode. Adding a style for replacement is a good idea and I will discuss it with the community before writing jsonencode. Thanks for mentioning that.

@siko1056
Copy link
Contributor

siko1056 commented Jul 9, 2020

The ReplacementStyle option is described for JSONio here

https://github.com/gllmflndn/JSONio/blob/6c699a315ac2c578864d8b740a061bff47b718bf/jsonread.m#L6-L9

and for Matlab matlab.lang.makeValidName here

https://www.mathworks.com/help/matlab/ref/matlab.lang.makevalidname.html#namevaluepairarguments

and might be a nice addition to cope with non-alphanumeric characters. The following works in Octave, but is considered as "invalid fieldname" in Matlab R2020b:

>> struct ("4number!", 3.14)
ans =

  scalar structure containing the fields:

    4number! = 3.1400

@Abdallah-Elshamy your jsondecode.cc currently follows Matlab

>> jsondecode ('{"4number!": 3.14}')
ans =

  scalar structure containing the fields:

    x4number_ = 3.1400

So the big idea is to just forward jsondecode (..., "ReplacementStyle", style) to matlab.lang.makeValidName

https://github.com/Abdallah-Elshamy/octave/blob/933e6ff0b47fb85e7cbe72b30bcd1660eb86deff/libinterp/corefcn/jsondecode.cc#L68-L71

Sounds good to me. Maybe you can also implement jsondecode (..., "Prefix", prefix) by forwarding varargin {2:end} to matlab.lang.makeValidName. This way we can also fix leading numbers in struct keys, like in the example above.

https://www.mathworks.com/help/matlab/ref/matlab.lang.makevalidname.html#namevaluepairarguments

@Abdallah-Elshamy
Copy link
Owner

Hi,

I have added the "ReplacementStyle" and "Prefix" options here in 7b96f44. I followed the suggested idea and forwarded the options to matlab.lang.makeValidName.

If you have any comments, please let me know

@Abdallah-Elshamy Abdallah-Elshamy transferred this issue from Abdallah-Elshamy/octave Jul 18, 2020
@Abdallah-Elshamy
Copy link
Owner

Hello all,

I added the "PrettyWriter" option in 3c75468. I also added the "ReplacementStyle" and "Prefix" options here in 27c37af.

If there is any other suggestions or comments, please let me know.
Thanks for your suggestions.

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

No branches or pull requests

3 participants