Sha256: 913bdd950279a2848ea2f688b210222c50fe2af0255c615b35c0ff40e4170ad3

Contents?: true

Size: 1.57 KB

Versions: 29

Compression:

Stored size: 1.57 KB

Contents

#! /usr/bin/env ruby -S rspec

require 'spec_helper'

describe "the to_bytes function" do
  let(:scope) { PuppetlabsSpec::PuppetInternals.scope }

  it "should exist" do
    Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
  end

  it "should raise a ParseError if there is less than 1 arguments" do
    lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
  end

  it "should convert kB to B" do
    result = scope.function_to_bytes(["4 kB"])
    result.should(eq(4096))
  end

  it "should work without B in unit" do
    result = scope.function_to_bytes(["4 k"])
    result.should(eq(4096))
  end

  it "should work without a space before unit" do
    result = scope.function_to_bytes(["4k"])
    result.should(eq(4096))
  end

  it "should work without a unit" do
    result = scope.function_to_bytes(["5678"])
    result.should(eq(5678))
  end

  it "should convert fractions" do
    result = scope.function_to_bytes(["1.5 kB"])
    result.should(eq(1536))
  end

  it "should convert scientific notation" do
    result = scope.function_to_bytes(["1.5e2 B"])
    result.should(eq(150))
  end

  it "should do nothing with a positive number" do
    result = scope.function_to_bytes([5678])
    result.should(eq(5678))
  end

  it "should should raise a ParseError if input isn't a number" do
    lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
  end

  it "should should raise a ParseError if prefix is unknown" do
    lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
freighthop-0.6.1 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.6.0 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.5.2 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.5.1 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.5.0 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.4.1 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.4.0 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.3.3 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.3.2 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.3.1 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.3.0 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.2.1 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.2.0 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.1.0 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.0.6 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.0.5 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.0.4 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.0.3 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.0.2 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
freighthop-0.0.1 modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb