-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * wip * not working * Moving 4 positions before try_read * tests * Add Swift test * bump version * feedback updates * remove useeless use * Create from String and expose Url * fix test
- Loading branch information
1 parent
b05189d
commit e8cb924
Showing
11 changed files
with
118 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sargon" | ||
version = "1.1.1" | ||
version = "1.1.2" | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
apple/Sources/Sargon/Extensions/Methods/Prelude/FfiUrl+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
|
||
#if DEBUG | ||
import XCTestDynamicOverlay | ||
#endif // DEBUG | ||
|
||
extension FfiUrl { | ||
public var url: URL { | ||
ffiUrlGetUrl(ffiUrl: self) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apple/Sources/Sargon/Extensions/Swiftified/Prelude/FfiUrl+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Foundation | ||
|
||
extension FfiUrl: @unchecked Sendable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import Sargon | ||
import SargonUniFFI | ||
import XCTest | ||
|
||
final class FfiUrlTests: TestCase { | ||
func test_url() throws { | ||
let url = URL(string: "https://radixdlt.com/")! | ||
let sut = try FfiUrl(urlPath: url.absoluteString) | ||
XCTAssertEqual(sut.url, url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::prelude::*; | ||
|
||
/// A wrapper around `Url` that allows us to safely deal with Urls generated on hosts. | ||
/// | ||
/// Context: We have defined a custom type conversion between Rust's `Url` and the hosts analogues. | ||
/// However, a Url could be considered valid on host but not on Rust. For example, Swift allows to build a Url | ||
/// from string `"invalid input"`, while Rust doesn't. | ||
/// | ||
/// Therefore, if a given Rust function expects a `Url` as param and is sent one from host side which is invalid, | ||
/// the code will panic. However, if we send the wrapper instead, we make sure the conversion is safely done on the | ||
/// host side, dealing with the failing conversion properly rather than panicking. | ||
#[derive(Debug, PartialEq, Eq, Hash, uniffi::Object, derive_more::Display)] | ||
#[uniffi::export(Debug, Display, Eq, Hash)] | ||
pub struct FfiUrl { | ||
pub url: Url, | ||
} | ||
|
||
#[uniffi::export] | ||
impl FfiUrl { | ||
#[uniffi::constructor] | ||
pub fn new(url_path: String) -> Result<Self> { | ||
Self::from_str(&url_path) | ||
} | ||
} | ||
|
||
#[uniffi::export] | ||
pub fn ffi_url_get_url(ffi_url: &FfiUrl) -> Url { | ||
ffi_url.url.clone() | ||
} | ||
|
||
impl FromStr for FfiUrl { | ||
type Err = CommonError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let url = parse_url(s)?; | ||
Ok(Self { url }) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[allow(clippy::upper_case_acronyms)] | ||
type SUT = FfiUrl; | ||
|
||
#[test] | ||
fn test_new() { | ||
let url_path = "https://radixdlt.com"; | ||
let result = SUT::new(url_path.to_string()); | ||
assert_eq!(result.unwrap().url, Url::parse(url_path).unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_from_str() { | ||
let result = SUT::from_str("https://radixdlt.com"); | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[test] | ||
fn test_get_url() { | ||
let url_path = "https://radixdlt.com"; | ||
let sut = SUT::new(url_path.to_string()).unwrap(); | ||
assert_eq!(ffi_url_get_url(&sut), Url::parse(url_path).unwrap()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod ffi_url; | ||
|
||
pub use ffi_url::*; |