Skip to content

katex test [nfc]: Name the KaTeX tests without redundancy after split #1767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions test/model/katex_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class KatexExample extends ContentExample {
// The font sizes can be compared using the katex.css generated
// from katex.scss :
// https://unpkg.com/[email protected]/dist/katex.css
static final mathBlockKatexSizing = KatexExample.block(
'math block; KaTeX different sizing',
static final sizing = KatexExample.block(
'different font sizes',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2155476
'\\Huge 1\n\\huge 2\n\\LARGE 3\n\\Large 4\n\\large 5\n\\normalsize 6\n\\small 7\n\\footnotesize 8\n\\scriptsize 9\n\\tiny 0',
'<p>'
Expand Down Expand Up @@ -82,8 +82,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexNestedSizing = KatexExample.block(
'math block; KaTeX nested sizing',
static final nestedSizing = KatexExample.block(
'sizing spans nested',
r'\tiny {1 \Huge 2}',
'<p>'
'<span class="katex-display"><span class="katex">'
Expand All @@ -108,8 +108,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexDelimSizing = KatexExample.block(
'math block; KaTeX delimiter sizing',
static final delimsizing = KatexExample.block(
'delimsizing spans, big delimiters',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2147135
r'⟨ \big( \Big[ \bigg⌈ \Bigg⌊',
'<p>'
Expand Down Expand Up @@ -150,8 +150,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexSpace = KatexExample.block(
'math block; KaTeX space',
static final spacing = KatexExample.block(
'positive horizontal spacing with margin-right',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2214883
'1:2',
'<p>'
Expand Down Expand Up @@ -184,8 +184,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexSuperscript = KatexExample.block(
'math block, KaTeX superscript; single vlist-r, single vertical offset row',
static final vlistSuperscript = KatexExample.block(
'superscript: single vlist-r, single vertical offset row',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2176734
"a'",
'<p>'
Expand Down Expand Up @@ -234,8 +234,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexSubscript = KatexExample.block(
'math block, KaTeX subscript; two vlist-r, single vertical offset row',
static final vlistSubscript = KatexExample.block(
'subscript: two vlist-r, single vertical offset row',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2176735
'x_n',
'<p>'
Expand Down Expand Up @@ -288,8 +288,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexSubSuperScript = KatexExample.block(
'math block, KaTeX subsup script; two vlist-r, multiple vertical offset rows',
static final vlistSubAndSuperscript = KatexExample.block(
'subscript and superscript: two vlist-r, multiple vertical offset rows',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2176738
'_u^o',
'<p>'
Expand Down Expand Up @@ -356,8 +356,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexRaisebox = KatexExample.block(
'math block, KaTeX raisebox; single vlist-r, single vertical offset row',
static final vlistRaisebox = KatexExample.block(
r'\raisebox: single vlist-r, single vertical offset row',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2176739
r'a\raisebox{0.25em}{$b$}c',
'<p>'
Expand Down Expand Up @@ -398,8 +398,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexNegativeMargin = KatexExample.block(
'math block, KaTeX negative margin',
static final negativeMargin = KatexExample.block(
r'negative horizontal margin (\!)',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2223563
r'1 \! 2',
'<p>'
Expand All @@ -421,8 +421,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexLogo = KatexExample.block(
'math block, KaTeX logo',
static final katexLogo = KatexExample.block(
'KaTeX logo: vlists, negative margins',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2141902
r'\KaTeX',
'<p>'
Expand Down Expand Up @@ -509,8 +509,8 @@ class KatexExample extends ContentExample {
]),
]);

static final mathBlockKatexNegativeMarginsOnVlistRow = KatexExample.block(
'math block, KaTeX negative margins on a vlist row',
static final vlistNegativeMargin = KatexExample.block(
'vlist using negative margin (subscript X_n)',
// https://chat.zulip.org/#narrow/channel/7-test-here/topic/Rajesh/near/2224918
'X_n',
'<p>'
Expand Down Expand Up @@ -571,17 +571,17 @@ class KatexExample extends ContentExample {
void main() async {
TestZulipBinding.ensureInitialized();

testParseExample(KatexExample.mathBlockKatexSizing);
testParseExample(KatexExample.mathBlockKatexNestedSizing);
testParseExample(KatexExample.mathBlockKatexDelimSizing);
testParseExample(KatexExample.mathBlockKatexSpace);
testParseExample(KatexExample.mathBlockKatexSuperscript);
testParseExample(KatexExample.mathBlockKatexSubscript);
testParseExample(KatexExample.mathBlockKatexSubSuperScript);
testParseExample(KatexExample.mathBlockKatexRaisebox);
testParseExample(KatexExample.mathBlockKatexNegativeMargin);
testParseExample(KatexExample.mathBlockKatexLogo);
testParseExample(KatexExample.mathBlockKatexNegativeMarginsOnVlistRow);
testParseExample(KatexExample.sizing);
testParseExample(KatexExample.nestedSizing);
testParseExample(KatexExample.delimsizing);
testParseExample(KatexExample.spacing);
testParseExample(KatexExample.vlistSuperscript);
testParseExample(KatexExample.vlistSubscript);
testParseExample(KatexExample.vlistSubAndSuperscript);
testParseExample(KatexExample.vlistRaisebox);
testParseExample(KatexExample.negativeMargin);
testParseExample(KatexExample.katexLogo);
testParseExample(KatexExample.vlistNegativeMargin);

test('all KaTeX content examples are tested', () {
// Check that every KatexExample defined above has a corresponding
Expand Down
164 changes: 81 additions & 83 deletions test/widgets/katex_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,95 +11,93 @@ import 'content_test.dart';
void main() {
TestZulipBinding.ensureInitialized();

group('MathBlock', () {
group('characters render at specific offsets with specific size', () {
final testCases = <(KatexExample, List<(String, Offset, Size)>, {bool? skip})>[
(KatexExample.mathBlockKatexSizing, skip: false, [
('1', Offset(0.00, 2.24), Size(25.59, 61.00)),
('2', Offset(25.59, 10.04), Size(21.33, 51.00)),
('3', Offset(46.91, 16.55), Size(17.77, 43.00)),
('4', Offset(64.68, 21.98), Size(14.80, 36.00)),
('5', Offset(79.48, 26.50), Size(12.34, 30.00)),
('6', Offset(91.82, 30.26), Size(10.28, 25.00)),
('7', Offset(102.10, 32.15), Size(9.25, 22.00)),
('8', Offset(111.35, 34.03), Size(8.23, 20.00)),
('9', Offset(119.58, 35.91), Size(7.20, 17.00)),
('0', Offset(126.77, 39.68), Size(5.14, 12.00)),
]),
(KatexExample.mathBlockKatexNestedSizing, skip: false, [
('1', Offset(0.00, 40.24), Size(5.14, 12.00)),
('2', Offset(5.14, 2.80), Size(25.59, 61.00)),
]),
(KatexExample.mathBlockKatexDelimSizing, skip: false, [
('(', Offset(8.00, 20.14), Size(9.42, 25.00)),
('[', Offset(17.42, 20.14), Size(9.71, 25.00)),
('⌈', Offset(27.12, 20.14), Size(11.99, 25.00)),
('⌊', Offset(39.11, 20.14), Size(13.14, 25.00)),
]),
(KatexExample.mathBlockKatexSpace, skip: false, [
('1', Offset(0.00, 2.24), Size(10.28, 25.00)),
(':', Offset(16.00, 2.24), Size(5.72, 25.00)),
('2', Offset(27.43, 2.24), Size(10.28, 25.00)),
]),
(KatexExample.mathBlockKatexSuperscript, skip: false, [
('a', Offset(0.00, 5.28), Size(10.88, 25.00)),
('′', Offset(10.88, 1.13), Size(3.96, 17.00)),
]),
(KatexExample.mathBlockKatexSubscript, skip: false, [
('x', Offset(0.00, 5.28), Size(11.76, 25.00)),
('n', Offset(11.76, 13.65), Size(8.63, 17.00)),
]),
(KatexExample.mathBlockKatexSubSuperScript, skip: false, [
('u', Offset(0.00, 15.65), Size(8.23, 17.00)),
('o', Offset(0.00, 2.07), Size(6.98, 17.00)),
]),
(KatexExample.mathBlockKatexRaisebox, skip: false, [
('a', Offset(0.00, 4.16), Size(10.88, 25.00)),
('b', Offset(10.88, -0.66), Size(8.82, 25.00)),
('c', Offset(19.70, 4.16), Size(8.90, 25.00)),
]),
(KatexExample.mathBlockKatexNegativeMargin, skip: false, [
('1', Offset(0.00, 3.12), Size(10.28, 25.00)),
('2', Offset(6.85, 3.36), Size(10.28, 25.00)),
]),
(KatexExample.mathBlockKatexLogo, skip: false, [
('K', Offset(0.0, 8.64), Size(16.0, 25.0)),
('A', Offset(12.50, 10.85), Size(10.79, 17.0)),
('T', Offset(20.21, 9.36), Size(14.85, 25.0)),
('E', Offset(31.63, 14.52), Size(14.0, 25.0)),
('X', Offset(43.06, 9.85), Size(15.42, 25.0)),
]),
(KatexExample.mathBlockKatexNegativeMarginsOnVlistRow, skip: false, [
('X', Offset(0.00, 7.04), Size(17.03, 25.00)),
('n', Offset(17.03, 15.90), Size(8.63, 17.00)),
]),
];
group('snapshot per-character rects', () {
final testCases = <(KatexExample, List<(String, Offset, Size)>, {bool? skip})>[
(KatexExample.sizing, skip: false, [
('1', Offset(0.00, 2.24), Size(25.59, 61.00)),
('2', Offset(25.59, 10.04), Size(21.33, 51.00)),
('3', Offset(46.91, 16.55), Size(17.77, 43.00)),
('4', Offset(64.68, 21.98), Size(14.80, 36.00)),
('5', Offset(79.48, 26.50), Size(12.34, 30.00)),
('6', Offset(91.82, 30.26), Size(10.28, 25.00)),
('7', Offset(102.10, 32.15), Size(9.25, 22.00)),
('8', Offset(111.35, 34.03), Size(8.23, 20.00)),
('9', Offset(119.58, 35.91), Size(7.20, 17.00)),
('0', Offset(126.77, 39.68), Size(5.14, 12.00)),
]),
(KatexExample.nestedSizing, skip: false, [
('1', Offset(0.00, 40.24), Size(5.14, 12.00)),
('2', Offset(5.14, 2.80), Size(25.59, 61.00)),
]),
(KatexExample.delimsizing, skip: false, [
('(', Offset(8.00, 20.14), Size(9.42, 25.00)),
('[', Offset(17.42, 20.14), Size(9.71, 25.00)),
('⌈', Offset(27.12, 20.14), Size(11.99, 25.00)),
('⌊', Offset(39.11, 20.14), Size(13.14, 25.00)),
]),
(KatexExample.spacing, skip: false, [
('1', Offset(0.00, 2.24), Size(10.28, 25.00)),
(':', Offset(16.00, 2.24), Size(5.72, 25.00)),
('2', Offset(27.43, 2.24), Size(10.28, 25.00)),
]),
(KatexExample.vlistSuperscript, skip: false, [
('a', Offset(0.00, 5.28), Size(10.88, 25.00)),
('′', Offset(10.88, 1.13), Size(3.96, 17.00)),
]),
(KatexExample.vlistSubscript, skip: false, [
('x', Offset(0.00, 5.28), Size(11.76, 25.00)),
('n', Offset(11.76, 13.65), Size(8.63, 17.00)),
]),
(KatexExample.vlistSubAndSuperscript, skip: false, [
('u', Offset(0.00, 15.65), Size(8.23, 17.00)),
('o', Offset(0.00, 2.07), Size(6.98, 17.00)),
]),
(KatexExample.vlistRaisebox, skip: false, [
('a', Offset(0.00, 4.16), Size(10.88, 25.00)),
('b', Offset(10.88, -0.66), Size(8.82, 25.00)),
('c', Offset(19.70, 4.16), Size(8.90, 25.00)),
]),
(KatexExample.negativeMargin, skip: false, [
('1', Offset(0.00, 3.12), Size(10.28, 25.00)),
('2', Offset(6.85, 3.36), Size(10.28, 25.00)),
]),
(KatexExample.katexLogo, skip: false, [
('K', Offset(0.0, 8.64), Size(16.0, 25.0)),
('A', Offset(12.50, 10.85), Size(10.79, 17.0)),
('T', Offset(20.21, 9.36), Size(14.85, 25.0)),
('E', Offset(31.63, 14.52), Size(14.0, 25.0)),
('X', Offset(43.06, 9.85), Size(15.42, 25.0)),
]),
(KatexExample.vlistNegativeMargin, skip: false, [
('X', Offset(0.00, 7.04), Size(17.03, 25.00)),
('n', Offset(17.03, 15.90), Size(8.63, 17.00)),
]),
];

for (final testCase in testCases) {
testWidgets(testCase.$1.description, (tester) async {
await _loadKatexFonts();
for (final testCase in testCases) {
testWidgets(testCase.$1.description, (tester) async {
await _loadKatexFonts();

await prepareContent(tester, plainContent(testCase.$1.html));
await prepareContent(tester, plainContent(testCase.$1.html));

final baseRect = tester.getRect(find.byType(KatexWidget));
final baseRect = tester.getRect(find.byType(KatexWidget));

for (final characterData in testCase.$2) {
final character = characterData.$1;
final expectedTopLeftOffset = characterData.$2;
final expectedSize = characterData.$3;
for (final characterData in testCase.$2) {
final character = characterData.$1;
final expectedTopLeftOffset = characterData.$2;
final expectedSize = characterData.$3;

final rect = tester.getRect(find.text(character));
final topLeftOffset = rect.topLeft - baseRect.topLeft;
final size = rect.size;
final rect = tester.getRect(find.text(character));
final topLeftOffset = rect.topLeft - baseRect.topLeft;
final size = rect.size;

check(topLeftOffset)
.within(distance: 0.05, from: expectedTopLeftOffset);
check(size)
.within(distance: 0.05, from: expectedSize);
}
}, skip: testCase.skip);
}
});
check(topLeftOffset)
.within(distance: 0.05, from: expectedTopLeftOffset);
check(size)
.within(distance: 0.05, from: expectedSize);
}
}, skip: testCase.skip);
}
});
}

Expand Down