Skip to content

Commit

Permalink
patch from_dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Sep 26, 2024
1 parent d1843bc commit 2f35591
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## v2.0.1 - 26 September 2024
- Patch to consider all headers in from_dicts.

## v2.0.0 - 24 September 2024
- Now there are four public functions, `to_lists`, `to_dicts`, `from_lists` and `from_dicts`.

Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "gsv"
version = "2.0.0"
version = "2.0.1"
gleam = ">= 0.32.0"
description = "A simple csv parser and generator written in gleam "

Expand Down
9 changes: 5 additions & 4 deletions src/gsv.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ pub fn from_dicts(
) -> String {
case input {
[] -> ""
[first_row, ..] -> {
_ -> {
let headers =
first_row
|> dict.to_list
|> list.map(pair.first)
input
|> list.map(dict.keys)
|> list.flatten
|> list.unique
|> list.sort(string.compare)

let rows =
Expand Down
15 changes: 15 additions & 0 deletions test/gsv_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,18 @@ pub fn dicts_with_empty_values_test() {
dict.from_list([#("age", "27"), #("name", "Austin")]),
])
}

pub fn dicts_with_missing_values_test() {
let data = [
dict.from_list([#("name", "Lucy"), #("score", "100"), #("colour", "Pink")]),
dict.from_list([
#("name", "Isaac"),
#("youtube", "@IsaacHarrisHolt"),
#("score", "99"),
]),
]
gsv.from_dicts(data, ",", gsv.Unix)
|> should.equal(
"colour,name,score,youtube\nPink,Lucy,100\nIsaac,99,@IsaacHarrisHolt",
)
}

0 comments on commit 2f35591

Please sign in to comment.