Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created August 5, 2011 20:32
Show Gist options
  • Save tenderlove/1128445 to your computer and use it in GitHub Desktop.
Save tenderlove/1128445 to your computer and use it in GitHub Desktop.
# encoding: utf-8
# Run this with 1.9.2 or 1.9.3
require 'psych'
require 'minitest/autorun'
require 'date'
class ZOMGTest < MiniTest::Unit::TestCase
# Quoted strings are assumed to be Strings
def test_json
json = <<EOF
{
"date_a": "2011-07-22T09:54:44Z",
"city": "wroc\u0142aw", # after this the next date is not parsed anymore!
"date_b": "2011-07-22T09:54:44Z"
}
EOF
hash = Psych.load json
assert_equal "wrocław", hash['city']
end
# Tagged string literals are typecast
def test_yaml
yaml = <<EOF
{
"date_a": ! "2011-07-22T09:54:44Z",
"city": "wroc\u0142aw", # after this the next date is not parsed anymore!
"date_b": ! "2011-07-22T09:54:44Z"
}
EOF
hash = Psych.load yaml
assert_kind_of Time, hash['date_a']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment