aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-29 21:54:57 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-29 21:54:57 +0200
commit77ccdd8559383c25fc59fbcba38117102e5657b5 (patch)
treeaf089391472afe3207572f16ed0940aa0b8fc37d /src
parentce40702a501c3159db89693bd7da713ae1b4c011 (diff)
fix(test): checking diff for random values in svg
Diffstat (limited to 'src')
-rw-r--r--src/data/test_content_1.typ4
-rw-r--r--src/data/test_content_2.typ4
-rw-r--r--src/eval/template_math_block.typ8
-rw-r--r--src/eval/template_math_content.typ3
-rw-r--r--src/paragraph.zig29
-rw-r--r--src/testing.zig2
6 files changed, 36 insertions, 14 deletions
diff --git a/src/data/test_content_1.typ b/src/data/test_content_1.typ
index e2f21a5..171e00b 100644
--- a/src/data/test_content_1.typ
+++ b/src/data/test_content_1.typ
@@ -1,5 +1,3 @@
#import "_base.typ": *
-#show: display.with()
-
-$text("Adwaita Mono") x$
+#display[$x$]
diff --git a/src/data/test_content_2.typ b/src/data/test_content_2.typ
index 47666a8..a126a0c 100644
--- a/src/data/test_content_2.typ
+++ b/src/data/test_content_2.typ
@@ -1,5 +1,3 @@
#import "_base.typ": *
-#show: display.with()
-
-$x^2$
+#display[$x^2$]
diff --git a/src/eval/template_math_block.typ b/src/eval/template_math_block.typ
index ecadae1..b36f063 100644
--- a/src/eval/template_math_block.typ
+++ b/src/eval/template_math_block.typ
@@ -1,8 +1,8 @@
-#show math.equation: set text(font: "New Computer Modern Math")
-#show math.text: set text(font: "New Computer Modern")
-
#let display(body) = context {
- let margin = 2pt
+ show math.equation: set text(font: "New Computer Modern Math")
+ show math.text: set text(font: "New Computer Modern")
+
+ let margin = 4pt
let m = measure(body)
set page(
fill: none,
diff --git a/src/eval/template_math_content.typ b/src/eval/template_math_content.typ
index cd31ef6..b4faf43 100644
--- a/src/eval/template_math_content.typ
+++ b/src/eval/template_math_content.typ
@@ -1,7 +1,8 @@
#let display(body) = context {
show math.equation: set text(font: "New Computer Modern Math")
+ show math.text: set text(font: "New Computer Modern")
- let margin = 2pt
+ let margin = 4pt
let m = measure(body)
set page(
fill: none,
diff --git a/src/paragraph.zig b/src/paragraph.zig
index 45af712..ce2d123 100644
--- a/src/paragraph.zig
+++ b/src/paragraph.zig
@@ -40,6 +40,31 @@ pub fn parseLine(alloc: Allocator, l: *Lexer) Error!Element {
return line.element();
}
+fn doTestMath(parent: Allocator, t: []const u8, v: []const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(parent);
+ defer arena.deinit();
+ var alloc = arena.allocator();
+
+ var l = try Lexer.init(t);
+ var p = try parse(alloc, &l);
+ const g = try p.renderHTML(alloc);
+ defer alloc.free(g);
+ try std.testing.expect(brk: {
+ var g_iter = std.mem.splitSequence(u8, g, " ");
+ var v_iter = std.mem.splitSequence(u8, v, " ");
+ while (g_iter.next()) |g_it| {
+ const v_it = v_iter.next() orelse break :brk false;
+ if ((std.mem.startsWith(u8, g_it, "xlink:href=") and std.mem.startsWith(u8, g_it, "xlink:href")) or
+ (std.mem.startsWith(u8, g_it, "id=") and std.mem.startsWith(u8, v_it, "id="))) continue;
+ if (!std.mem.eql(u8, g_it, v_it)) {
+ std.debug.print("not the same: {s} vs {s}", .{g_it, v_it});
+ break :brk false;
+ }
+ }
+ break :brk v_iter.next() == null;
+ });
+}
+
test "parse paragraphs" {
const alloc = std.testing.allocator;
@@ -50,8 +75,8 @@ test "parse paragraphs" {
try doTest(parse, alloc, "[](bar)", "<p><a href=\"bar\">bar</a></p>");
try doTest(parse, alloc, "[foo](bar)", "<p><a href=\"bar\">foo</a></p>");
try doTest(parse, alloc, "hello [foo](bar) world", "<p>hello <a href=\"bar\">foo</a> world</p>");
- try doTest(parse, alloc, "$x$", "<p>" ++ @embedFile("data/test_content_1.svg") ++ "</p>");
- try doTest(parse, alloc, "$x^2$", "<p>" ++ @embedFile("data/test_content_2.svg") ++ "</p>");
+ try doTestMath(alloc, "$x$", "<p>" ++ @embedFile("data/test_content_1.svg") ++ "</p>");
+ try doTestMath(alloc, "$x^2$", "<p>" ++ @embedFile("data/test_content_2.svg") ++ "</p>");
try doTestError(parse, alloc, "hello *world", Error.ModifierNotClosed);
try doTestError(parse, alloc, "hello *wo_rld*", Error.ModifierNotClosed);
diff --git a/src/testing.zig b/src/testing.zig
index cfc3505..4ed071f 100644
--- a/src/testing.zig
+++ b/src/testing.zig
@@ -14,7 +14,7 @@ pub fn do(comptime parse: fn (Allocator, *Lexer) parser.Error!Element, parent: A
const g = try p.renderHTML(alloc);
defer alloc.free(g);
std.testing.expect(std.mem.eql(u8, g, v)) catch |err| {
- std.debug.print("{s}\n", .{g});
+ std.debug.print("got: {s}\nwanted: {s}\n", .{g, v});
return err;
};
}