From d20c308f53d12f58a2b3e80ece44914d9cc66131 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 23 Jan 2025 15:57:00 -0500 Subject: [PATCH] Add 'override' modifier to overwritten properties in file types, generate test coverage for all runtimes --- bunfig.toml | 4 ++++ coverage.sh | 6 ------ deno.jsonc | 2 +- justfile | 10 +++++++--- package.json | 5 +++-- src/common/editor.ts | 12 ++++++++++-- src/common/filetype/c.ts | 16 ++++++++-------- src/common/filetype/css.ts | 16 ++++++++-------- src/common/filetype/javascript.ts | 20 ++++++++++---------- src/common/filetype/rust.ts | 16 ++++++++-------- src/common/filetype/shell.ts | 12 ++++++------ tools/bun-coverage.sh | 3 +++ tools/deno-coverage.sh | 5 +++++ tools/tsx-coverage.sh | 12 ++++++++++++ 14 files changed, 85 insertions(+), 54 deletions(-) delete mode 100755 coverage.sh create mode 100755 tools/bun-coverage.sh create mode 100755 tools/deno-coverage.sh create mode 100755 tools/tsx-coverage.sh diff --git a/bunfig.toml b/bunfig.toml index d0f2114..ebec340 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -8,5 +8,9 @@ save = false # always enable coverage coverage = true +coverageReporter = ["text", "lcov"] +coverageDir = "coverage/raw" +coverageThreshold = 0.7 + # disable code coverage counting test files coverageSkipTestFiles = true \ No newline at end of file diff --git a/coverage.sh b/coverage.sh deleted file mode 100755 index b341c2d..0000000 --- a/coverage.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -rm -fr /coverage/ -deno test --allow-all --coverage=coverage -deno coverage coverage --lcov > coverage/coverage.lcov -genhtml -o coverage coverage/coverage.lcov -rm coverage/*.json diff --git a/deno.jsonc b/deno.jsonc index a146961..7491a36 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -13,6 +13,6 @@ "semiColons": true, "singleQuote": true }, - "nodeModulesDir": true, + "nodeModulesDir": "auto", "exclude": ["src/bun/"] } diff --git a/justfile b/justfile index e8f9712..57ec698 100644 --- a/justfile +++ b/justfile @@ -3,14 +3,14 @@ default: @just --list # Test coverage -coverage: deno-coverage bun-coverage +coverage: deno-coverage bun-coverage tsx-coverage # Generate test coverage and open report in default browser open-coverage: coverage - open coverage/index.html + open coverage # Typescript checking -check: deno-check bun-check +check: deno-check bun-check tsx-check # Generate source docs docs: @@ -93,6 +93,10 @@ tsx-check: tsx-test: npm run tsx-test +# Create test coverage report with tsx +tsx-coverage: + npm run tsx-coverage + # Run with tsx (NodeJS) tsx-run file="": npm run tsx-run {{file}} diff --git a/package.json b/package.json index 595de32..06f828b 100644 --- a/package.json +++ b/package.json @@ -8,15 +8,16 @@ }, "scripts": { "bun-check": "bunx tsc", - "bun-coverage": "bun test --coverage", + "bun-coverage": "./tools/bun-coverage.sh", "bun-run": "bun run ./src/scroll.ts", "bun-test": "bun test", "deno-lint": "deno lint", "deno-check": "deno check --all -c deno.jsonc ./src/deno/*.ts ./src/common/*.ts ./src/tsx/*.ts", - "deno-coverage": "./coverage.sh", + "deno-coverage": "./tools/deno-coverage.sh", "deno-run": "deno run --allow-all --deny-hrtime ./src/scroll.ts", "deno-test": "deno test --allow-all", "tsx-check": "npx tsc", + "tsx-coverage": "./tools/tsx-coverage.sh", "tsx-run": "tsx ./src/scroll.ts", "tsx-test": "tsx --test './src/common/all_test.ts'" }, diff --git a/src/common/editor.ts b/src/common/editor.ts index dd25e09..bdc3cfc 100644 --- a/src/common/editor.ts +++ b/src/common/editor.ts @@ -452,6 +452,7 @@ export default class Editor { for (let y = 0; y < this.screen.rows; y++) { this.buffer.append(Ansi.ClearLine); const fileRow = y + this.offset.y; + if (fileRow >= this.numRows) { this.drawPlaceholderRow(fileRow); } else { @@ -479,7 +480,12 @@ export default class Editor { this.buffer.append(row.render(this.offset.x, len)); } + /** + * Visually display an empty row + */ protected drawPlaceholderRow(y: number): void { + // Show program name and version in the middle of the screen in + // empty, clean documents if (y === Math.trunc(this.screen.rows / 2) && this.document.isEmpty()) { const message = `Scroll editor -- version ${SCROLL_VERSION}`; const messageLen = (message.length > this.screen.cols) @@ -494,9 +500,11 @@ export default class Editor { } this.buffer.append(message, messageLen); - } else { - this.buffer.append('~'); + return; } + + // Display an empty row with a starting tilde + this.buffer.append('~'); } protected drawStatusBar(): void { diff --git a/src/common/filetype/c.ts b/src/common/filetype/c.ts index 0cc0a15..3ff8b76 100644 --- a/src/common/filetype/c.ts +++ b/src/common/filetype/c.ts @@ -7,11 +7,11 @@ import { } from './base.ts'; export class CFile extends AbstractFileType { - public readonly name: FileLang = FileLang.C; - public readonly singleLineComment = Some('//'); - public readonly multiLineCommentStart: Option = Some('/*'); - public readonly multiLineCommentEnd: Option = Some('*/'); - public readonly keywords1 = [ + public override readonly name: FileLang = FileLang.C; + public override readonly singleLineComment = Some('//'); + public override readonly multiLineCommentStart: Option = Some('/*'); + public override readonly multiLineCommentEnd: Option = Some('*/'); + public override readonly keywords1 = [ 'continue', 'register', 'restrict', @@ -44,7 +44,7 @@ export class CFile extends AbstractFileType { 'do', 'if', ]; - public readonly keywords2 = [ + public override readonly keywords2 = [ '#include', 'unsigned', 'uint32_t', @@ -74,7 +74,7 @@ export class CFile extends AbstractFileType { 'int', '#if', ]; - public readonly operators = [ + public override readonly operators = [ '>>>=', '**=', '&&=', @@ -143,7 +143,7 @@ export class CFile extends AbstractFileType { ',', ';', ]; - public readonly hlOptions: HighlightingOptions = { + public override readonly hlOptions: HighlightingOptions = { ...defaultHighlightOptions, characters: true, hexNumbers: true, diff --git a/src/common/filetype/css.ts b/src/common/filetype/css.ts index 09da21c..4ca52f3 100644 --- a/src/common/filetype/css.ts +++ b/src/common/filetype/css.ts @@ -7,11 +7,11 @@ import { } from './base.ts'; export class CSSFile extends AbstractFileType { - public readonly name: FileLang = FileLang.CSS; - public readonly singleLineComment = None; - public readonly multiLineCommentStart: Option = Some('/*'); - public readonly multiLineCommentEnd: Option = Some('*/'); - public readonly keywords1 = [ + public override readonly name: FileLang = FileLang.CSS; + public override readonly singleLineComment = None; + public override readonly multiLineCommentStart: Option = Some('/*'); + public override readonly multiLineCommentEnd: Option = Some('*/'); + public override readonly keywords1 = [ ':active', ':any-link', ':autofill', @@ -87,7 +87,7 @@ export class CSSFile extends AbstractFileType { '@supports', '@view-transition', ]; - public readonly keywords2 = [ + public override readonly keywords2 = [ 'animation-range-end', 'animation-range-start', 'accent-color', @@ -386,8 +386,8 @@ export class CSSFile extends AbstractFileType { 'overscroll-behavior-y', 'overflow-clip-margin', ]; - public readonly operators = ['::', ':', ',', '+', '>', '~', '-']; - public readonly hlOptions: HighlightingOptions = { + public override readonly operators = ['::', ':', ',', '+', '>', '~', '-']; + public override readonly hlOptions: HighlightingOptions = { ...defaultHighlightOptions, }; } diff --git a/src/common/filetype/javascript.ts b/src/common/filetype/javascript.ts index 2d1a118..d0b1312 100644 --- a/src/common/filetype/javascript.ts +++ b/src/common/filetype/javascript.ts @@ -7,11 +7,11 @@ import { } from './base.ts'; export class JavaScriptFile extends AbstractFileType { - public readonly name: FileLang = FileLang.JavaScript; - public readonly singleLineComment = Some('//'); - public readonly multiLineCommentStart: Option = Some('/*'); - public readonly multiLineCommentEnd: Option = Some('*/'); - public readonly keywords1 = [ + public override readonly name: FileLang = FileLang.JavaScript; + public override readonly singleLineComment = Some('//'); + public override readonly multiLineCommentStart: Option = Some('/*'); + public override readonly multiLineCommentEnd: Option = Some('*/'); + public override readonly keywords1 = [ '=>', 'await', 'break', @@ -53,7 +53,7 @@ export class JavaScriptFile extends AbstractFileType { 'with', 'yield', ]; - public readonly keywords2 = [ + public override readonly keywords2 = [ 'arguments', 'as', 'async', @@ -72,7 +72,7 @@ export class JavaScriptFile extends AbstractFileType { 'Symbol', 'undefined', ]; - public readonly operators = [ + public override readonly operators = [ '>>>=', '**=', '<<=', @@ -121,7 +121,7 @@ export class JavaScriptFile extends AbstractFileType { ',', ';', ]; - public readonly hlOptions: HighlightingOptions = { + public override readonly hlOptions: HighlightingOptions = { ...defaultHighlightOptions, octalNumbers: true, hexNumbers: true, @@ -131,8 +131,8 @@ export class JavaScriptFile extends AbstractFileType { } export class TypeScriptFile extends JavaScriptFile { - public readonly name: FileLang = FileLang.TypeScript; - public readonly keywords2 = [ + public override readonly name: FileLang = FileLang.TypeScript; + public override readonly keywords2 = [ ...super.secondaryKeywords, // Typescript-specific 'any', diff --git a/src/common/filetype/rust.ts b/src/common/filetype/rust.ts index b588971..b9bcb1f 100644 --- a/src/common/filetype/rust.ts +++ b/src/common/filetype/rust.ts @@ -7,11 +7,11 @@ import { } from './base.ts'; export class RustFile extends AbstractFileType { - public readonly name: FileLang = FileLang.Rust; - public readonly singleLineComment = Some('//'); - public readonly multiLineCommentStart: Option = Some('/*'); - public readonly multiLineCommentEnd: Option = Some('*/'); - public readonly keywords1 = [ + public override readonly name: FileLang = FileLang.Rust; + public override readonly singleLineComment = Some('//'); + public override readonly multiLineCommentStart: Option = Some('/*'); + public override readonly multiLineCommentEnd: Option = Some('*/'); + public override readonly keywords1 = [ 'continue', 'return', 'static', @@ -47,7 +47,7 @@ export class RustFile extends AbstractFileType { 'if', 'in', ]; - public readonly keywords2 = [ + public override readonly keywords2 = [ 'DoubleEndedIterator', 'ExactSizeIterator', 'IntoIterator', @@ -109,7 +109,7 @@ export class RustFile extends AbstractFileType { '&self', 'self', ]; - public readonly operators = [ + public override readonly operators = [ '||=', '>>=', '<=>', @@ -160,7 +160,7 @@ export class RustFile extends AbstractFileType { ',', '-', ]; - public readonly hlOptions: HighlightingOptions = { + public override readonly hlOptions: HighlightingOptions = { ...defaultHighlightOptions, characters: true, binNumbers: true, diff --git a/src/common/filetype/shell.ts b/src/common/filetype/shell.ts index 5ffc0de..30e731c 100644 --- a/src/common/filetype/shell.ts +++ b/src/common/filetype/shell.ts @@ -7,9 +7,9 @@ import { } from './base.ts'; export class ShellFile extends AbstractFileType { - public readonly name: FileLang = FileLang.Shell; - public readonly singleLineComment = Some('#'); - public readonly keywords1 = [ + public override readonly name: FileLang = FileLang.Shell; + public override readonly singleLineComment = Some('#'); + public override readonly keywords1 = [ 'case', 'do', 'done', @@ -28,9 +28,9 @@ export class ShellFile extends AbstractFileType { 'while', 'declare', ]; - public readonly keywords2 = ['set']; - public readonly operators = ['[[', ']]']; - public readonly hlOptions: HighlightingOptions = { + public override readonly keywords2 = ['set']; + public override readonly operators = ['[[', ']]']; + public override readonly hlOptions: HighlightingOptions = { ...defaultHighlightOptions, numbers: false, }; diff --git a/tools/bun-coverage.sh b/tools/bun-coverage.sh new file mode 100755 index 0000000..41b7a9c --- /dev/null +++ b/tools/bun-coverage.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +bun test --coverage +genhtml -o coverage/bun coverage/raw/lcov.info diff --git a/tools/deno-coverage.sh b/tools/deno-coverage.sh new file mode 100755 index 0000000..8de1b69 --- /dev/null +++ b/tools/deno-coverage.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +deno test --allow-all --coverage=coverage/raw +deno coverage coverage/raw --lcov > coverage/raw/deno.lcov +rm -rf coverage/raw/*.json +genhtml --ignore-errors inconsistent,inconsistent -o coverage/deno coverage/raw/deno.lcov diff --git a/tools/tsx-coverage.sh b/tools/tsx-coverage.sh new file mode 100755 index 0000000..6b9b94b --- /dev/null +++ b/tools/tsx-coverage.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail +PARENT_DIR="$(dirname "$(realpath "$0")")" +TSX="$(realpath "${PARENT_DIR}/../node_modules/.bin/tsx")" + +"${TSX}" --test --experimental-test-coverage \ + --test-reporter=dot \ + --test-reporter-destination=stdout \ + --test-reporter=lcov \ + --test-reporter-destination=coverage/raw/tsx.lcov './src/common/all_test.ts' + +genhtml --ignore-errors inconsistent,inconsistent -o coverage/tsx coverage/raw/tsx.lcov \ No newline at end of file