Skip to content

Commit

Permalink
fix: optional argument without default value
Browse files Browse the repository at this point in the history
The code path for optional argument without a default value wasn't being
tested. Added a test and fixed it so that it properly expands to
-NoValue-.
  • Loading branch information
theseanl committed Jan 29, 2024
1 parent 38a18e2 commit 6b9e249
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/unified-latex-util-macros/libs/newcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function createMacroExpander(
// Check if there exists a default argument for this hash number
const defaultArg = defaultArgs[hashNum - 1];
if (!defaultArg) {
return s(`#${hashNum}`);
return emptyArg(); // Return -NoValue-
}

// Detect self-references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ describe("unified-latex-utils-macros", () => {
expect(printRaw(expander(macro))).toEqual("a $x^{A}_{B}$");
});

it("Can substitute optional arguments", () => {
let substitutionBody = latexParser.parse("a b #1 c #2").content;
// This macro defines the args that will be substituted
let macro = parseXxxMacro("\\xxx{B}", "o m");

const expander = createMacroExpander(substitutionBody);
expect(printRaw(expander(macro))).toEqual("a b c B");
})

it("Can substitute default arguments", () => {
let substitutionBody = latexParser.parse("a b #1 c #2").content;
// This macro defines the args that will be substituted
Expand Down

0 comments on commit 6b9e249

Please sign in to comment.