Commit 253334c0 authored by Mark Stenglein's avatar Mark Stenglein

ContentLine: Generate: Refactor

Eliminates a huge amount of code in favor of one template string. Should
work much better.

Additionally, there was a mistake in the test cases where the CRLF was
omitted from the test. This commit fixes that by simply adding it.
Signed-off-by: Mark Stenglein's avatarMark Stenglein <mark@stengle.in>
parent dfd82c8d
Pipeline #1175 passed with stages
in 51 seconds
......@@ -95,15 +95,6 @@ export default class ContentLine implements ICalElement {
* @author Mark Stenglein <mark@stengle.in>
*/
public generate(): string {
let outputLine = this.name;
this.params.forEach((param) => {
outputLine += ";";
outputLine += param.generate();
});
outputLine += ":" + this.value + CRLF;
return ContentLine.fold(outputLine);
return `${this.name};${this.params.map(param => param.generate()).join(";")}:${this.value}${CRLF}`;
}
}
......@@ -170,7 +170,7 @@ describe("ContentLine", () => {
const param2: Parameter = new Parameter("PARAM-TWO", ["value1"]);
const params: Parameter[] = [param1, param2];
const test: ContentLine = new ContentLine("NAME", params, "value");
const expected = "NAME;PARAM-ONE=value1,value2;PARAM-TWO=value1:value";
const expected = "NAME;PARAM-ONE=value1,value2;PARAM-TWO=value1:value\r\n";
const result = test.generate();
expect(result).to.be.equal(expected);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment