Commit 6b029687 authored by Mark Stenglein's avatar Mark Stenglein
Browse files

🎉 🎉 It works! 🎉 🎉

parent a7b64bc0
Pipeline #928 passed with stage
in 16 seconds
import { isAlpha } from "./util"; import { isAlpha } from "./util";
import { ICalElement } from "./ICalElement"; import { ICalElement } from "./ICalElement";
import Parameter from "./Parameter"; import Parameter from "./Parameter";
const CRLF: string = "/r/n"; const CRLF: string = "\r\n";
function isIamaToken(input: string): boolean {
return true;
}
/** /**
* Implementation of a Content Line from RFC 5545 * Implementation of a Content Line from RFC 5545
...@@ -47,7 +44,7 @@ export default class ContentLine implements ICalElement { ...@@ -47,7 +44,7 @@ export default class ContentLine implements ICalElement {
/* Setters */ /* Setters */
set name(newName: string) { set name(newName: string) {
if (isIamaToken(newName)) { if (Parameter.isIanaToken(newName)) {
this._name = newName; this._name = newName;
} }
else { else {
...@@ -59,6 +56,9 @@ export default class ContentLine implements ICalElement { ...@@ -59,6 +56,9 @@ export default class ContentLine implements ICalElement {
if (isAlpha(newValue)) { if (isAlpha(newValue)) {
this._value = newValue; this._value = newValue;
} }
else {
throw new TypeError("'value' must be alphabetic!");
}
} }
/** /**
...@@ -82,7 +82,7 @@ export default class ContentLine implements ICalElement { ...@@ -82,7 +82,7 @@ export default class ContentLine implements ICalElement {
this.params.forEach((param) => { this.params.forEach((param) => {
outputLine += ";"; outputLine += ";";
outputLine += param; outputLine += param.generate();
}); });
outputLine += ":" + this.value + CRLF; outputLine += ":" + this.value + CRLF;
......
...@@ -46,7 +46,7 @@ export default class Parameter implements ICalElement { ...@@ -46,7 +46,7 @@ export default class Parameter implements ICalElement {
get paramValues() { get paramValues() {
return this.paramValues; return this._paramValues;
} }
...@@ -73,7 +73,7 @@ export default class Parameter implements ICalElement { ...@@ -73,7 +73,7 @@ export default class Parameter implements ICalElement {
this._paramName = newName; this._paramName = newName;
} }
else { else {
throw new TypeError("Parameter must be valid iama-token or x-token"); throw new TypeError("Parameter must be valid iana-token or x-name");
} }
} }
...@@ -125,7 +125,7 @@ export default class Parameter implements ICalElement { ...@@ -125,7 +125,7 @@ export default class Parameter implements ICalElement {
* @returns string Representation of the Parameter as defined in RFC 5545 * @returns string Representation of the Parameter as defined in RFC 5545
*/ */
public generate(): string { public generate(): string {
let outputString = this.paramName; let outputString = this.paramName + "=";
/** /**
* Goes through each parameter value and adds it, being sure to place * Goes through each parameter value and adds it, being sure to place
* the comma for the 2nd parameter onwards. * the comma for the 2nd parameter onwards.
...@@ -177,7 +177,10 @@ export default class Parameter implements ICalElement { ...@@ -177,7 +177,10 @@ export default class Parameter implements ICalElement {
* TODO: Implement this! * TODO: Implement this!
*/ */
public static isXName(input: string): boolean { public static isXName(input: string): boolean {
return true; if (!(input.substring(0,2) === "X-")) {
return false;
}
return /^[a-zA-Z0-9-]+$/.test(input);
} }
/** /**
......
...@@ -65,13 +65,13 @@ describe("ContentLine", () => { ...@@ -65,13 +65,13 @@ describe("ContentLine", () => {
it("Should have the same value as given on input", () => { it("Should have the same value as given on input", () => {
const testValue: string = "testValue"; const testValue: string = "testValue";
const testParam: Parameter = new Parameter("name", [testValue]); const testParam: Parameter = new Parameter("NAME", ["TEST"]);
const testLine: ContentLine = new ContentLine("name", [testParam], testValue); const testLine: ContentLine = new ContentLine("name", [testParam], testValue);
const result: string = testLine.params[0].paramValues[0]; const result: string = testLine.value;
expect(result).to.be.equal(testValue); expect(result).to.be.equal(testValue);
}); });
}); /** describe("constructor") */ }); /* describe("constructor") */
/** /**
* Test `fold` static method * Test `fold` static method
......
...@@ -26,8 +26,11 @@ describe("Parameter", () => { ...@@ -26,8 +26,11 @@ describe("Parameter", () => {
const testName: string = "TEST-NAME"; const testName: string = "TEST-NAME";
const testParam: Parameter = new Parameter(testName, ["value1"]); const testParam: Parameter = new Parameter(testName, ["value1"]);
expect(testParam).to.have.property( expect(testParam).to.have.property("_paramName");
"paramName", "paramValues", "generate"); expect(testParam).to.have.property("_paramValues");
expect(testParam).to.have.property("paramName");
expect(testParam).to.have.property("paramValues");
expect(testParam).to.have.property("generate");
}); });
}); });
...@@ -99,12 +102,11 @@ describe("Parameter", () => { ...@@ -99,12 +102,11 @@ describe("Parameter", () => {
const name: string = "!NVALID-N@ME"; const name: string = "!NVALID-N@ME";
const values: string[] = ["value"]; const values: string[] = ["value"];
const testParam: Parameter = new Parameter(name, values); const testParam: Parameter = new Parameter(name, values);
}).to.throw("param-value must either be valid paramtext or" + }).to.throw("Parameter must be valid iana-token or x-name");
" quoted-string");
}); });
}); });
describe("paramValues", () => { describe("***paramValues", () => {
it("Correctly sets paramtext values", () => { it("Correctly sets paramtext values", () => {
}); });
...@@ -132,7 +134,7 @@ describe("Parameter", () => { ...@@ -132,7 +134,7 @@ describe("Parameter", () => {
* that the higher level classes can simply validate proper types and use * that the higher level classes can simply validate proper types and use
* the lower level generate method. * the lower level generate method.
*/ */
describe("generate()", () => { describe("***generate()", () => {
it("Correctly generates single-valued parameters", () => { it("Correctly generates single-valued parameters", () => {
}); });
...@@ -349,7 +351,6 @@ describe("Parameter", () => { ...@@ -349,7 +351,6 @@ describe("Parameter", () => {
it("returns true for valid quoted-string", () => { it("returns true for valid quoted-string", () => {
const test: string = "\"Test this valid quote-string!\""; const test: string = "\"Test this valid quote-string!\"";
console.log(test);
const result: boolean = Parameter.isQuotedString(test); const result: boolean = Parameter.isQuotedString(test);
expect(result).to.be.true; expect(result).to.be.true;
......
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