<commit_before>require 'helper'

class TestDatatypes < Test::Unit::TestCase
  def test_pointer
    data = {
      Parse::Protocol::KEY_CLASS_NAME => "DatatypeTestClass",
      Parse::Protocol::KEY_OBJECT_ID => "<KEY>"
    }
    p = Parse::Pointer.new data

    assert_equal p.to_json, "{\"__type\":\"Pointer\",\"#{Parse::Protocol::KEY_CLASS_NAME}\":\"DatatypeTestClass\",\"#{Parse::Protocol::KEY_OBJECT_ID}\":\"12345abcd\"}"
  end

  def test_date
    date_time = DateTime.now
    data = date_time
    parse_date = Parse::Date.new data

    assert_equal parse_date.value, date_time
    assert_equal JSON.parse(parse_date.to_json)["iso"], date_time.iso8601(3)
    assert_equal 0, parse_date <=> parse_date
    assert_equal 0, Parse::Date.new(data) <=> Parse::Date.new(data)

    post = Parse::Object.new("Post")
    post["time"] = parse_date
    post.save
    q = Parse.get("Post", post.id)
    assert_equal parse_date.utc, q["time"].utc
  end

  def test_bytes
    data = {
      "base64" => Base64.encode64("testing bytes!")
    }
    byte = Parse::Bytes.new data

    assert_equal byte.value, "testing bytes!"
    assert_equal JSON.parse(byte.to_json)[Parse::Protocol::KEY_TYPE], Parse::Protocol::TYPE_BYTES
    assert_equal JSON.parse(byte.to_json)["base64"], Base64.encode64("testing bytes!")
  end
<commit_msg>improved test that actually serializes back and forth with parse<commit_after>require 'helper'

class TestDatatypes < Test::Unit::TestCase
  def test_pointer
    data = {
      Parse::Protocol::KEY_CLASS_NAME => "DatatypeTestClass",
      Parse::Protocol::KEY_OBJECT_ID => "<KEY>"
    }
    p = Parse::Pointer.new data

    assert_equal p.to_json, "{\"__type\":\"Pointer\",\"#{Parse::Protocol::KEY_CLASS_NAME}\":\"DatatypeTestClass\",\"#{Parse::Protocol::KEY_OBJECT_ID}\":\"12345abcd\"}"
  end

  def test_date
    date_time = DateTime.now
    data = date_time
    parse_date = Parse::Date.new data

    assert_equal parse_date.value, date_time
    assert_equal JSON.parse(parse_date.to_json)["iso"], date_time.iso8601(3)
    assert_equal 0, parse_date <=> parse_date
    assert_equal 0, Parse::Date.new(data) <=> Parse::Date.new(data)

    post = Parse::Object.new("Post")
    post["time"] = parse_date
    post.save
    q = Parse.get("Post", post.id)

    # time zone from parse is utc so string formats don't compare equal,
    # also floating points vary a bit so only equality after rounding to millis is guaranteed
    assert_equal parse_date.to_time.utc.to_datetime.iso8601(3), q["time"].to_time.utc.to_datetime.iso8601(3)
  end

  def test_bytes
    data = {
      "base64" => Base64.encode64("testing bytes!")
    }
    byte = Parse::Bytes.new data

    assert_equal byte.value, "testing bytes!"
    assert_equal JSON.parse(byte.to_json)[Parse::Protocol::KEY_TYPE], Parse::Protocol::TYPE_BYTES
    assert_equal JSON.parse(byte.to_json)["base64"], Base64.encode64("testing bytes!")
  end

{'fraction_non_alphanumeric': 0.1456544142906218, 'fraction_numerical': 0.01992442459635864, 'mean_word_length': 4.144876325088339, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4001623', 'n_tokens_mistral': 1008, 'n_tokens_neox': 967, 'n_words': 186}