File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed
LiveViewNativeCore/include
Tests/LiveViewNativeTests Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ pub extern "C" fn document_empty() -> *mut dom::Document {
102
102
#[ export_name = "__liveview_native_core$Document$parse" ]
103
103
pub extern "C" fn document_parse < ' a > (
104
104
text : RustStr < ' a > ,
105
- error : * mut support :: RustString ,
105
+ error : * mut RustString ,
106
106
) -> support:: RustResult {
107
107
match dom:: Document :: parse ( text. to_str ( ) ) {
108
108
Ok ( doc) => {
@@ -114,7 +114,7 @@ pub extern "C" fn document_parse<'a>(
114
114
}
115
115
Err ( err) => {
116
116
unsafe {
117
- error. write ( support :: RustString :: from_string ( err. to_string ( ) ) ) ;
117
+ error. write ( RustString :: from_string ( err. to_string ( ) ) ) ;
118
118
}
119
119
support:: RustResult {
120
120
is_ok : false ,
@@ -124,6 +124,12 @@ pub extern "C" fn document_parse<'a>(
124
124
}
125
125
}
126
126
127
+ #[ export_name = "__liveview_native_core$Document$to_string" ]
128
+ pub extern "C" fn document_to_string ( doc : * mut dom:: Document ) -> RustString {
129
+ let doc = unsafe { & * doc } ;
130
+ RustString :: from_string ( doc. to_string ( ) )
131
+ }
132
+
127
133
#[ export_name = "__liveview_native_core$Document$merge" ]
128
134
pub extern "C" fn document_merge ( doc : * mut dom:: Document , other : * const dom:: Document ) -> bool {
129
135
let doc = unsafe { & mut * doc } ;
Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ public class Document {
65
65
} ) . get ( )
66
66
}
67
67
68
+ /// Renders this document to a `String` for display and comparison
69
+ public func toString( ) -> String {
70
+ let str = RustString ( __liveview_native_core $Document$to_string( self . repr) )
71
+ return str. toString ( )
72
+ }
73
+
68
74
/// Register a callback to be fired when a matching event occurs on this document.
69
75
///
70
76
/// The given callback receives the document to which the event applies, as well as the
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ final class LiveViewNativeTests: XCTestCase {
23
23
XCTAssertEqual ( ctx is MyContext , true )
24
24
( ctx as! MyContext ) . didChange = true
25
25
}
26
+ let rendered1 = doc1. toString ( )
27
+ XCTAssertEqual ( input, rendered1)
26
28
27
29
let updated = """
28
30
<html lang= " en " >
@@ -36,9 +38,14 @@ final class LiveViewNativeTests: XCTestCase {
36
38
</html>
37
39
"""
38
40
let doc2 = try Document . parse ( updated)
41
+ let rendered2 = doc2. toString ( )
42
+ XCTAssertEqual ( updated, rendered2)
39
43
40
44
doc1. merge ( with: doc2)
41
45
42
46
XCTAssertEqual ( context. didChange, true )
47
+
48
+ let finalRender = doc1. toString ( )
49
+ XCTAssertEqual ( finalRender, rendered2)
43
50
}
44
51
}
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ typedef struct __Node {
40
40
__NodeData data ;
41
41
} __Node ;
42
42
43
+ extern _RustString __liveview_native_core$Document$to_string (__Document doc );
44
+
43
45
extern __Document __liveview_native_core$Document$empty ();
44
46
45
47
extern void __liveview_native_core$Document$drop (__Document doc );
You can’t perform that action at this time.
0 commit comments