blob: eb4117a7067315137c1fd2e16ad8b53e1e1a0e36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
const std = @import("std");
const paste = @import("../../input/paste.zig");
pub fn is_safe(data: ?[*]const u8, len: usize) callconv(.c) bool {
const slice: []const u8 = if (data) |v| v[0..len] else &.{};
return paste.isSafe(slice);
}
test "is_safe with safe data" {
const testing = std.testing;
const safe = "hello world";
try testing.expect(is_safe(safe.ptr, safe.len));
}
test "is_safe with newline" {
const testing = std.testing;
const unsafe = "hello\nworld";
try testing.expect(!is_safe(unsafe.ptr, unsafe.len));
}
test "is_safe with bracketed paste end" {
const testing = std.testing;
const unsafe = "hello\x1b[201~world";
try testing.expect(!is_safe(unsafe.ptr, unsafe.len));
}
test "is_safe with empty data" {
const testing = std.testing;
const empty = "";
try testing.expect(is_safe(empty.ptr, 0));
}
test "is_safe with null empty data" {
const testing = std.testing;
try testing.expect(is_safe(null, 0));
}
|