aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2021-05-22 20:12:25 +0200
committerLibravatar Rutger Broekhoff2021-05-22 20:12:25 +0200
commit4716921ce42b5153b5c60edf3638e1592f72f743 (patch)
treea895cd71a8aa7c3c4255249b268c00e75ec49895
parentdd5e276c483852afd9b294b6d3559af46ef819a0 (diff)
downloadzig-nkeys-4716921ce42b5153b5c60edf3638e1592f72f743.tar.gz
zig-nkeys-4716921ce42b5153b5c60edf3638e1592f72f743.zip
Add some more tests for Base32 encoder and decoder
-rw-r--r--src/base32.zig20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/base32.zig b/src/base32.zig
index c92545b..d8adfd5 100644
--- a/src/base32.zig
+++ b/src/base32.zig
@@ -248,17 +248,27 @@ test {
248 const decoded = "this is a test"; 248 const decoded = "this is a test";
249 249
250 var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined; 250 var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined;
251 _ = try Decoder.decode(&decode_buf, encoded); 251 var decode_res = try Decoder.decode(&decode_buf, encoded);
252 252
253 try testing.expectEqualStrings(decoded, &decode_buf); 253 try testing.expectEqualStrings(decoded, decode_res);
254
255 var encode_buf: [Encoder.calcSize(decoded.len)]u8 = undefined;
256 var encode_res = Encoder.encode(&encode_buf, decoded);
257
258 try testing.expectEqualStrings(encoded, encode_res);
254} 259}
255 260
256test { 261test {
257 const encoded = "SNAH7EH5X4P5R2M2RGF3LVAL6NRFIXLN2E67O6FNRUQ4JCQBPL64GEBPLY"; 262 const encoded = "SNAH7EH5X4P5R2M2RGF3LVAL6NRFIXLN2E67O6FNRUQ4JCQBPL64GEBPLY";
258 const decoded = [_]u8{ 0x93, 0x40, 0x7f, 0x90, 0xfd, 0xbf, 0x1f, 0xd8, 0xe9, 0x9a, 0x89, 0x8b, 0xb5, 0xd4, 0x0b, 0xf3, 0x62, 0x54, 0x5d, 0x6d, 0xd1, 0x3d, 0xf7, 0x78, 0xad, 0x8d, 0x21, 0xc4, 0x8a, 0x01, 0x7a, 0xfd, 0xc3, 0x10, 0x2f, 0x5e }; 263 const decoded = &[_]u8{ 0x93, 0x40, 0x7f, 0x90, 0xfd, 0xbf, 0x1f, 0xd8, 0xe9, 0x9a, 0x89, 0x8b, 0xb5, 0xd4, 0x0b, 0xf3, 0x62, 0x54, 0x5d, 0x6d, 0xd1, 0x3d, 0xf7, 0x78, 0xad, 0x8d, 0x21, 0xc4, 0x8a, 0x01, 0x7a, 0xfd, 0xc3, 0x10, 0x2f, 0x5e };
259 264
260 var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined; 265 var decode_buf: [Decoder.calcSize(encoded.len)]u8 = undefined;
261 _ = try Decoder.decode(&decode_buf, encoded); 266 var decode_res = try Decoder.decode(&decode_buf, encoded);
267
268 try testing.expectEqualSlices(u8, decoded, decode_res);
269
270 var encode_buf: [Encoder.calcSize(decoded.len)]u8 = undefined;
271 var encode_res = Encoder.encode(&encode_buf, decoded);
262 272
263 try testing.expectEqualSlices(u8, &decoded, &decode_buf); 273 try testing.expectEqualSlices(u8, encoded, encode_res);
264} 274}