-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expanding default arguments support (#84)
* Expand default arguments with references to other arguments Test's courtesy of @theseanl
- Loading branch information
Showing
9 changed files
with
585 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
packages/unified-latex-util-arguments/tests/attach-arguments-defaults.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import util from "util"; | ||
import type * as Ast from "@unified-latex/unified-latex-types"; | ||
import { attachMacroArgs } from "../libs/attach-arguments"; | ||
import { strToNodes } from "../../test-common"; | ||
import { arg, s, SP } from "@unified-latex/unified-latex-builder"; | ||
|
||
/* eslint-env jest */ | ||
|
||
// Make console.log pretty-print by default | ||
const origLog = console.log; | ||
console.log = (...args) => { | ||
origLog(...args.map((x) => util.inspect(x, false, 10, true))); | ||
}; | ||
|
||
describe("unified-latex-util-arguments", () => { | ||
it("Default arguments are stored if provided and no argument given", () => { | ||
let nodes = strToNodes(`\\xxx`); | ||
attachMacroArgs(nodes, { | ||
xxx: { | ||
signature: "O{x}", | ||
}, | ||
}); | ||
expect(nodes).toEqual([ | ||
{ | ||
type: "macro", | ||
content: "xxx", | ||
args: [ | ||
{ | ||
type: "argument", | ||
content: [], | ||
openMark: "", | ||
closeMark: "", | ||
_renderInfo: { defaultArg: "x" }, | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
nodes = strToNodes(`\\xxx`); | ||
attachMacroArgs(nodes, { | ||
xxx: { | ||
signature: "D(){x}", | ||
}, | ||
}); | ||
expect(nodes).toEqual([ | ||
{ | ||
type: "macro", | ||
content: "xxx", | ||
args: [ | ||
{ | ||
type: "argument", | ||
content: [], | ||
openMark: "", | ||
closeMark: "", | ||
_renderInfo: { defaultArg: "x" }, | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
nodes = strToNodes(`\\xxx`); | ||
attachMacroArgs(nodes, { | ||
xxx: { | ||
signature: "E{_}{x}", | ||
}, | ||
}); | ||
expect(nodes).toEqual([ | ||
{ | ||
type: "macro", | ||
content: "xxx", | ||
args: [ | ||
{ | ||
type: "argument", | ||
content: [], | ||
openMark: "", | ||
closeMark: "", | ||
_renderInfo: { defaultArg: "x" }, | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
it("Embellishment arguments keep track of their defaults", () => { | ||
let nodes = strToNodes(`\\xxx_{a}`); | ||
attachMacroArgs(nodes, { | ||
xxx: { | ||
signature: "E{_^}{xy}", | ||
}, | ||
}); | ||
expect(nodes).toEqual([ | ||
{ | ||
args: [ | ||
{ | ||
closeMark: "", | ||
content: [ | ||
{ | ||
content: "a", | ||
type: "string", | ||
}, | ||
], | ||
openMark: "_", | ||
type: "argument", | ||
}, | ||
{ | ||
_renderInfo: { | ||
defaultArg: "y", | ||
}, | ||
closeMark: "", | ||
content: [], | ||
openMark: "", | ||
type: "argument", | ||
}, | ||
], | ||
content: "xxx", | ||
type: "macro", | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.