@@ -115,35 +115,32 @@ impl FunctionExpression for EncodeGzipFn {
115115
116116#[ cfg( test) ]
117117mod test {
118- use base64:: Engine ;
119-
120118 use crate :: value;
121119
122120 use super :: * ;
123121
124- fn decode_base64 ( text : & str ) -> Vec < u8 > {
125- let engine = base64:: engine:: GeneralPurpose :: new (
126- & base64:: alphabet:: STANDARD ,
127- base64:: engine:: general_purpose:: GeneralPurposeConfig :: new ( ) ,
128- ) ;
129-
130- engine. decode ( text) . expect ( "Cannot decode from Base64" )
122+ fn encode ( text : & str , level : flate2:: Compression ) -> Vec < u8 > {
123+ let mut encoder = GzEncoder :: new ( text. as_bytes ( ) , level) ;
124+ let mut output = vec ! [ ] ;
125+ encoder. read_to_end ( & mut output) . unwrap ( ) ;
126+ output
131127 }
132128
133129 test_function ! [
134130 encode_gzip => EncodeGzip ;
135131
136132 with_defaults {
137133 args: func_args![ value: value!( "you_have_successfully_decoded_me.congratulations.you_are_breathtaking." ) ] ,
138- want: Ok ( value!( decode_base64 ( "H4sIAAAAAAAA/w3LgQ3AIAgEwI1ciVD8qqmVRKAJ29cBLjWo8weyEIHZHXMmVYhWVHpRRFfb7DHZhy4reQBv0LXB3p2fsVr5AXeBkepGAAAA" ) . as_bytes( ) ) ) ,
134+ want: Ok ( value!( encode ( "you_have_successfully_decoded_me.congratulations.you_are_breathtaking." , flate2 :: Compression :: default ( ) ) . as_bytes( ) ) ) ,
139135 tdef: TypeDef :: bytes( ) . infallible( ) ,
140136 }
141137
142138 with_custom_compression_level {
143139 args: func_args![ value: value!( "you_have_successfully_decoded_me.congratulations.you_are_breathtaking." ) , compression_level: 9 ] ,
144- want: Ok ( value!( decode_base64 ( "H4sIAAAAAAAC/w3LgQ3AIAgEwI1ciVD8qqmVRKAJ29cBLjWo8weyEIHZHXMmVYhWVHpRRFfb7DHZhy4reQBv0LXB3p2fsVr5AXeBkepGAAAA" ) . as_bytes( ) ) ) ,
140+ want: Ok ( value!( encode ( "you_have_successfully_decoded_me.congratulations.you_are_breathtaking." , flate2 :: Compression :: new ( 9 ) ) . as_bytes( ) ) ) ,
145141 tdef: TypeDef :: bytes( ) . infallible( ) ,
146142 }
143+
147144 invalid_constant_compression {
148145 args: func_args![ value: value!( "test" ) , compression_level: 11 ] ,
149146 want: Err ( "compression level must be <= 10" ) ,
0 commit comments