Test coverage for the FileType classes
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
c31933ed9b
commit
a7fcc982fe
@ -2,12 +2,13 @@ import Ansi, * as _Ansi from './ansi.ts';
|
||||
import Buffer from './buffer.ts';
|
||||
import Document from './document.ts';
|
||||
import Editor from './editor.ts';
|
||||
import { FileLang, FileType } from './filetype/mod.ts';
|
||||
import { FileLang } from './filetype/mod.ts';
|
||||
import { highlightToColor, HighlightType } from './highlight.ts';
|
||||
import Option, { None, Some } from './option.ts';
|
||||
import Position from './position.ts';
|
||||
import Row from './row.ts';
|
||||
|
||||
import FileType, * as FT from './filetype/mod.ts';
|
||||
import * as Fn from './fns.ts';
|
||||
import { defaultTerminalSize, SCROLL_TAB_SIZE } from './config.ts';
|
||||
import { getTestRunner } from './runtime/mod.ts';
|
||||
@ -472,6 +473,19 @@ const EditorTest = {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const FileTypeTest = {
|
||||
'FileType.from()': () => {
|
||||
for (const [ext, typeClass] of FT.fileTypeMap.entries()) {
|
||||
const file = `test${ext}`;
|
||||
const syntax = FileType.from(file);
|
||||
|
||||
assertInstanceOf(syntax, typeClass);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const OptionTest = {
|
||||
'Option.from()': () => {
|
||||
assertNone(Option.from(null));
|
||||
@ -633,6 +647,7 @@ testSuite({
|
||||
Buffer: BufferTest,
|
||||
Document: DocumentTest,
|
||||
Editor: EditorTest,
|
||||
FileType: FileTypeTest,
|
||||
Option: OptionTest,
|
||||
Position: PositionTest,
|
||||
Row: RowTest,
|
||||
|
@ -76,8 +76,7 @@ export abstract class AbstractFileType implements IFileType {
|
||||
}
|
||||
|
||||
public hasMultilineComments(): boolean {
|
||||
return this.multiLineCommentStart.isSome() &&
|
||||
this.multiLineCommentEnd.isSome();
|
||||
return this.multiLineCommentStart.and(this.multiLineCommentEnd).isSome();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,29 +9,31 @@ import { ShellFile } from './shell.ts';
|
||||
// External interface
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
export class FileType extends AbstractFileType {
|
||||
static #fileTypeMap = new Map([
|
||||
['.c', CFile],
|
||||
['.h', CFile],
|
||||
['.css', CSSFile],
|
||||
['.json', JavaScriptFile],
|
||||
['.js', JavaScriptFile],
|
||||
['.jsx', JavaScriptFile],
|
||||
['.mjs', JavaScriptFile],
|
||||
['.bash', ShellFile],
|
||||
['.sh', ShellFile],
|
||||
['.ts', TypeScriptFile],
|
||||
['.tsx', TypeScriptFile],
|
||||
]);
|
||||
export const fileTypeMap = new Map([
|
||||
['.c', CFile],
|
||||
['.h', CFile],
|
||||
['.css', CSSFile],
|
||||
['.json', JavaScriptFile],
|
||||
['.js', JavaScriptFile],
|
||||
['.jsx', JavaScriptFile],
|
||||
['.mjs', JavaScriptFile],
|
||||
['.bash', ShellFile],
|
||||
['.sh', ShellFile],
|
||||
['.ts', TypeScriptFile],
|
||||
['.tsx', TypeScriptFile],
|
||||
]);
|
||||
|
||||
export class FileType extends AbstractFileType {
|
||||
public static default(): FileType {
|
||||
return new FileType();
|
||||
}
|
||||
|
||||
public static from(filename: string): FileType {
|
||||
const ext = path.extname(filename);
|
||||
const type = FileType.#fileTypeMap.get(ext) ?? FileType;
|
||||
const type = fileTypeMap.get(ext) ?? FileType;
|
||||
|
||||
return new type();
|
||||
}
|
||||
}
|
||||
|
||||
export default FileType;
|
||||
|
@ -1,2 +1,5 @@
|
||||
export * from './base.ts';
|
||||
export * from './filetype.ts';
|
||||
|
||||
import FileType from './filetype.ts';
|
||||
export default FileType;
|
||||
|
Loading…
Reference in New Issue
Block a user