Commit 504e6f55 authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Added a bunch more tests.

- Committing to keep changes small and in case @yoda is also working
  on it right now.
parent 9844e819
Pipeline #924 failed with stage
in 13 seconds
......@@ -79,15 +79,28 @@ describe("Parameter", () => {
describe("SET Methods", () => {
describe("paramName", () => {
it("Correctly sets iana-token names", () => {
const name: string = "A0-TEST";
const values: string[] = ["value"];
const testParam: Parameter = new Parameter(name, values);
expect(testParam.paramName).to.be.equal(name);
});
it("Correctly sets x-name names", () => {
const name: string = "X-VENDOR-TEST";
const values: string[] = ["value"];
const testParam: Parameter = new Parameter(name, values);
expect(testParam.paramName).to.be.equal(name);
});
it("Throws an exception on incorrect name type", () => {
expect(() => {
const name: string = "!NVALID-N@ME";
const values: string[] = ["value"];
const testParam: Parameter = new Parameter(name, values);
}).to.throw("param-value must either be valid paramtext or" +
" quoted-string");
});
});
......@@ -152,23 +165,33 @@ describe("Parameter", () => {
});
it("returns true for valid iana-token", () => {
const test: string = "ICALENDAR";
const result: boolean = Parameter.isIanaToken(test);
expect(result).to.be.true;
});
it("returns false for empty string", () => {
const test: string = "";
const result: boolean = Parameter.isIanaToken(test);
expect(result).to.be.false;
});
it("returns true for string containing \"-\"", () => {
const test: string = "ICAL-TEST";
const result: boolean = Parameter.isIanaToken(test);
expect(result).to.be.true;
});
it("returns false for string containing special chars", () => {
const test: string = "!CAL-TEST";
const result: boolean = Parameter.isIanaToken(test);
expect(result).to.be.false;
});
it("returns false for string containing control chars", () => {
const test: string = "CAL-TEST\r\n";
const result: boolean = Parameter.isIanaToken(test);
expect(result).to.be.false;
});
});
......@@ -188,37 +211,47 @@ describe("Parameter", () => {
});
it("returns true for x-name value without vendorid", () => {
const test: string = "X-TESTING-TIME";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.true;
});
it("returns true for x-name value containing vendorid", () => {
});
it("returns false for x-name containing long vendorid", () => {
const test: string = "X-MIC-TESTING-TIME";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.true;
});
it("returns false for x-name containing special chars", () => {
const test: string = "X-TEST!NG-TIME";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.false;
});
it("returns false for x-name containing control chars", () => {
const test: string = "X-TESTNG-TIME/r/n";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.false;
});
it("returns false when missing \"X-\" from start" +
" of x-name", () => {
const test: string = "TESTNG-TIME";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.false;
});
it("returns false for empty string", () => {
const test: string = "";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.false;
});
it("returns false for vendorid containing special" +
" chars (even \"-\")", () => {
const test: string = "X-V#NDOR-TEST";
const result: boolean = Parameter.isXName(test);
expect(result).to.be.false;
});
});
......@@ -226,15 +259,18 @@ describe("Parameter", () => {
* param-text definition from RFC 5545 (pg. 10)
*
* paramtext = *SAFE-CHAR
*
* Because this only exists to check and make sure that it is safe text
* of any length, this really only needs to be checked to be sure it
* exists and somebody hasn't renamed/deleted it. It's essentially an
* alias.
*/
describe("isParamText()", () => {
it("exists", () => {
expect(Parameter).itself.respondsTo("isParamText");
});
it("returns true for valid param text", () => {
});
it("see isSafeChar() for other tests; this is an alias", () => {});
});
/**
......@@ -248,6 +284,57 @@ describe("Parameter", () => {
it("exists", () => {
expect(Parameter).itself.respondsTo("isSafeChar");
});
it("Returns true for any char except ctl,dquote,;,:,\",\"", () => {
const test: string = "abcdefghijklmnopqrstuvwxyz" +
" ABCDEFGHIJKLMNOPQRSTUVWXYZ 01234567890 !@#$%^&*()~`'.";
const result: boolean = Parameter.isSafeChar(test);
expect(result).to.be.true;
});
it("Returns false for \";\"", () => {
const test: string = "test this char ';'";
const result: boolean = Parameter.isSafeChar(test);
expect(result).to.be.false;
});
it("Returns false for \":\"", () => {
const test: string = "test this char ':'";
const result: boolean = Parameter.isSafeChar(test);
expect(result).to.be.false;
});
it("Returns false for \",\"", () => {
const test: string = "test this char ','";
const result: boolean = Parameter.isSafeChar(test);
expect(result).to.be.false;
});
it("Returns false for DQUOTE", () => {
const test: string = "test this char '\"'";
const result: boolean = Parameter.isSafeChar(test);
expect(result).to.be.false;
});
/**
* This test needs to be updated for the CONTROL char. I'm
* not really sure how to make a CONTROL char in js escape
* sequences though, so I'm skipping for now.
*
* TODO: Come back to this!
*/
it("Returns false for CONTROL", () => {
const test: string = "test this char '\"'";
const result: boolean = false; // Parameter.isSafeChar(test);
expect(result).to.be.false;
});
});
/**
......@@ -259,6 +346,11 @@ describe("Parameter", () => {
it("exists", () => {
expect(Parameter).itself.respondsTo("isQuotedString");
});
it("", () => {
});
});
/**
......@@ -271,6 +363,11 @@ describe("Parameter", () => {
it("exists", () => {
expect(Parameter).itself.respondsTo("isQSafeChar");
});
it("", () => {
});
});
});
......
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