Added two more tests and removed file extension package.

parent f860cba2
......@@ -4,10 +4,9 @@
* @Copyright (c) 2018, Marcel Dominic Bandowski.
* Released under the MIT License.
*/
const camelcase = require("camelcase");
const fileExtension = require("file-extension");
import * as path from "path";
const camelcase = require("camelcase");
/**
* compare the input before and after the conversion
* @param input
......@@ -24,9 +23,9 @@ export const checkString = (input: string): boolean => {
*/
export const checkFile = (input: string): boolean => {
if (input.match(new RegExp(/^.*\./))) {
const fileName = input.replace(`.${fileExtension(input, {preserveCase: true})}`, "");
const fileName: string = path.basename(input, path.extname(input));
return fileName === camelcase(fileName);
} else {
return false;
}
};
\ No newline at end of file
};
......@@ -41,6 +41,11 @@ test('checkFileWrongJPG', async () => {
expect(checkFile("Camel Case.JPG")).toBe(false);
});
test('checkFileWithOnlyLowerOrUppercaseChars', async () => {
expect(checkFile("camelcase.jpg")).toBe(true);
expect(checkFile("CAMELCASE.JPG")).toBe(false);
});
/**
* Test with missing file extension
*/
......@@ -49,4 +54,4 @@ test('checkFileMissingFileExtension', async () => {
expect(checkFile("CamelCase")).toBe(false);
expect(checkFile("camel Case")).toBe(false);
expect(checkFile("Camel Case")).toBe(false);
});
\ No newline at end of file
});
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