From feac15c1f3479f7d7641480a4608f3ac5d3b2fca Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 19 Sep 2023 11:36:25 +0900 Subject: [PATCH] [ruby/securerandom] Extract `assert_uuid_v7` https://github.com/ruby/securerandom/commit/029677584d --- test/ruby/test_random_formatter.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/test/ruby/test_random_formatter.rb b/test/ruby/test_random_formatter.rb index 7c3003e02d..f927522d96 100644 --- a/test/ruby/test_random_formatter.rb +++ b/test/ruby/test_random_formatter.rb @@ -75,29 +75,22 @@ module Random::Formatter assert_match(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/, uuid) end - def test_uuid_v7 - t1 = current_uuid7_time - uuid = @it.uuid_v7 - t3 = current_uuid7_time + def assert_uuid_v7(**opts) + t1 = current_uuid7_time(**opts) + uuid = @it.uuid_v7(**opts) + t3 = current_uuid7_time(**opts) assert_match(/\A\h{8}-\h{4}-7\h{3}-[89ab]\h{3}-\h{12}\z/, uuid) - t2 = get_uuid7_time(uuid) + t2 = get_uuid7_time(uuid, **opts) assert_operator(t1, :<=, t2) assert_operator(t2, :<=, t3) end - def test_uuid_v7_extra_timestamp_bits + def test_uuid_v7 + assert_uuid_v7 0.upto(12) do |extra_timestamp_bits| - t1 = current_uuid7_time extra_timestamp_bits: extra_timestamp_bits - uuid = @it.uuid_v7 extra_timestamp_bits: extra_timestamp_bits - t3 = current_uuid7_time extra_timestamp_bits: extra_timestamp_bits - - assert_match(/\A\h{8}-\h{4}-7\h{3}-[89ab]\h{3}-\h{12}\z/, uuid) - - t2 = get_uuid7_time uuid, extra_timestamp_bits: extra_timestamp_bits - assert_operator(t1, :<=, t2) - assert_operator(t2, :<=, t3) + assert_uuid_v7 extra_timestamp_bits: extra_timestamp_bits end end