]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Improve tests of sexp-conv.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 2 Oct 2025 17:13:06 +0000 (19:13 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 2 Oct 2025 17:13:06 +0000 (19:13 +0200)
tools/sexp-conv-test

index 9ebdeea8c3db512aeb3ce20c26aa710aed18c0f3..c1cb7b3d7b9c2e71e663e4031e29b79183613f84 100755 (executable)
@@ -76,6 +76,22 @@ test_canonical () {
     fi
 }
 
+test_hash () {
+    print_raw "$1" test.in
+    if $EMULATOR ./sexp-conv$EXEEXT --hash=sha256 <test.in >test1.out ; then
+       true
+    else
+       exit 1
+    fi
+    print_nl "$2" test2.out
+
+    if cmp test1.out test2.out ; then
+       true
+    else
+       exit 1;
+    fi
+}
+
 test_advanced '0:' '""'
 test_advanced '3:foo' 'foo'
 test_advanced '12:fooooooooooo' 'fooooooooooo'
@@ -97,6 +113,8 @@ bar)' '(foo ; gazonk
      bar)'
 
 test_advanced '(foo[bar]foo)' '(foo [bar]foo)'
+test_advanced 'foo bar' 'foo
+bar'
 
 test_advanced '(#aabb#)' '(|qrs=|)'
 test_advanced '(|qrs=|)' '(|qrs=|)'
@@ -110,6 +128,8 @@ test_transport '()' '{KCk=}'
 test_transport '1:A' '{MTpB}'
 test_transport 'foo' '{Mzpmb28=}'
 test_transport '(foo bar baz)' '{KDM6Zm9vMzpiYXIzOmJheik=}'
+test_transport 'foo bar' '{Mzpmb28=}
+{MzpiYXI=}'
 
 test_canonical '""' '0:'
 test_canonical '{MDo=}' '0:'
@@ -119,6 +139,11 @@ test_canonical 'foo' '3:foo'
 test_canonical 'fooooooooooo' '12:fooooooooooo'
 test_canonical 'fooooooooo' '10:fooooooooo'
 test_canonical '(foo bar baz)' '(3:foo3:bar3:baz)'
+test_canonical 'foo bar' '3:foo3:bar'
 test_canonical '{KDM6Zm9vMzpiYXIzOmJheik=}' '(3:foo3:bar3:baz)'
 
+test_hash '""' 'ba768b331fd86cec803be04e56ab2b3d4c0e98ef4ee4fcd4e72ad7cce61a1d1f'
+test_hash '(foo bar baz)' '8f881b925600176cf30cbec63a94087b4e13e6c04dd6f46a7d2481fe2a073c6a'
+test_hash 'foo bar' 'bdf3c778043c2b05b4c6d398ab924e747fee44055cd8048ee237c544945a8cb2
+5dd05adb6d766bdde7a1f612d32e97ee93d2f318b01a90c616c06ff4c0d3fe3b'
 exit 0