Created
January 12, 2012 22:47
-
-
Save jfirebaugh/1603645 to your computer and use it in GitHub Desktop.
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
| Encoding.list.each do |encoding| | |
| print "Testing #{encoding.name}" | |
| (0..0xffff).each do |i| | |
| print "." if i % 256 == 0 | |
| begin | |
| result = i.chr(encoding) | |
| rescue RangeError | |
| next | |
| rescue Exception => e | |
| puts "expected #{i}.chr(#{encoding.name.inspect}) to raise RangeError, but it raised #{e.inspect} instead" | |
| next | |
| end | |
| if result.length != 1 | |
| puts "expected #{i}.chr(#{encoding.name.inspect}) to be a single character, but it was #{result.length}" | |
| elsif !result.valid_encoding? | |
| puts "expected #{i}.chr(#{encoding.name.inspect}) to return a validly encoded string, but it returned #{result.inspect} instead" | |
| elsif result.encoding != encoding | |
| puts "expected #{i}.chr(#{encoding.name.inspect}) to be encoded as #{encoding.name}" | |
| elsif result.codepoints.to_a != [i] | |
| puts "expected #{i}.chr(#{encoding.name.inspect}) to encode the codepoint #{i}, but it encoded #{result.codepoints.to_a} instead" | |
| end | |
| end | |
| print "\n" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment