Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # encoding: utf-8
  2. # Run this with 1.9.2 or 1.9.3
  3.  
  4. require 'psych'
  5. require 'minitest/autorun'
  6. require 'date'
  7.  
  8.  
  9. class ZOMGTest < MiniTest::Unit::TestCase
  10.   # Quoted strings are assumed to be Strings
  11.   def test_json
  12.     json = <<EOF
  13. {
  14.   "date_a": "2011-07-22T09:54:44Z",
  15.   "city": "wroc\u0142aw",               # after this the next date is not parsed anymore!
  16.   "date_b": "2011-07-22T09:54:44Z"
  17. }
  18. EOF
  19.     hash = Psych.load json
  20.     assert_equal "wrocław", hash['city']
  21.   end
  22.  
  23.   # Tagged string literals are typecast
  24.   def test_yaml
  25.     yaml = <<EOF
  26. {
  27.   "date_a": ! "2011-07-22T09:54:44Z",
  28.   "city": "wroc\u0142aw",               # after this the next date is not parsed anymore!
  29.   "date_b": ! "2011-07-22T09:54:44Z"
  30. }
  31. EOF
  32.     hash = Psych.load yaml
  33.     assert_kind_of Time, hash['date_a']
  34.   end
  35. end