| 1 | module yaml |
| 2 | |
| 3 | import x.json2 |
| 4 | |
| 5 | // json_logically_eq compares two JSON strings by decoding and re-encoding |
| 6 | // both sides via json2, normalizing whitespace and treating an empty input |
| 7 | // as the literal "null" document. |
| 8 | // |
| 9 | // For tests only. Lives in a non-_test.v file because V compiles each |
| 10 | // `_test.v` file as its own binary, so a helper cannot otherwise be shared |
| 11 | // across the module's test files. Not exported (lowercase name) so it stays |
| 12 | // invisible to consumers of `yaml`. |
| 13 | fn json_logically_eq(a string, b string) !bool { |
| 14 | a_norm := if a.trim_space() == '' { 'null' } else { a } |
| 15 | b_norm := if b.trim_space() == '' { 'null' } else { b } |
| 16 | pa := json2.decode[json2.Any](a_norm)! |
| 17 | pb := json2.decode[json2.Any](b_norm)! |
| 18 | return json2.encode(pa, json2.EncoderOptions{}) == json2.encode(pb, json2.EncoderOptions{}) |
| 19 | } |
| 20 | |