2 test_description="hex encoding and decoding"
3 . $(dirname "$0")/test-lib.sh || exit 1
5 if [ -n "${NOTMUCH_TEST_INSTALLED-}" ]; then
9 test_begin_subtest "round trip"
10 find $NOTMUCH_SRCDIR/test/corpora/default -type f -print | sort | xargs cat > EXPECTED
11 $TEST_DIRECTORY/hex-xcode --direction=encode < EXPECTED | $TEST_DIRECTORY/hex-xcode --direction=decode > OUTPUT
12 test_expect_equal_file EXPECTED OUTPUT
14 test_begin_subtest "punctuation"
15 tag1='comic_swear=$&^%$^%\\//-+$^%$'
16 tag_enc1=$($TEST_DIRECTORY/hex-xcode --direction=encode "$tag1")
17 test_expect_equal "$tag_enc1" "comic_swear=%24%26%5e%25%24%5e%25%5c%5c%2f%2f-+%24%5e%25%24"
19 test_begin_subtest "round trip newlines"
20 printf 'this\n tag\t has\n spaces\n' > EXPECTED.$test_count
21 $TEST_DIRECTORY/hex-xcode --direction=encode < EXPECTED.$test_count |\
22 $TEST_DIRECTORY/hex-xcode --direction=decode > OUTPUT.$test_count
23 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
25 test_begin_subtest "round trip 8bit chars"
26 echo '%c3%91%c3%a5%c3%b0%c3%a3%c3%a5%c3%a9-%c3%8f%c3%8a' > EXPECTED.$test_count
27 $TEST_DIRECTORY/hex-xcode --direction=decode < EXPECTED.$test_count |\
28 $TEST_DIRECTORY/hex-xcode --direction=encode > OUTPUT.$test_count
29 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
31 test_begin_subtest "round trip (in-place)"
32 find $NOTMUCH_SRCDIR/test/corpora/default -type f -print | sort | xargs cat > EXPECTED
33 $TEST_DIRECTORY/hex-xcode --in-place --direction=encode < EXPECTED |\
34 $TEST_DIRECTORY/hex-xcode --in-place --direction=decode > OUTPUT
35 test_expect_equal_file EXPECTED OUTPUT
37 test_begin_subtest "punctuation (in-place)"
38 tag1='comic_swear=$&^%$^%\\//-+$^%$'
39 tag_enc1=$($TEST_DIRECTORY/hex-xcode --in-place --direction=encode "$tag1")
40 test_expect_equal "$tag_enc1" "comic_swear=%24%26%5e%25%24%5e%25%5c%5c%2f%2f-+%24%5e%25%24"
42 test_begin_subtest "round trip newlines (in-place)"
43 printf 'this\n tag\t has\n spaces\n' > EXPECTED.$test_count
44 $TEST_DIRECTORY/hex-xcode --in-place --direction=encode < EXPECTED.$test_count |\
45 $TEST_DIRECTORY/hex-xcode --in-place --direction=decode > OUTPUT.$test_count
46 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count
48 test_begin_subtest "round trip 8bit chars (in-place)"
49 echo '%c3%91%c3%a5%c3%b0%c3%a3%c3%a5%c3%a9-%c3%8f%c3%8a' > EXPECTED.$test_count
50 $TEST_DIRECTORY/hex-xcode --in-place --direction=decode < EXPECTED.$test_count |\
51 $TEST_DIRECTORY/hex-xcode --in-place --direction=encode > OUTPUT.$test_count
52 test_expect_equal_file EXPECTED.$test_count OUTPUT.$test_count