add: json diff viewer#1
Conversation
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
| // ColorizedResponse holds the colorized differences between the expected and actual JSON responses. | ||
| // ExpectedResponse: The colorized string representing the differences in the expected JSON response. | ||
| // ActualResponse: The colorized string representing the differences in the actual JSON response. | ||
| type ColorisedResponse struct { |
| // ExpectedResponse: The colorized string representing the differences in the expected JSON response. | ||
| // ActualResponse: The colorized string representing the differences in the actual JSON response. | ||
| type ColorisedResponse struct { | ||
| ExpectedResponse string |
There was a problem hiding this comment.
these could be expected and actual?
| // json2: The second JSON object to compare. | ||
| // noise: A map containing fields to ignore during the comparison. | ||
| // Returns a ColorizedResponse containing the colorized differences for the expected and actual JSON responses. | ||
| func ColorJSONDiff(json1 []byte, json2 []byte, noise map[string][]string) (ColorisedResponse, error) { |
| // expect: The JSON string containing the expected values. | ||
| // actual: The JSON string containing the actual values. | ||
| // Returns a ColorizedResponse containing the colorized differences for the expected and actual JSON responses. | ||
| func ColorDiff(expect, actual string) ColorisedResponse { |
| // expect: The map containing the expected header values. | ||
| // actual: The map containing the actual header values. | ||
| // Returns a ColorizedResponse containing the colorized differences for the expected and actual headers. | ||
| func ColorHeaderDiff(expect, actual map[string]string) ColorisedResponse { |
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
| End int // End is the ending index of the range. | ||
| } | ||
|
|
||
| // ColorizedResponse holds the colorized differences between the expected and actual JSON responses. |
There was a problem hiding this comment.
Change the comment, since there is not struct named as ColorizedReponse
| } | ||
|
|
||
| // isControlCharacter checks if a character is a control character. | ||
| func isControlCharacter(char rune) bool { |
There was a problem hiding this comment.
Please explain it more. This doesn't explain what a control character is.
| } | ||
|
|
||
| // maxLineLength is the maximum length of a line before it is wrapped. | ||
| const max_line_length = 50 |
|
@shivamsouravjha Add a pipeline to trigger the unit tests. |
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
Signed-off-by: shivamsouravjha <shivamsouravjha@gmail.com>
| if !reflect.DeepEqual(val1, val2) { | ||
| // Marshal values to pretty-printed JSON strings | ||
| val1Str, err := json.MarshalIndent(val1, "", " ") | ||
| if err != nil { |
There was a problem hiding this comment.
why are you not printing the error?
There was a problem hiding this comment.
considering this to be a sdk I thought of not adding print statements.
| } | ||
| val2Str, err := json.MarshalIndent(val2, "", " ") | ||
| if err != nil { | ||
| return |
| nextLine := lines[i+1] | ||
|
|
||
| // Process lines that start with a '-' indicating expected differences. | ||
| if len(line) > 0 && line[0] == '-' && i != len(lines)-1 { |
There was a problem hiding this comment.
Do you think that the condition len(line)>0 can happen anytime?
There was a problem hiding this comment.
yes ,I've explicitly appended empty string in the lines in
lines = insertEmptyLines(lines) // Insert empty lines between consecutive elements with the same symbol.
So that two ++ signs don't come after each other
gouravkrosx
left a comment
There was a problem hiding this comment.
Please address the comments, rest LGTM!
Signed-off-by: shivamsouravjha <2019145@iiitdmj.ac.in>
No description provided.