2016-07-13 09:27:07 -04:00
|
|
|
#frozen_string_literal: false
|
2016-07-05 07:49:39 -04:00
|
|
|
require 'test_helper'
|
2015-04-12 04:36:37 -04:00
|
|
|
require 'time'
|
|
|
|
|
2016-07-13 09:27:07 -04:00
|
|
|
class JSONStringMatchingTest < Test::Unit::TestCase
|
2015-04-12 04:36:37 -04:00
|
|
|
include JSON
|
|
|
|
|
|
|
|
class TestTime < ::Time
|
|
|
|
def self.json_create(string)
|
|
|
|
Time.parse(string)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_json(*)
|
|
|
|
%{"#{strftime('%FT%T%z')}"}
|
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
to_i == other.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_match_date
|
|
|
|
t = TestTime.new
|
|
|
|
t_json = [ t ].to_json
|
2016-07-05 07:49:39 -04:00
|
|
|
time_regexp = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/
|
2015-04-12 04:36:37 -04:00
|
|
|
assert_equal [ t ],
|
2016-07-05 07:49:39 -04:00
|
|
|
parse(
|
|
|
|
t_json,
|
|
|
|
:create_additions => true,
|
|
|
|
:match_string => { time_regexp => TestTime }
|
|
|
|
)
|
2015-04-12 04:36:37 -04:00
|
|
|
assert_equal [ t.strftime('%FT%T%z') ],
|
2016-07-05 07:49:39 -04:00
|
|
|
parse(
|
|
|
|
t_json,
|
|
|
|
:match_string => { time_regexp => TestTime }
|
|
|
|
)
|
2015-04-12 04:36:37 -04:00
|
|
|
end
|
|
|
|
end
|