test: prove canonical directory package identity
This commit is contained in:
@@ -217,6 +217,39 @@ export fn occurrences(haystack: str, needle: str) i32 = {
|
||||
return count;
|
||||
};
|
||||
|
||||
// Expected semantic identity for a canonical absolute directory that is not
|
||||
// representable below an active source root. Keep this independent observer
|
||||
// byte-for-byte aligned with the documented driver protocol.
|
||||
export fn localpackageidentity(dir: str, leaf: str) str = {
|
||||
let out: []u8 = alloc([], (dir.len * 4 + leaf.len + 16): u64)!;
|
||||
let prefix: str = "__wwlocal.p";
|
||||
let i: i32 = 0;
|
||||
for (i < prefix.len) { append(out, prefix[i]); i += 1; };
|
||||
let hex: str = "0123456789abcdef";
|
||||
i = 0;
|
||||
for (i < dir.len) {
|
||||
let c: u8 = dir[i];
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9')) {
|
||||
append(out, c);
|
||||
} else if (c == '_') {
|
||||
append(out, '_'); append(out, 'u');
|
||||
} else if (c == '/') {
|
||||
append(out, '_'); append(out, 's');
|
||||
} else {
|
||||
let high: i32 = (c / 16u8): i32;
|
||||
let low: i32 = (c % 16u8): i32;
|
||||
append(out, '_'); append(out, 'x');
|
||||
append(out, hex[high]); append(out, hex[low]);
|
||||
};
|
||||
i += 1;
|
||||
};
|
||||
append(out, '.');
|
||||
i = 0;
|
||||
for (i < leaf.len) { append(out, leaf[i]); i += 1; };
|
||||
return strings.frombytes(out);
|
||||
};
|
||||
|
||||
// Byte-lexicographic order, so directory listings sort identically on
|
||||
// every host regardless of locale.
|
||||
export fn lexless(a: str, b: str) bool = {
|
||||
|
||||
Reference in New Issue
Block a user