authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-01 00:07:21 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-01 00:07:33 -08:00
logb4d8be82ef92e32b38e2faee3c9de625d61a31b3
tree1adec1b3988db6ebe863fab228728dc71ad9eccb
parent5fe7ba43c95f32d9ea7035b4f3e6f1e03506ae60

add dynamic test


2 files changed, 90 insertions(+), 0 deletions(-)

qrcode.zig+8
......@@ -1066,6 +1066,14 @@ fn versionBits(version: u16) u18 {
10661066 })[version];
10671067}
10681068
1069pub fn getMinVersion(comptime level: Level, comptime mode: Mode, length: usize) ?u16 {
1070 const max_lengths = maxLenPerModeLevelVersion(mode, level);
1071 for (max_lengths, 0..) |l, i| {
1072 if (l > length) return @intCast(i);
1073 }
1074 return null;
1075}
1076
10691077//
10701078//
10711079//
test.zig+82
......@@ -988,3 +988,85 @@ test {
988988 \\
989989 );
990990}
991
992test {
993 const allocator = std.testing.allocator;
994 const input = "https://en.wikipedia.org/wiki/Main_Page";
995 const version = qrcode.getMinVersion(.L, .latin1, input.len).?;
996 switch (version) {
997 inline 1...40 => |v| {
998 const grid = qrcode.encode(.latin1, .L, v, input);
999 const blocks = try grid.asBlockString2(allocator);
1000 defer allocator.free(blocks);
1001 try expect(blocks).toEqualString(
1002 \\█▀▀▀▀▀█ ▄▄█ ▀█▄ ▀▄ █▀▀▀▀▀█|
1003 \\█ ███ █ ▀▄ ▄ █▄█▀█▀▀ █ ███ █|
1004 \\█ ▀▀▀ █ █▀█ █▀▀▄█▄█▄▄ █ ▀▀▀ █|
1005 \\▀▀▀▀▀▀▀ █ █▄▀ █ ▀▄█▄█ ▀▀▀▀▀▀▀|
1006 \\▀█ █▄ ▀▀▄▄ ███▀█▄ ▀▀ ▄█▀▀▄▀▀▄|
1007 \\▄ ▀▀▀ ▀▀▀▄▄███ ▄▀▄█▄ ▀█ ▀██ |
1008 \\▀█▄▄██▀▀▄ ▀█ ▄▀▀▀█▄▄██▀▀ ▀ ▀▀|
1009 \\ ▄ █▀█▀ ▄▀█ ▀▀▄ ▄▄▄▀ ▄▀▄█▀█▀|
1010 \\ █▀▄▀▀ ▄█▄ ██▄▀▄█ ▀█▄ ▄ ▀▄|
1011 \\▀ ▀█▀▀ █▀█ █▄▄▄█ █ ▄ ▄ ██|
1012 \\▀ ▀▀ ▀ █▄ ▄ ▄ █ ▄█▀▀▀█ █▄▄|
1013 \\█▀▀▀▀▀█ ▀▄▀ ▄▄█▀█ █ ▀ █▄▄▀▄|
1014 \\█ ███ █ ▄▀▀▄█ █▀▀ ▄▀▀███▄▄█▀|
1015 \\█ ▀▀▀ █ ▄█▀ █▄▄ ▄███▄█ ▀▀▀▄▀|
1016 \\▀▀▀▀▀▀▀ ▀ ▀ ▀▀▀ ▀▀ ▀ ▀▀▀ ▀ |
1017 \\
1018 );
1019 const braille = try grid.asBrailleString(allocator);
1020 defer allocator.free(braille);
1021 try expect(braille).toEqualString(
1022 \\⡏⣭⡍⡇⢖⠃⡀⣝⡦⡬⠆⡏⣭⡍⡇|
1023 \\⠧⠭⠥⠇⡏⣇⠏⡕⢗⣗⡆⠧⠭⠥⠇|
1024 \\⡙⠼⠆⠭⢖⣸⣿⠙⡢⣩⡐⢯⠱⣭⠂|
1025 \\⢙⢲⢿⠍⢂⢽⠰⢍⢙⣒⠟⡩⣨⢬⠅|
1026 \\⠄⠋⢮⠥⠚⡦⡟⣎⣚⡄⡝⡂⡐⢨⡆|
1027 \\⡥⠭⠤⡅⢗⠔⠀⣂⡧⡔⡏⠍⣇⡳⡂|
1028 \\⡇⠿⠇⡇⣪⠕⣇⡘⣩⣴⣩⠛⠷⢞⠅|
1029 \\⠉⠉⠉⠁⠁⠈⠈⠉⠈⠁⠁⠈⠉⠈⠀|
1030 \\
1031 );
1032 const svg = try grid.asSvg(allocator);
1033 defer allocator.free(svg);
1034 try expect(svg).toEqualString(
1035 \\<svg xmlns="http://www.w3.org/2000/svg" width="310" height="300" viewBox="-1 -1 31 30" shape-rendering="crispEdges" stroke="#000">
1036 \\<rect x="-1" y="-1" width="31" height="30" fill="#fff" stroke="none" />
1037 \\<path d="M0,0 h7 M10,0 h1 M14,0 h2 M19,0 h1 M22,0 h7" />
1038 \\<path d="M0,1 h1 M6,1 h1 M8,1 h3 M15,1 h2 M20,1 h1 M22,1 h1 M28,1 h1" />
1039 \\<path d="M0,2 h1 M2,2 h3 M6,2 h1 M8,2 h1 M14,2 h1 M16,2 h5 M22,2 h1 M24,2 h3 M28,2 h1" />
1040 \\<path d="M0,3 h1 M2,3 h3 M6,3 h1 M9,3 h1 M12,3 h1 M14,3 h3 M18,3 h1 M22,3 h1 M24,3 h3 M28,3 h1" />
1041 \\<path d="M0,4 h1 M2,4 h3 M6,4 h1 M8,4 h3 M12,4 h3 M16,4 h1 M18,4 h1 M22,4 h1 M24,4 h3 M28,4 h1" />
1042 \\<path d="M0,5 h1 M6,5 h1 M8,5 h1 M10,5 h1 M12,5 h1 M15,5 h6 M22,5 h1 M28,5 h1" />
1043 \\<path d="M0,6 h7 M8,6 h1 M10,6 h1 M12,6 h1 M14,6 h1 M16,6 h1 M18,6 h1 M20,6 h1 M22,6 h7" />
1044 \\<path d="M8,7 h1 M10,7 h2 M14,7 h1 M17,7 h4 " />
1045 \\<path d="M0,8 h2 M3,8 h1 M6,8 h2 M11,8 h5 M18,8 h2 M22,8 h3 M26,8 h2 " />
1046 \\<path d="M1,9 h1 M3,9 h2 M8,9 h2 M11,9 h3 M15,9 h2 M21,9 h2 M25,9 h1 M28,9 h1" />
1047 \\<path d="M2,10 h3 M6,10 h3 M11,10 h3 M17,10 h1 M19,10 h1 M22,10 h2 M25,10 h3 " />
1048 \\<path d="M0,11 h1 M9,11 h5 M16,11 h1 M18,11 h3 M23,11 h1 M26,11 h2 " />
1049 \\<path d="M0,12 h2 M4,12 h4 M10,12 h2 M14,12 h4 M20,12 h4 M25,12 h1 M27,12 h2" />
1050 \\<path d="M1,13 h5 M8,13 h1 M11,13 h1 M13,13 h1 M17,13 h5 " />
1051 \\<path d="M3,14 h4 M10,14 h2 M13,14 h2 M20,14 h1 M23,14 h1 M25,14 h4" />
1052 \\<path d="M1,15 h1 M3,15 h1 M5,15 h1 M9,15 h1 M11,15 h1 M15,15 h1 M17,15 h3 M22,15 h1 M24,15 h2 M27,15 h1 " />
1053 \\<path d="M2,16 h2 M5,16 h2 M9,16 h1 M12,16 h2 M15,16 h1 M17,16 h1 M20,16 h2 M27,16 h1 " />
1054 \\<path d="M2,17 h1 M4,17 h1 M8,17 h3 M12,17 h3 M16,17 h2 M21,17 h2 M25,17 h1 M28,17 h1" />
1055 \\<path d="M0,18 h1 M4,18 h4 M10,18 h3 M14,18 h1 M18,18 h1 M20,18 h1 M27,18 h2" />
1056 \\<path d="M5,19 h1 M10,19 h1 M12,19 h1 M14,19 h5 M20,19 h1 M22,19 h1 M24,19 h1 M27,19 h2" />
1057 \\<path d="M0,20 h1 M2,20 h2 M6,20 h1 M8,20 h1 M16,20 h1 M20,20 h5 M26,20 h1 " />
1058 \\<path d="M8,21 h2 M11,21 h1 M14,21 h1 M16,21 h1 M19,21 h2 M24,21 h1 M26,21 h3" />
1059 \\<path d="M0,22 h7 M8,22 h1 M10,22 h1 M16,22 h3 M20,22 h1 M22,22 h1 M24,22 h1 M27,22 h1 " />
1060 \\<path d="M0,23 h1 M6,23 h1 M9,23 h1 M14,23 h3 M18,23 h1 M20,23 h1 M24,23 h3 M28,23 h1" />
1061 \\<path d="M0,24 h1 M2,24 h3 M6,24 h1 M9,24 h2 M12,24 h1 M15,24 h3 M20,24 h5 M27,24 h2" />
1062 \\<path d="M0,25 h1 M2,25 h3 M6,25 h1 M8,25 h1 M11,25 h2 M15,25 h1 M19,25 h1 M22,25 h6 " />
1063 \\<path d="M0,26 h1 M2,26 h3 M6,26 h1 M9,26 h2 M12,26 h1 M17,26 h3 M21,26 h1 M24,26 h3 M28,26 h1" />
1064 \\<path d="M0,27 h1 M6,27 h1 M8,27 h2 M12,27 h3 M16,27 h6 M27,27 h1 " />
1065 \\<path d="M0,28 h7 M8,28 h1 M11,28 h1 M13,28 h3 M17,28 h2 M20,28 h1 M23,28 h3 M27,28 h1 " />
1066 \\</svg>
1067 \\
1068 );
1069 },
1070 else => unreachable,
1071 }
1072}