Skip to content
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
1 change: 1 addition & 0 deletions demo/test-cases.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ <h2>Operators</h2>
<test-case>ı.^\^</test-case>
<test-case>x.^ \(n)</test-case>
<test-case>&lt;&lt;&lt; [] &gt;&gt;&gt;</test-case>
<test-case>a o. b</test-case>

<test-case display="block">
\`lim sup`._(n -> oo)
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/tokenizer/scanners/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default function alphaScanner(char, input, { start, grouping }) {
[nextChar] = input.slice(i);
}

// alpha may contain a period, but not never end with one.
if (value.endsWith(".")) {
// alpha may contain a period, but only known ops can end with one.
if (value.endsWith(".") && !KNOWN_OPS.has(value)) {
value = value.slice(0, -1);
}

Expand Down
18 changes: 18 additions & 0 deletions src/compiler/tokenizer/scanners/alpha.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ test("can’t end with a period", (t) => {
t.is(token?.split, true);
});

test("unless it is a known operator", (t) => {
const token = alpha("o", "o.", { start: 0, grouping: false });

t.is(token?.type, "operator");
t.is(token?.value, "⊙");
t.is(token?.end, 2);
t.falsy(token?.split);
});

test("known operator ends in period cannot be followed by an alphanum", (t) => {
const token = alpha("o", "o.o", { start: 0, grouping: false });

t.is(token?.type, "ident");
t.is(token?.value, "o");
t.is(token?.end, 1);
t.is(token?.split, true);
});

test("known prefix", (t) => {
const token = alpha("h", "hat a", { start: 0, grouping: false });

Expand Down
8 changes: 8 additions & 0 deletions src/compiler/tokenizer/scanners/operator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ test("known operator", (t) => {
t.is(token?.end, 3);
});

test("known operator that ends with a period", (t) => {
const token = operator("o.", " o. b", { start: 1, grouping: false });

t.is(token?.type, "operator");
t.is(token?.value, "⊙");
t.is(token?.end, 3);
});

test("emits the longest possible known operator", (t) => {
const token = operator("^", "^^^ 1", { start: 0, grouping: false });

Expand Down
6 changes: 6 additions & 0 deletions test/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ test("i hat", (t) => {
t.snapshot(render("ı.^\\^"));
});

test("circumpunct", (t) => {
t.is(render("o."), "<math><mo>⊙</mo></math>");
t.snapshot(render("a o. b"));
t.snapshot(render("a o.b"));
});

test("Norm of two parallel lines", (t) => {
t.snapshot(render("||a || b||"));
});
Expand Down
10 changes: 10 additions & 0 deletions test/snapshots/operators.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ Generated by [AVA](https://avajs.dev).

'<math><mover><mi>ı</mi><mo>^</mo></mover></math>'

## circumpunct

> Snapshot 1

'<math><mi>a</mi><mo>⊙</mo><mi>b</mi></math>'

> Snapshot 2

'<math><mi>a</mi><mrow><mi>o</mi><mo>.</mo><mi>b</mi></mrow></math>'

## Norm of two parallel lines

> Snapshot 1
Expand Down
Binary file modified test/snapshots/operators.js.snap
Binary file not shown.