Merge pull request #54 from Browsercore/text

text: properties and methods
This commit is contained in:
Francis Bouvier
2023-10-10 07:55:10 +02:00
committed by GitHub
3 changed files with 63 additions and 0 deletions

View File

@@ -1,3 +1,9 @@
const std = @import("std");
const jsruntime = @import("jsruntime");
const Case = jsruntime.test_utils.Case;
const checkCases = jsruntime.test_utils.checkCases;
const parser = @import("../netsurf.zig");
const CharacterData = @import("character_data.zig").CharacterData;
@@ -6,4 +12,43 @@ pub const Text = struct {
pub const Self = parser.Text;
pub const prototype = *CharacterData;
pub const mem_guarantied = true;
// JS funcs
// --------
// Read attributes
pub fn get_wholeText(self: *parser.Text) []const u8 {
return parser.textWholdeText(self);
}
// JS methods
// ----------
pub fn _splitText(self: *parser.Text, offset: u32) *parser.Text {
return parser.textSplitText(self, offset);
}
};
// Tests
// -----
pub fn testExecFn(
_: std.mem.Allocator,
js_env: *jsruntime.Env,
comptime _: []jsruntime.API,
) !void {
var get_whole_text = [_]Case{
.{ .src = "let text = document.getElementById('link').firstChild", .ex = "undefined" },
.{ .src = "text.wholeText === 'OK'", .ex = "true" },
};
try checkCases(js_env, &get_whole_text);
var split_text = [_]Case{
.{ .src = "text.data = 'OK modified'", .ex = "OK modified" },
.{ .src = "let split = text.splitText('OK'.length)", .ex = "undefined" },
.{ .src = "split.data === ' modified'", .ex = "true" },
.{ .src = "text.data === 'OK'", .ex = "true" },
};
try checkCases(js_env, &split_text);
}