@@ -15,33 +15,42 @@ import Testing
1515struct EncodingTests {
1616 let backslash : UInt8 = 92
1717
18- #if canImport(Foundation)
18+ private func uint8Array_equals_string( array: [ UInt8 ] , string: String ) -> Bool {
19+ #if canImport(Foundation)
20+ return String ( data: Data ( array) , encoding: . utf8) == string
21+ #endif
22+ return true
23+ }
1924
20- // MARK: utf8Array
21- @Test func encoding_utf8Array( ) {
22- var expected_result : String = #html( option ( attributes: [ . class( [ " row " ] ) ] , value: " wh'at? " ) )
23- var uint8Array : [ UInt8 ] = #html( encoding: . utf8Bytes,
24- option ( attributes: [ . class( [ " row " ] ) ] , value: " wh'at? " )
25- )
26- #expect( String ( data : Data ( uint8Array) , encoding : . utf8 ) == expected_result)
27- #expect( uint8Array. firstIndex ( of: backslash) == nil )
25+ // MARK: utf8Array
26+ @Test func encoding_utf8Array( ) {
27+ var expected_result : String = #html( option ( attributes: [ . class( [ " row " ] ) ] , value: " wh'at? " ) )
28+ var uint8Array : [ UInt8 ] = #html( encoding: . utf8Bytes,
29+ option ( attributes: [ . class( [ " row " ] ) ] , value: " wh'at? " )
30+ )
31+ #expect( uint8Array_equals_string ( array : uint8Array, string : expected_result) )
32+ #expect( uint8Array. firstIndex ( of: backslash) == nil )
2833
29- expected_result = #html( div ( attributes: [ . htmx( . request( js: false , timeout: nil , credentials: " true " , noHeaders: nil ) ) ] ) )
30- uint8Array = #html( encoding: . utf8Bytes,
31- div ( attributes: [ . htmx( . request( js: false , timeout: nil , credentials: " true " , noHeaders: nil ) ) ] )
32- )
33- #expect( String ( data : Data ( uint8Array) , encoding : . utf8 ) == expected_result)
34- #expect( uint8Array. firstIndex ( of: backslash) == nil )
34+ expected_result = #html( div ( attributes: [ . htmx( . request( js: false , timeout: nil , credentials: " true " , noHeaders: nil ) ) ] ) )
35+ uint8Array = #html( encoding: . utf8Bytes,
36+ div ( attributes: [ . htmx( . request( js: false , timeout: nil , credentials: " true " , noHeaders: nil ) ) ] )
37+ )
38+ #expect( uint8Array_equals_string ( array : uint8Array, string : expected_result) )
39+ #expect( uint8Array. firstIndex ( of: backslash) == nil )
3540
36- let set : Set < Data ? > = Set ( HTMXTests . dictionary_json_results ( tag: " div " , closingTag: true , attribute: " hx-headers " , delimiter: " ' " , [ " womp " : " womp " , " ding dong " : " d1tched " , " EASY " : " C,L.a;P! " ] ) . map ( {
37- $0. data ( using: . utf8)
38- } ) )
39- uint8Array = #html( encoding: . utf8Bytes,
40- div ( attributes: [ . htmx( . headers( js: false , [ " womp " : " womp " , " ding dong " : " d1tched " , " EASY " : " C,L.a;P! " ] ) ) ] )
41- )
42- #expect( set. contains ( Data ( uint8Array) ) )
43- #expect( uint8Array. firstIndex ( of: backslash) == nil )
44- }
41+ uint8Array = #html( encoding: . utf8Bytes,
42+ div ( attributes: [ . htmx( . headers( js: false , [ " womp " : " womp " , " ding dong " : " d1tched " , " EASY " : " C,L.a;P! " ] ) ) ] )
43+ )
44+ #if canImport(Foundation)
45+ let set : Set < Data ? > = Set ( HTMXTests . dictionary_json_results ( tag: " div " , closingTag: true , attribute: " hx-headers " , delimiter: " ' " , [ " womp " : " womp " , " ding dong " : " d1tched " , " EASY " : " C,L.a;P! " ] ) . map ( {
46+ $0. data ( using: . utf8)
47+ } ) )
48+ #expect( set. contains ( Data ( uint8Array) ) )
49+ #endif
50+ #expect( uint8Array. firstIndex ( of: backslash) == nil )
51+ }
52+
53+ #if canImport(Foundation)
4554
4655 // MARK: foundationData
4756 @Test func encoding_foundationData( ) {
0 commit comments