Created
October 26, 2025 22:38
-
-
Save SamSaffron/0bfdcd2023c568728d3e903e940d602e to your computer and use it in GitHub Desktop.
bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require "psych" | |
| require "psych/pure" | |
| yaml_source = <<~YAML | |
| --- | |
| before_array: value1 | |
| # Comment before the problematic array | |
| flow_array_with_comment: [ | |
| 'item1', 'item2', 'item3', # inline comment here | |
| ] | |
| # Comment after the array | |
| after_array: value2 | |
| nested_structure: | |
| key1: value1 | |
| key2: value2 | |
| YAML | |
| puts "=== Original YAML ===" | |
| puts yaml_source | |
| # Load with Psych::Pure (comment-preserving) | |
| config = Psych::Pure.load( | |
| yaml_source, | |
| comments: true, | |
| aliases: true, | |
| permitted_classes: [Symbol, Date, Time, Set] | |
| ) | |
| puts "\n=== After Load + Dump ===" | |
| dumped = Psych::Pure.dump(config) | |
| puts dumped | |
| puts "\n=== Traditional Parse Comparison ===" | |
| # Parse both with traditional Psych to compare data | |
| original_parsed = Psych.load(yaml_source) | |
| dumped_parsed = Psych.load(dumped) | |
| puts "Original keys: #{original_parsed.keys.inspect}" | |
| puts "Dumped keys: #{dumped_parsed.keys.inspect}" | |
| puts "\nOriginal parsed:" | |
| puts original_parsed.inspect | |
| puts "\nDumped parsed:" | |
| puts dumped_parsed.inspect | |
| # Check if data matches | |
| if original_parsed == dumped_parsed | |
| puts "\n✓ PASS: Data is identical" | |
| exit 0 | |
| else | |
| puts "\n✗ FAIL: Data was corrupted during round-trip!" | |
| missing_keys = original_parsed.keys - dumped_parsed.keys | |
| extra_keys = dumped_parsed.keys - original_parsed.keys | |
| puts " Missing keys after dump: #{missing_keys.inspect}" unless missing_keys.empty? | |
| puts " Extra keys after dump: #{extra_keys.inspect}" unless extra_keys.empty? | |
| exit 1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment