-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compress.gzip: change the endianness for validation to conform to the…
- Loading branch information
Showing
14 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
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,41 @@ | ||
import os | ||
import compress.gzip | ||
|
||
const samples_folder = os.join_path(os.dir(@FILE), 'samples') | ||
|
||
fn s(fname string) string { | ||
return os.join_path(samples_folder, fname) | ||
} | ||
|
||
fn read_and_decode_file(fpath string) !([]u8, string) { | ||
compressed := os.read_bytes(fpath)! | ||
decoded := gzip.decompress(compressed)! | ||
content := decoded.bytestr() | ||
return compressed, content | ||
} | ||
|
||
fn test_reading_and_decoding_a_known_gziped_file() { | ||
compressed, content := read_and_decode_file(s('known.gz'))! | ||
assert compressed#[0..3] == [u8(31), 139, 8] | ||
assert compressed#[-5..] == [u8(127), 115, 1, 0, 0] | ||
assert content.contains('## Description:') | ||
assert content.contains('## Examples:') | ||
assert content.ends_with('```\n') | ||
} | ||
|
||
fn test_decoding_all_samples_files() { | ||
for gz_file in os.walk_ext(samples_folder, '.gz') { | ||
_, content := read_and_decode_file(gz_file)! | ||
assert content.len > 0, 'decoded content should not be empty: `${content}`' | ||
} | ||
} | ||
|
||
fn test_reading_gzip_files_compressed_with_different_options() { | ||
_, content1 := read_and_decode_file(s('readme_level_1.gz'))! | ||
_, content5 := read_and_decode_file(s('readme_level_5.gz'))! | ||
_, content9 := read_and_decode_file(s('readme_level_9.gz'))! | ||
_, content9_rsyncable := read_and_decode_file(s('readme_level_9_rsyncable.gz'))! | ||
assert content9_rsyncable == content9 | ||
assert content9 == content5 | ||
assert content5 == content1 | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.