Commit 3ffb8d87 authored by Mark Stenglein's avatar Mark Stenglein

Moar tests

parent 867935a0
Pipeline #906 passed with stage
in 20 seconds
......@@ -3,14 +3,15 @@ import { isAlpha } from "./util";
/**
* Implementation of a Content Line from RFC 5545
*
* @author Mark Stenglein <mark@stengle.in>
*
* Chapter 3.1 defines the content line. This implementation will use it as an
* abstract class which can be extended later by the specific content types.
*
* This class defines all of the general features specified by the chapter,
* while leaving the specific features required by individual component objects
* unfilled.
*
* @author Mark Stenglein <mark@stengle.in>
* @since 0.1.0
*/
export default class ContentLine {
private _name: string;
......
/**
* Utility File
*
* @author Mark Stenglein <mark@stengle.in>
*/
/**
* isAlpha checks to make sure that an input string consists ONLY of lower or
* upper case letters.
*
* @since 0.1.0
* @param input Input string to be tested
* @returns boolean value of if it is only alpha
*/
export function isAlpha(input: string): boolean {
return /^[a-zA-Z]+$/.test(input);
}
......@@ -2,26 +2,116 @@ import ContentLine from "../src/ContentLine";
import { expect } from "chai";
import "mocha";
/**
* Test The ContentLine class
*/
describe("ContentLine", () => {
it("Should exist", () => {
let result = true;
expect(ContentLine).to.exist;
});
if (typeof ContentLine === undefined) {
result = false;
}
/**
* Test ContentLine's constructor
*/
describe("constructor", () => {
it("Should create an object", () => {
const test: ContentLine = new ContentLine("name", ["param"], "value");
let result: boolean = true;
expect(result).to.be.true;
});
if (typeof test === undefined) {
result = false;
}
expect(result).to.be.true;
});
it("Should have the same name as given on input", () => {
const test: string = "name";
const testLine: ContentLine = new ContentLine(test, ["param"], "value");
const result: string = testLine.name;
expect(result).to.be.equal(test);
});
it("Should have the same param as given on input", () => {
const testParam1: string[] = ["param1"];
const testLine: ContentLine = new ContentLine("name", testParam1, "value");
const result: string[] = testLine.params;
it("Should create an object", () => {
const test = new ContentLine("name", ["param"], "value");
let result = true;
expect(result).to.be.deep.equal(testParam1);
});
if (typeof test === undefined) {
result = false;
}
it("Should accept multiple param values on input", () => {
const testParams: string[] = ["param1", "param2"];
const testLine: ContentLine = new ContentLine("name", testParams, "value");
const result: string[] = testLine.params;
expect(result).to.be.true;
expect(result).to.be.deep.equal(testParams);
});
it("Should accept no param values as input", () => {
const testParams: string[] = [];
const testLine: ContentLine = new ContentLine("name", testParams, "value");
const result: string[] = testLine.params;
expect(result).to.be.deep.equal(testParams);
});
it("Should have the same value as given on input", () => {
const testValue: string = "testValue";
const testLine: ContentLine = new ContentLine("name", ["test"], testValue);
const result: string = testLine.value;
expect(result).to.be.equal(testValue);
});
});
});
/**
* Test `fold` static method
*
* @author Mark Stenglein <mark@stenle.in>
*/
describe("fold", () => {
it("Should exist as a static method", () => {
expect(ContentLine).itself.respondsTo("fold");
});
it("Should not fold short lines", () => {
const test: string = "A short line";
const result: string = ContentLine.fold(test);
expect(test).to.be.equal(result);
});
it("Should fold lines longer than 74 characters", () => {
const test: string = "This is a quite long string which should" +
" be folded on the 74th character exactly.";
const expected: string = "This is a quite long string which" +
" should be folded on the 74th character e\r\n xactly.";
const result: string = ContentLine.fold(test);
expect(result).to.be.equal(expected);
});
it("Should fold really long lines at each fold spot.", () => {
const test: string = "This string is longer than 10, being 74" +
" characters long to be quite exact.This string is longer" +
" than 10, being 74 characters long to be quite exact.This" +
" string is longer than 10, being 74 characters long to be" +
" quite exact.";
const expected: string = "This string is longer than 10, being" +
" 74 characters long to be quite exact.\r\n This string is" +
" longer than 10, being 74 characters long to be quite" +
" exact.\r\n This string is longer than 10, being 74" +
" characters long to be quite exact.";
const result: string = ContentLine.fold(test);
expect(result).to.be.equal(expected);
})
});
});
......@@ -6,13 +6,7 @@ describe("util", () => {
describe("isAlpha", () => {
it("Should exist", () => {
let result = true;
if (typeof isAlpha === undefined) {
result = false;
}
expect(result).to.be.true;
expect(isAlpha).to.exist;
});
it("Should return false for numbers", () => {
......
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