Sha256: d24d5b8c600a582b961e4239fb7556b04898aa76bc05fe733f73df7b8ccb7969

Contents?: true

Size: 1.45 KB

Versions: 19

Compression:

Stored size: 1.45 KB

Contents

require "spec_helper"
require "utils/hash_transform_keys"

RSpec.describe Metanorma::Utils do
  it "deep stringify hash but skip values" do
    result = {
      test0: :test0,
      test1: false,
      test2: {
        test20: :test20,
      },
      test3: %i(test31 test32 test33),
      test4: [
        {
          test41: :test41,
        },
      ],
    }.stringify_all_keys

    expect(result).to include("test0", "test1", "test2", "test3", "test4")
    expect(result["test0"]).to eq(:test0)
    expect(result["test2"]).to include("test20")
    expect(result["test2"]["test20"]).to eq(:test20)
    expect(result["test3"]).to include(:test31, :test32, :test33)
    expect(result["test4"][0]).to include("test41")
    expect(result["test4"][0]["test41"]).to eq(:test41)
  end

  it "deep symbolize hash but skip values" do
    result = {
      test0: "test0",
      test1: false,
      test2: {
        test20: "test20",
      },
      test3: %w(test31 test32 test33),
      test4: [
        {
          test41: "test41",
        },
      ],
    }.stringify_all_keys.symbolize_all_keys

    expect(result).to include(:test0, :test1, :test2, :test3, :test4)
    expect(result[:test0]).to eq("test0")
    expect(result[:test2]).to include(:test20)
    expect(result[:test2][:test20]).to eq("test20")
    expect(result[:test3]).to include("test31", "test32", "test33")
    expect(result[:test4][0]).to include(:test41)
    expect(result[:test4][0][:test41]).to eq("test41")
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
metanorma-utils-1.3.1 spec/hash_transform_keys_spec.rb
metanorma-utils-1.3.0 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.9 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.8 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.7 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.6 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.5 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.4 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.3 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.2 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.1 spec/hash_transform_keys_spec.rb
metanorma-utils-1.2.0 spec/hash_transform_keys_spec.rb
metanorma-utils-1.1.0 spec/hash_transform_keys_spec.rb
metanorma-utils-1.0.9 spec/hash_transform_keys_spec.rb
metanorma-utils-1.0.8 spec/hash_transform_keys_spec.rb
metanorma-utils-1.0.7 spec/hash_transform_keys_spec.rb
metanorma-utils-1.0.6 spec/hash_transform_keys_spec.rb
metanorma-utils-1.0.5 spec/hash_transform_keys_spec.rb
metanorma-utils-1.0.4 spec/hash_transform_keys_spec.rb