msaraiva / exsamples

Initializes lists of maps, structs or keyword lists using tabular data in Elixir
MIT License
121 stars 8 forks source link

Feature request: binary keys for maps #1

Closed olivermt closed 2 years ago

olivermt commented 8 years ago

I am using this stuff to functionally test api endpoints, and keys there are always strings and not atoms.

Right now I have to Enum.into every sample I use.

msaraiva commented 8 years ago

It looks like a nice addition. I think we have two options:

1- Add an extra option to samples. Something like:

    samples stringify_keys: true do
      :name       | :country        | :city
      "Christian" | "United States" | "New York City"
      "Peter"     | "Austria"       | "Vienna"
    end

2- Let define the first row as strings:

    samples do
      "name"      | "country"       | "city"
      "Christian" | "United States" | "New York City"
      "Peter"     | "Austria"       | "Vienna"
    end

Still not sure which one would be better. I'll take a look at it.

olivermt commented 8 years ago

I think the first one is better in terms of backwards compability at least.

OvermindDL1 commented 8 years ago

Second is best for consistency though, and I am not sure how it would not be backwards incompatible either?

Malian commented 2 years ago

I am voting for (2) for consistency as

samples do
  %{}   | "name"      | "country"       | "city"
  user1 | "Christian" | "United States" | "New York City"
  user2 | "Ingrid"    |   "Austria"     | "Salzburg"
end

already returns string keys

[
  %{"city" => "New York City", "country" => "United States", "name" => "Christian"},
  %{"city" => "Salzburg", "country" => "Austria", "name" => "Ingrid"}
]

I made a PR for those who want to test: https://github.com/msaraiva/exsamples/pull/5

msaraiva commented 2 years ago

Fixed in #5.