-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.ts
36 lines (30 loc) · 1.19 KB
/
main_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// rndhex - main_test.ts
import { assertMatch } from "https://deno.land/[email protected]/assert/mod.ts";
import { getRandomHexCode, printColoredSquare } from "./main.ts";
// Test for generating a random hex code
Deno.test("Random Hex Code Generation", () => {
const hexCode = getRandomHexCode();
// Check that the hex code matches the pattern for a valid hex color code
const hexPattern = /^#[0-9a-fA-F]{6}$/;
assertMatch(hexCode, hexPattern, `Generated hex code (${hexCode}) is not valid`);
});
// Mock the console output to test the square printing
Deno.test("Print Colored Square Format", () => {
const hexCode = "#ffffff"; // Example hex code to test
// Capture the console output
const originalConsoleLog = console.log;
let consoleOutput = "";
console.log = (output: string) => {
consoleOutput += output + "\n";
};
try {
// Call the function to print the colored square
printColoredSquare(hexCode);
// Check that the output contains the square format
const squarePattern = /###\n###\n###/;
assertMatch(consoleOutput, squarePattern, "Square format not found in output");
} finally {
// Restore the original console.log
console.log = originalConsoleLog;
}
});