Add tests for ciutf8
This commit is contained in:
parent
d82d271a7f
commit
bca6a98889
1 changed files with 48 additions and 10 deletions
58
src/util.zig
58
src/util.zig
|
@ -183,14 +183,52 @@ pub const ciutf8 = struct {
|
||||||
|
|
||||||
return it_a == null and it_b == null;
|
return it_a == null and it_b == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lowerInPlace(str: []u8) void {
|
|
||||||
const view = View.init(str) catch return;
|
|
||||||
|
|
||||||
var iter = view.iterator();
|
|
||||||
var it = iter.nextCodepointSlice();
|
|
||||||
while (it != null) : (it = iter.nextCodepointSlice()) {
|
|
||||||
if (isAscii(it.?[0])) it.?[0] = toLower(it.?[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test "case insensitive eql with utf-8 chars" {
|
||||||
|
const t = std.testing;
|
||||||
|
try t.expectEqual(true, ciutf8.eql("abc 💯 def", "aBc 💯 DEF"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("xyz 💯 ijk", "aBc 💯 DEF"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("abc 💯 def", "aBc x DEF"));
|
||||||
|
try t.expectEqual(true, ciutf8.eql("💯", "💯"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("💯", "a"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("💯", "💯 continues"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("💯 fsdfs", "💯"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("💯", ""));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("", "💯"));
|
||||||
|
|
||||||
|
try t.expectEqual(true, ciutf8.eql("abc x def", "aBc x DEF"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("xyz x ijk", "aBc x DEF"));
|
||||||
|
try t.expectEqual(true, ciutf8.eql("x", "x"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("x", "a"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("x", "x continues"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("x fsdfs", "x"));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("x", ""));
|
||||||
|
try t.expectEqual(false, ciutf8.eql("", "x"));
|
||||||
|
|
||||||
|
try t.expectEqual(true, ciutf8.eql("", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
test "case insensitive hash with utf-8 chars" {
|
||||||
|
const t = std.testing;
|
||||||
|
try t.expect(ciutf8.hash("abc 💯 def") == ciutf8.hash("aBc 💯 DEF"));
|
||||||
|
try t.expect(ciutf8.hash("xyz 💯 ijk") != ciutf8.hash("aBc 💯 DEF"));
|
||||||
|
try t.expect(ciutf8.hash("abc 💯 def") != ciutf8.hash("aBc x DEF"));
|
||||||
|
try t.expect(ciutf8.hash("💯") == ciutf8.hash("💯"));
|
||||||
|
try t.expect(ciutf8.hash("💯") != ciutf8.hash("a"));
|
||||||
|
try t.expect(ciutf8.hash("💯") != ciutf8.hash("💯 continues"));
|
||||||
|
try t.expect(ciutf8.hash("💯 fsdfs") != ciutf8.hash("💯"));
|
||||||
|
try t.expect(ciutf8.hash("💯") != ciutf8.hash(""));
|
||||||
|
try t.expect(ciutf8.hash("") != ciutf8.hash("💯"));
|
||||||
|
|
||||||
|
try t.expect(ciutf8.hash("abc x def") == ciutf8.hash("aBc x DEF"));
|
||||||
|
try t.expect(ciutf8.hash("xyz x ijk") != ciutf8.hash("aBc x DEF"));
|
||||||
|
try t.expect(ciutf8.hash("x") == ciutf8.hash("x"));
|
||||||
|
try t.expect(ciutf8.hash("x") != ciutf8.hash("a"));
|
||||||
|
try t.expect(ciutf8.hash("x") != ciutf8.hash("x continues"));
|
||||||
|
try t.expect(ciutf8.hash("x fsdfs") != ciutf8.hash("x"));
|
||||||
|
try t.expect(ciutf8.hash("x") != ciutf8.hash(""));
|
||||||
|
try t.expect(ciutf8.hash("") != ciutf8.hash("x"));
|
||||||
|
|
||||||
|
try t.expect(ciutf8.hash("") == ciutf8.hash(""));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue