Sha256: 1c06bf71d1e6ab0bd910acecadbd461b8fce055606dafcccd1ef24f0830a56b1

Contents?: true

Size: 1.39 KB

Versions: 11

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class DurationTest < Minitest::Test
  MINUTES_IN_SECONDS = 60
  HOURS_IN_SECONDS = 60 * MINUTES_IN_SECONDS
  DAYS_IN_SECONDS = 24 * HOURS_IN_SECONDS

  TESTS = [
    ['PT0M0S', 0],
    ['PT6M', 6 * MINUTES_IN_SECONDS],
    ['PT90S', 90],
    ['P1D', DAYS_IN_SECONDS],
    ['PT1.5M', 1.5 * MINUTES_IN_SECONDS],
    ['P0.75D', 0.75 * DAYS_IN_SECONDS],
    ['PT1M90.3S', MINUTES_IN_SECONDS + 90.3],
    ['PT1H', HOURS_IN_SECONDS],
    ['PT1.3H', 1.3 * HOURS_IN_SECONDS],
    ['P1.5DT1.5M', 1.5 * DAYS_IN_SECONDS + MINUTES_IN_SECONDS * 1.5],
    ['P1.5DT1.5H1.5M', 1.5 * DAYS_IN_SECONDS + 1.5 * HOURS_IN_SECONDS + MINUTES_IN_SECONDS * 1.5],
    ['P1.5DT1.5H1.5M3.5S', 1.5 * DAYS_IN_SECONDS + 1.5 * HOURS_IN_SECONDS + MINUTES_IN_SECONDS * 1.5 + 3.5],
    ['P1DT2H3M4S', DAYS_IN_SECONDS + 2 * HOURS_IN_SECONDS + 3 * MINUTES_IN_SECONDS + 4],
    ['PT1H30M', HOURS_IN_SECONDS + 30 * MINUTES_IN_SECONDS],
    ['P0.5DT0.25H', 0.5 * DAYS_IN_SECONDS + 0.25 * HOURS_IN_SECONDS],
    ['PT15M30S', 15 * MINUTES_IN_SECONDS + 30],
    ['PT0.000347222H', 0.000347222 * HOURS_IN_SECONDS],
    ['PT23H59M59S', 23 * HOURS_IN_SECONDS + 59 * MINUTES_IN_SECONDS + 59],
    ['P0.25DT3.75H', 0.25 * DAYS_IN_SECONDS + 3.75 * HOURS_IN_SECONDS],
  ]

  def test_parsing
    TESTS.each do |test|
      assert_equal test[1], Prefab::Duration.parse(test[0]), "Failed parsing #{test[0]}"
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.8.7 test/test_duration.rb
prefab-cloud-ruby-1.8.6 test/test_duration.rb
prefab-cloud-ruby-1.8.5 test/test_duration.rb
prefab-cloud-ruby-1.8.4 test/test_duration.rb
prefab-cloud-ruby-1.8.3 test/test_duration.rb
prefab-cloud-ruby-1.8.2 test/test_duration.rb
prefab-cloud-ruby-1.8.1 test/test_duration.rb
prefab-cloud-ruby-1.8.0 test/test_duration.rb
prefab-cloud-ruby-1.7.2 test/test_duration.rb
prefab-cloud-ruby-1.7.1 test/test_duration.rb
prefab-cloud-ruby-1.7.0 test/test_duration.rb