forked from opensearch-project/opensearch-api-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Theo Truong <[email protected]>
- Loading branch information
Showing
4 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,84 @@ | ||
import { type StoryEvaluation } from './types/eval.types' | ||
import { type Evaluation, Result, type StoryEvaluation } from './types/eval.types' | ||
|
||
function b (text: string): string { return `\x1b[1m${text}\x1b[0m` } | ||
function i (text: string): string { return `\x1b[3m${text}\x1b[0m` } | ||
|
||
function padding (text: string, length: number, prefix: number = 0): string { | ||
const spaces = length - text.length > 0 ? ' '.repeat(length - text.length) : '' | ||
return `${' '.repeat(prefix)}${text}${spaces}` | ||
} | ||
|
||
function green (text: string): string { return `\x1b[32m${text}\x1b[0m` } | ||
function red (text: string): string { return `\x1b[31m${text}\x1b[0m` } | ||
function yellow (text: string): string { return `\x1b[33m${text}\x1b[0m` } | ||
function cyan (text: string): string { return `\x1b[36m${text}\x1b[0m` } | ||
function gray (text: string): string { return `\x1b[90m${text}\x1b[0m` } | ||
function magenta (text: string): string { return `\x1b[35m${text}\x1b[0m` } | ||
|
||
export default class ResultsDisplayer { | ||
evaluation: StoryEvaluation | ||
skip_components: boolean | ||
|
||
constructor (evaluation: StoryEvaluation) { | ||
this.evaluation = evaluation | ||
this.skip_components = [Result.PASSED, Result.SKIPPED].includes(evaluation.result) | ||
} | ||
|
||
display (): void { | ||
this.#display_story() | ||
this.#display_prologues() | ||
this.#display_epilogues() | ||
this.#display_chapters() | ||
} | ||
|
||
#display_story (): void { | ||
const result = this.#result(this.evaluation.result) | ||
const title = cyan(b(this.evaluation.display_path)) | ||
console.log(`${result} ${title}`) | ||
} | ||
|
||
#display_chapters (): void { | ||
const evaluations = this.evaluation.chapters | ||
if (this.skip_components || evaluations == null) return | ||
|
||
let result = Result.PASSED | ||
if (evaluations.some(e => e.result === Result.ERROR)) result = Result.ERROR | ||
else if (evaluations.some(e => e.result === Result.FAILED)) result = Result.FAILED | ||
else if (evaluations.every(e => e.result === Result.SKIPPED)) result = Result.SKIPPED | ||
this.#display_evaluation({ result }, 'CHAPTERS', 4) | ||
|
||
for (const evaluation of evaluations) { | ||
this.#display_evaluation(evaluation, i(evaluation.synopsis), 7) | ||
} | ||
} | ||
|
||
#display_prologues (): void { | ||
const evaluation = this.evaluation.prologues | ||
if (this.skip_components || evaluation == null) return | ||
this.#display_evaluation(evaluation, 'PROLOGUES', 4) | ||
} | ||
|
||
#display_epilogues (): void { | ||
const evaluation = this.evaluation.epilogues | ||
if (this.skip_components || evaluation == null) return | ||
this.#display_evaluation(evaluation, 'EPILOGUES', 4) | ||
} | ||
|
||
#display_evaluation (evaluation: Evaluation, title: string, prefix: number = 0): void { | ||
const result = padding(this.#result(evaluation.result), 0, prefix) | ||
const message = evaluation.message != null ? `${gray('(' + evaluation.message + ')')}` : '' | ||
console.log(`${result} ${title} ${message}`) | ||
} | ||
|
||
#result (r: Result): string { | ||
const text = padding(r, 7) | ||
switch (r) { | ||
case Result.PASSED: return green(text) | ||
case Result.FAILED: return magenta(text) | ||
case Result.SKIPPED: return yellow(text) | ||
case Result.ERROR: return red(text) | ||
case Result.OK: return green(text) | ||
default: return gray(text) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters