mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
text: add wholeText getter
Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
@@ -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 parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const CharacterData = @import("character_data.zig").CharacterData;
|
const CharacterData = @import("character_data.zig").CharacterData;
|
||||||
@@ -6,4 +12,28 @@ pub const Text = struct {
|
|||||||
pub const Self = parser.Text;
|
pub const Self = parser.Text;
|
||||||
pub const prototype = *CharacterData;
|
pub const prototype = *CharacterData;
|
||||||
pub const mem_guarantied = true;
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
|
// JS funcs
|
||||||
|
// --------
|
||||||
|
|
||||||
|
// Read attributes
|
||||||
|
|
||||||
|
pub fn get_wholeText(self: *parser.Text) []const u8 {
|
||||||
|
return parser.textWholdeText(self);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -503,6 +503,16 @@ pub fn characterDataSubstringData(cdata: *CharacterData, offset: u32, count: u32
|
|||||||
// Text
|
// Text
|
||||||
pub const Text = c.dom_text;
|
pub const Text = c.dom_text;
|
||||||
|
|
||||||
|
fn textVtable(text: *Text) c.dom_text_vtable {
|
||||||
|
return getVtable(c.dom_text_vtable, Text, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn textWholdeText(text: *Text) []const u8 {
|
||||||
|
var s: ?*String = undefined;
|
||||||
|
_ = textVtable(text).dom_text_get_whole_text.?(text, &s);
|
||||||
|
return stringToData(s.?);
|
||||||
|
}
|
||||||
|
|
||||||
// Comment
|
// Comment
|
||||||
pub const Comment = c.dom_comment;
|
pub const Comment = c.dom_comment;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const DOM = @import("dom.zig");
|
|||||||
const docTestExecFn = @import("html/document.zig").testExecFn;
|
const docTestExecFn = @import("html/document.zig").testExecFn;
|
||||||
const nodeTestExecFn = @import("dom/node.zig").testExecFn;
|
const nodeTestExecFn = @import("dom/node.zig").testExecFn;
|
||||||
const characterDataTestExecFn = @import("dom/character_data.zig").testExecFn;
|
const characterDataTestExecFn = @import("dom/character_data.zig").testExecFn;
|
||||||
|
const textTestExecFn = @import("dom/text.zig").testExecFn;
|
||||||
|
|
||||||
var doc: *parser.DocumentHTML = undefined;
|
var doc: *parser.DocumentHTML = undefined;
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ fn testsAllExecFn(
|
|||||||
docTestExecFn,
|
docTestExecFn,
|
||||||
nodeTestExecFn,
|
nodeTestExecFn,
|
||||||
characterDataTestExecFn,
|
characterDataTestExecFn,
|
||||||
|
textTestExecFn,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline for (testFns) |testFn| {
|
inline for (testFns) |testFn| {
|
||||||
|
|||||||
Reference in New Issue
Block a user