🧚 A practical web framework for Gleam

Test body functions

Changed files
+47 -4
src
test
-2
src/wisp/testing.gleam
··· 79 79 request(http.Patch, path, headers, <<body:utf8>>) 80 80 } 81 81 82 - // TODO: test 83 82 // TODO: document 84 83 pub fn string_body(response: Response) -> String { 85 84 case response.body { ··· 92 91 } 93 92 } 94 93 95 - // TODO: test 96 94 // TODO: document 97 95 pub fn bit_string_body(response: Response) -> BitString { 98 96 case response.body {
+1
test/fixture.txt
··· 1 + Hello, Joe!
+46 -2
test/wisp/testing_test.gleam
··· 1 - import wisp 2 - import wisp/testing 3 1 import gleam/http 2 + import gleam/http/response 4 3 import gleam/option.{None} 4 + import gleam/string_builder 5 5 import gleeunit/should 6 + import wisp 7 + import wisp/testing 6 8 7 9 pub fn request_test() { 8 10 let request = ··· 254 256 |> wisp.read_body_to_bitstring 255 257 |> should.equal(Ok(<<"wubwub":utf8>>)) 256 258 } 259 + 260 + pub fn string_body_empty_test() { 261 + wisp.ok() 262 + |> response.set_body(wisp.Empty) 263 + |> testing.string_body 264 + |> should.equal("") 265 + } 266 + 267 + pub fn string_body_file_test() { 268 + wisp.ok() 269 + |> response.set_body(wisp.File("test/fixture.txt")) 270 + |> testing.string_body 271 + |> should.equal("Hello, Joe!\n") 272 + } 273 + 274 + pub fn string_body_text_test() { 275 + wisp.ok() 276 + |> response.set_body(wisp.Text(string_builder.from_string("Hello, Joe!"))) 277 + |> testing.string_body 278 + |> should.equal("Hello, Joe!") 279 + } 280 + 281 + pub fn bit_string_body_empty_test() { 282 + wisp.ok() 283 + |> response.set_body(wisp.Empty) 284 + |> testing.bit_string_body 285 + |> should.equal(<<>>) 286 + } 287 + 288 + pub fn bit_string_body_file_test() { 289 + wisp.ok() 290 + |> response.set_body(wisp.File("test/fixture.txt")) 291 + |> testing.bit_string_body 292 + |> should.equal(<<"Hello, Joe!\n":utf8>>) 293 + } 294 + 295 + pub fn bit_string_body_text_test() { 296 + wisp.ok() 297 + |> response.set_body(wisp.Text(string_builder.from_string("Hello, Joe!"))) 298 + |> testing.bit_string_body 299 + |> should.equal(<<"Hello, Joe!":utf8>>) 300 + }