aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/blake3/b3sum/src/unit_tests.rs
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-11-07 14:49:13 +0100
committerGitHub Enterprise <[email protected]>2025-11-07 14:49:13 +0100
commit24e43a913f29ac3b314354e8ce5175f135bcc64f (patch)
treeca442937ceeb63461012b33a4576e9835099f106 /thirdparty/blake3/b3sum/src/unit_tests.rs
parentget oplog attachments (#622) (diff)
downloadzen-24e43a913f29ac3b314354e8ce5175f135bcc64f.tar.xz
zen-24e43a913f29ac3b314354e8ce5175f135bcc64f.zip
switch to xmake for package management (#611)
This change removes our dependency on vcpkg for package management, in favour of bringing some code in-tree in the `thirdparty` folder as well as using the xmake build-in package management feature. For the latter, all the package definitions are maintained in the zen repo itself, in the `repo` folder. It should now also be easier to build the project as it will no longer depend on having the right version of vcpkg installed, which has been a common problem for new people coming in to the codebase. Now you should only need xmake to build. * Bumps xmake requirement on github runners to 2.9.9 to resolve an issue where xmake on Windows invokes cmake with `v144` toolchain which does not exist * BLAKE3 is now in-tree at `thirdparty/blake3` * cpr is now in-tree at `thirdparty/cpr` * cxxopts is now in-tree at `thirdparty/cxxopts` * fmt is now in-tree at `thirdparty/fmt` * robin-map is now in-tree at `thirdparty/robin-map` * ryml is now in-tree at `thirdparty/ryml` * sol2 is now in-tree at `thirdparty/sol2` * spdlog is now in-tree at `thirdparty/spdlog` * utfcpp is now in-tree at `thirdparty/utfcpp` * xmake package repo definitions is in `repo` * implemented support for sanitizers. ASAN is supported on windows, TSAN, UBSAN, MSAN etc are supported on Linux/MacOS though I have not yet tested it extensively on MacOS * the zencore encryption implementation also now supports using mbedTLS which is used on MacOS, though for now we still use openssl on Linux * crashpad * bumps libcurl to 8.11.0 (from 8.8.0) which should address a rare build upload bug
Diffstat (limited to 'thirdparty/blake3/b3sum/src/unit_tests.rs')
-rw-r--r--thirdparty/blake3/b3sum/src/unit_tests.rs235
1 files changed, 235 insertions, 0 deletions
diff --git a/thirdparty/blake3/b3sum/src/unit_tests.rs b/thirdparty/blake3/b3sum/src/unit_tests.rs
new file mode 100644
index 000000000..75f672b4c
--- /dev/null
+++ b/thirdparty/blake3/b3sum/src/unit_tests.rs
@@ -0,0 +1,235 @@
+use std::path::Path;
+
+#[test]
+fn test_parse_check_line() {
+ // =========================
+ // ===== Success Cases =====
+ // =========================
+
+ // the basic case
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "0909090909090909090909090909090909090909090909090909090909090909 foo",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x09; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, "foo");
+ assert_eq!(file_path, Path::new("foo"));
+
+ // regular whitespace
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "fafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa \t\r\n\n\r \t\r\n\n\r",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0xfa; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, " \t\r\n\n\r \t");
+ assert_eq!(file_path, Path::new(" \t\r\n\n\r \t"));
+
+ // path is one space
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "4242424242424242424242424242424242424242424242424242424242424242 ",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x42; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, " ");
+ assert_eq!(file_path, Path::new(" "));
+
+ // *Unescaped* backslashes. Note that this line does *not* start with a
+ // backslash, so something like "\" + "n" is interpreted as *two*
+ // characters. We forbid all backslashes on Windows, so this test is
+ // Unix-only.
+ if cfg!(not(windows)) {
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "4343434343434343434343434343434343434343434343434343434343434343 fo\\a\\no",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x43; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, "fo\\a\\no");
+ assert_eq!(file_path, Path::new("fo\\a\\no"));
+ }
+
+ // escaped newlines
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "\\4444444444444444444444444444444444444444444444444444444444444444 fo\\r\\n\\n\\ro",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x44; 32]));
+ assert!(is_escaped);
+ assert_eq!(file_string, "fo\\r\\n\\n\\ro");
+ assert_eq!(file_path, Path::new("fo\r\n\n\ro"));
+
+ // Escaped newline and backslash. Again because backslash is not allowed on
+ // Windows, this test is Unix-only.
+ if cfg!(not(windows)) {
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "\\4545454545454545454545454545454545454545454545454545454545454545 fo\\n\\\\o",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x45; 32]));
+ assert!(is_escaped);
+ assert_eq!(file_string, "fo\\n\\\\o");
+ assert_eq!(file_path, Path::new("fo\n\\o"));
+ }
+
+ // non-ASCII path
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "4646464646464646464646464646464646464646464646464646464646464646 否认",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x46; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, "否认");
+ assert_eq!(file_path, Path::new("否认"));
+
+ // untagged separator " " in the file name
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "4747474747474747474747474747474747474747474747474747474747474747 foo bar",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x47; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, "foo bar");
+ assert_eq!(file_path, Path::new("foo bar"));
+
+ // tagged separator ") = " in the file name
+ let crate::ParsedCheckLine {
+ file_string,
+ is_escaped,
+ file_path,
+ expected_hash,
+ } = crate::parse_check_line(
+ "BLAKE3 (foo) = bar) = 4848484848484848484848484848484848484848484848484848484848484848",
+ )
+ .unwrap();
+ assert_eq!(expected_hash, blake3::Hash::from([0x48; 32]));
+ assert!(!is_escaped);
+ assert_eq!(file_string, "foo) = bar");
+ assert_eq!(file_path, Path::new("foo) = bar"));
+
+ // =========================
+ // ===== Failure Cases =====
+ // =========================
+
+ // too short
+ crate::parse_check_line("").unwrap_err();
+ crate::parse_check_line("0").unwrap_err();
+ crate::parse_check_line("00").unwrap_err();
+ crate::parse_check_line("0000000000000000000000000000000000000000000000000000000000000000")
+ .unwrap_err();
+ crate::parse_check_line("0000000000000000000000000000000000000000000000000000000000000000 ")
+ .unwrap_err();
+
+ // not enough spaces
+ crate::parse_check_line("0000000000000000000000000000000000000000000000000000000000000000 foo")
+ .unwrap_err();
+
+ // capital letter hex
+ crate::parse_check_line(
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA foo",
+ )
+ .unwrap_err();
+
+ // non-hex hex
+ crate::parse_check_line(
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx foo",
+ )
+ .unwrap_err();
+
+ // non-ASCII hex
+ crate::parse_check_line("你好, 我叫杰克. 认识你很高兴. 要不要吃个香蕉? foo").unwrap_err();
+
+ // invalid escape sequence
+ crate::parse_check_line(
+ "\\0000000000000000000000000000000000000000000000000000000000000000 fo\\o",
+ )
+ .unwrap_err();
+
+ // truncated escape sequence
+ crate::parse_check_line(
+ "\\0000000000000000000000000000000000000000000000000000000000000000 foo\\",
+ )
+ .unwrap_err();
+
+ // null char
+ crate::parse_check_line(
+ "0000000000000000000000000000000000000000000000000000000000000000 fo\0o",
+ )
+ .unwrap_err();
+
+ // Unicode replacement char
+ crate::parse_check_line(
+ "0000000000000000000000000000000000000000000000000000000000000000 fo�o",
+ )
+ .unwrap_err();
+
+ // On Windows only, backslashes are not allowed, escaped or otherwise.
+ if cfg!(windows) {
+ crate::parse_check_line(
+ "0000000000000000000000000000000000000000000000000000000000000000 fo\\o",
+ )
+ .unwrap_err();
+ crate::parse_check_line(
+ "\\0000000000000000000000000000000000000000000000000000000000000000 fo\\\\o",
+ )
+ .unwrap_err();
+ }
+}
+
+#[test]
+fn test_filepath_to_string() {
+ let output = crate::filepath_to_string(Path::new("foo"));
+ assert_eq!(output.filepath_string, "foo");
+ assert!(!output.is_escaped);
+
+ let output = crate::filepath_to_string(Path::new("f\\ \t\r\noo"));
+ if cfg!(windows) {
+ // We normalize backslashes to forward slashes on Windows.
+ assert_eq!(output.filepath_string, "f/ \t\\r\\noo");
+ } else {
+ assert_eq!(output.filepath_string, "f\\\\ \t\\r\\noo");
+ }
+ assert!(output.is_escaped);
+}