Skip to content

Commit ef4a7d0

Browse files
chancedanonrig
authored andcommitted
updates Debug to include ada_get_components output`
1 parent 7702d1e commit ef4a7d0

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub mod ffi {
9191
base: *const c_char,
9292
base_length: usize,
9393
) -> bool;
94-
pub fn ada_get_url_components(url: *mut ada_url) -> ada_url_components;
94+
pub fn ada_get_components(url: *mut ada_url) -> ada_url_components;
9595

9696
// Getters
9797
pub fn ada_get_origin(url: *mut ada_url) -> ada_owned_string;
@@ -502,7 +502,18 @@ impl std::convert::AsRef<[u8]> for Url {
502502

503503
impl std::fmt::Debug for Url {
504504
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
505-
write!(f, "\"{}\"", self.href())
505+
let components = unsafe { ffi::ada_get_components(self.url) };
506+
f.debug_struct("Url")
507+
.field("href", &self.href())
508+
.field("protocol_end", &components.protocol_end)
509+
.field("username_end", &components.username_end)
510+
.field("host_start", &components.host_start)
511+
.field("host_end", &components.host_end)
512+
.field("port", &components.port)
513+
.field("pathname_start", &components.pathname_start)
514+
.field("search_start", &components.search_start)
515+
.field("hash_start", &components.hash_start)
516+
.finish()
506517
}
507518
}
508519

@@ -559,6 +570,17 @@ impl std::str::FromStr for Url {
559570
#[cfg(test)]
560571
mod test {
561572
use super::*;
573+
574+
#[test]
575+
fn spike_debug() {
576+
// TODO: This is a spike test to see if the debug output is correct. Update or remove this test once clarified that the output is as expected - @chanced
577+
let tests = [("https://www.ada-url.com/playground")];
578+
for value in tests {
579+
let url = Url::parse(value, None).expect("Should have parsed url");
580+
println!("{:?}", url);
581+
}
582+
}
583+
562584
#[test]
563585
fn should_display_serialization() {
564586
let tests = [
@@ -572,6 +594,7 @@ mod test {
572594
assert_eq!(url.to_string(), expected);
573595
}
574596
}
597+
575598
#[test]
576599
fn should_parse_with_try_from() {
577600
let tests = [("http://example.com/", true), ("invalid url", false)];

0 commit comments

Comments
 (0)