Skip to content

Commit

Permalink
update readme with new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Peinhardt authored and Benjamin Peinhardt committed May 24, 2023
1 parent 5dacba1 commit c446268
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ We are using the grammar from [rfc 4180](https://datatracker.ietf.org/doc/html/r
#### Example

```gleam
"Ben, 25,\" TRUE\n\r\"\"\"\nAustin, 25, FALSE"
|> gsv.to_lists
|> should.equal(Ok([
["Ben", " 25", " TRUE\n\r\""],
["Austin", " 25", " FALSE"],
]))
import gsv.{Unix, Windows}
pub fn main() {
let csv_str = "Hello, World\nGoodbye, Mars"
// Parse a CSV string to a List(List(String))
let assert Ok(records) = gsv.to_lists(csv_str)
// Write a List(List(String)) to a CSV string
let csv_str = records
|> gsv.from_lists(separator: ",", line_ending: Windows)
}
```

## Quick start
Expand Down
20 changes: 16 additions & 4 deletions test/gsv_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gleeunit
import gleeunit/should
import internal/token.{CR, Comma, Doublequote, LF, Textdata, scan}
import internal/ast.{parse}
import gsv
import gsv.{Unix, Windows}
import gleam/list
import gleam/result
import gleam/int
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn decode_to_type_test() {
pub fn encode_test() {
let assert Ok(lls) = gsv.to_lists("Ben, 25\nAustin, 21")
lls
|> gsv.from_lists(separator: ",", line_ending: gsv.Unix)
|> gsv.from_lists(separator: ",", line_ending: Unix)
|> should.equal("Ben, 25\nAustin, 21")
}

Expand All @@ -117,7 +117,7 @@ pub fn encode_with_escaped_string_test() {
|> gsv.to_lists

lls
|> gsv.from_lists(separator: ",", line_ending: gsv.Unix)
|> gsv.from_lists(separator: ",", line_ending: Unix)
|> should.equal("Ben, 25,\" TRUE\n\r\"\" \"\nAustin, 25, FALSE")
}

Expand All @@ -127,6 +127,18 @@ pub fn encode_with_escaped_string_windows_test() {
|> gsv.to_lists

lls
|> gsv.from_lists(separator: ",", line_ending: gsv.Windows)
|> gsv.from_lists(separator: ",", line_ending: Windows)
|> should.equal("Ben, 25,\" TRUE\n\r\"\" \"\r\nAustin, 25, FALSE")
}

pub fn for_the_readme_test() {
let csv_str = "Hello, World\nGoodbye, Mars"

// Parse a CSV string to a List(List(String))
let assert Ok(records) = gsv.to_lists(csv_str)

// Write a List(List(String)) to a CSV string
records
|> gsv.from_lists(separator: ",", line_ending: Windows)
|> should.equal("Hello, World\r\nGoodbye, Mars")
}

0 comments on commit c446268

Please sign in to comment.