aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2021-08-22 19:37:42 +0100
committerLouis Pilfold <louis@lpil.uk>2021-08-23 16:08:19 +0100
commit7c261986cf3139bac7c37089e5df4f513a65506e (patch)
treefc8c633c9d81e0cc648ec1a3da2b82d8d6596151
parent188319d5620126442635124f143ad7ff66455ebe (diff)
downloadgleam_stdlib-7c261986cf3139bac7c37089e5df4f513a65506e.tar.gz
gleam_stdlib-7c261986cf3139bac7c37089e5df4f513a65506e.zip
Fragment
-rw-r--r--src/gleam/uri.gleam5
-rw-r--r--test/gleam/uri_test.gleam12
2 files changed, 16 insertions, 1 deletions
diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam
index 8e49c5b..53c695a 100644
--- a/src/gleam/uri.gleam
+++ b/src/gleam/uri.gleam
@@ -237,7 +237,10 @@ if erlang {
/// ```
///
pub fn to_string(uri: Uri) -> String {
- let parts = []
+ let parts = case uri.fragment {
+ Some(fragment) -> ["#", fragment]
+ _ -> []
+ }
let parts = [uri.path, ..parts]
let parts = case uri.host, string.starts_with(uri.path, "/") {
Some(host), False if host != "" -> ["/", ..parts]
diff --git a/test/gleam/uri_test.gleam b/test/gleam/uri_test.gleam
index 46ac2a5..34c8a68 100644
--- a/test/gleam/uri_test.gleam
+++ b/test/gleam/uri_test.gleam
@@ -96,6 +96,10 @@ pub fn scheme_to_string_test() {
uri.Uri(Some("https"), None, None, None, "/one/two", None, None)
|> uri.to_string
|> should.equal("https:/one/two")
+
+ uri.Uri(None, None, None, None, "noslash", None, Some("frag"))
+ |> uri.to_string
+ |> should.equal("noslash#frag")
}
pub fn host_to_string_test() {
@@ -118,6 +122,14 @@ pub fn host_to_string_test() {
uri.Uri(None, None, Some(""), None, "", None, None)
|> uri.to_string
|> should.equal("//")
+
+ uri.Uri(None, None, Some("example.com"), None, "noslash", None, Some("ok"))
+ |> uri.to_string
+ |> should.equal("//example.com/noslash#ok")
+
+ uri.Uri(None, None, Some(""), None, "", None, Some("ok"))
+ |> uri.to_string
+ |> should.equal("//#ok")
}
pub fn port_to_string_test() {