Skip to content

Commit

Permalink
Add test for #38
Browse files Browse the repository at this point in the history
This tests that a string with ä in it round-trips properly
  • Loading branch information
brendanlong committed Nov 11, 2018
1 parent 2eae60a commit 4eea38e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pgx/src/pgx_value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ let to_point = Option.map to_point'

let of_string t = Some t

let to_string_exn = required (fun t -> t)
let to_string t = t
let to_string_exn = required to_string

let unit = Some ""

Expand Down
26 changes: 26 additions & 0 deletions pgx_test/src/pgx_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,32 @@ module Make_tests (IO : Pgx.IO) = struct
| _ -> assert false))
>>| List.iter (fun () -> ())
)
; "UTF-8 partial round-trip", (fun () ->
(* TODO: We should probably add more round-trip tests *)
let expect = "test-ä-test" in
with_conn (fun db ->
simple_query db "CREATE TEMPORARY TABLE this_test (id text)"
>>= fun _ ->
execute db ~params:[ Pgx.Value.of_string expect]
"INSERT INTO this_test (id) VALUES ($1)"
>>= fun _ ->
execute db "SELECT id FROM this_test"
>>| function
| [[ result ]] -> assert_equal (Some expect) (Pgx.Value.to_string result)
| _ -> assert false
)
)
; "UTF-8 round-trip", (fun () ->
(* TODO: We should probably add more round-trip tests *)
let expect = "test-ä-test" in
with_conn (fun db ->
execute db ~params:[ Pgx.Value.of_string expect ]
"SELECT $1::VARCHAR"
>>| function
| [[ result ]] -> assert_equal (Some expect) (Pgx.Value.to_string result)
| _ -> assert false
)
)
] in
make_tests "pgx_async" tests
>>| run_test_tt_main ~exit
Expand Down

0 comments on commit 4eea38e

Please sign in to comment.