tests: mocklib: forward compatibility change
authorJo-Philipp Wich <jo@mein.io>
Fri, 11 Feb 2022 16:41:00 +0000 (17:41 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 11 Feb 2022 16:41:00 +0000 (17:41 +0100)
Upstream ucode will change ord()'s return value type from array to integer,
add logic to handle both old and new cases.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
tests/lib/mocklib/uci.uc

index 69d25615faaaee94c23e8e06cb9ea1ebc0f18715..ed6b610229cc5f105310193b46cadb4a421e0a31 100644 (file)
@@ -1,11 +1,16 @@
 {%
        let mocklib = global.mocklib;
 
+       let byte = (str, off) => {
+               let v = ord(str, off);
+               return length(v) ? v[0] : v;
+       };
+
        let hash = (s) => {
                let h = 7;
 
                for (let i = 0; i < length(s); i++)
-                       h = h * 31 + ord(s, i)[0];
+                       h = h * 31 + byte(s, i);
 
                return h;
        };