Turn math component into array

This commit is contained in:
Dolan Miu
2020-10-13 02:06:27 +01:00
parent e36e9e1cf4
commit 5be195fd91
39 changed files with 208 additions and 157 deletions

View File

@ -8,7 +8,7 @@ import { MathBase } from "./math-base";
describe("MathBase", () => {
describe("#constructor()", () => {
it("should create a MathBase with correct root key", () => {
const mathBase = new MathBase(new MathRun("2+2"));
const mathBase = new MathBase([new MathRun("2+2")]);
const tree = new Formatter().format(mathBase);
expect(tree).to.deep.equal({

View File

@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathBase extends XmlComponent {
constructor(run: MathComponent) {
constructor(children: MathComponent[]) {
super("m:e");
this.root.push(run);
for (const child of children) {
this.root.push(child);
}
}
}

View File

@ -8,7 +8,7 @@ import { MathSubScriptElement } from "./math-sub-script";
describe("MathSubScriptElement", () => {
describe("#constructor()", () => {
it("should create a MathSubScriptElement with correct root key", () => {
const mathSubScriptElement = new MathSubScriptElement(new MathRun("2+2"));
const mathSubScriptElement = new MathSubScriptElement([new MathRun("2+2")]);
const tree = new Formatter().format(mathSubScriptElement);
expect(tree).to.deep.equal({

View File

@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathSubScriptElement extends XmlComponent {
constructor(child: MathComponent) {
constructor(children: MathComponent[]) {
super("m:sub");
this.root.push(child);
for (const child of children) {
this.root.push(child);
}
}
}

View File

@ -9,9 +9,9 @@ describe("MathSum", () => {
describe("#constructor()", () => {
it("should create a MathSum with correct root key", () => {
const mathSum = new MathSum({
child: new MathRun("1"),
subScript: new MathRun("2"),
superScript: new MathRun("3"),
children: [new MathRun("1")],
subScript: [new MathRun("2")],
superScript: [new MathRun("3")],
});
const tree = new Formatter().format(mathSum);

View File

@ -8,9 +8,9 @@ import { MathSubScriptElement } from "./math-sub-script";
import { MathSuperScriptElement } from "./math-super-script";
export interface IMathSumOptions {
readonly child: MathComponent;
readonly subScript?: MathComponent;
readonly superScript?: MathComponent;
readonly children: MathComponent[];
readonly subScript?: MathComponent[];
readonly superScript?: MathComponent[];
}
export class MathSum extends XmlComponent {
@ -27,6 +27,6 @@ export class MathSum extends XmlComponent {
this.root.push(new MathSuperScriptElement(options.superScript));
}
this.root.push(new MathBase(options.child));
this.root.push(new MathBase(options.children));
}
}

View File

@ -8,7 +8,7 @@ import { MathSuperScriptElement } from "./math-super-script";
describe("MathSuperScriptElement", () => {
describe("#constructor()", () => {
it("should create a MathSuperScriptElement with correct root key", () => {
const mathSuperScriptElement = new MathSuperScriptElement(new MathRun("2+2"));
const mathSuperScriptElement = new MathSuperScriptElement([new MathRun("2+2")]);
const tree = new Formatter().format(mathSuperScriptElement);
expect(tree).to.deep.equal({

View File

@ -4,9 +4,11 @@ import { XmlComponent } from "file/xml-components";
import { MathComponent } from "../math-component";
export class MathSuperScriptElement extends XmlComponent {
constructor(child: MathComponent) {
constructor(children: MathComponent[]) {
super("m:sup");
this.root.push(child);
for (const child of children) {
this.root.push(child);
}
}
}