2025-10-19 13:14:18 +00:00
|
|
|
import { assert, assertEquals } from 'jsr:@std/assert@^1.0.0';
|
2025-10-18 15:58:20 +00:00
|
|
|
import { Logger } from '../ts/logger.ts';
|
2025-03-26 22:19:24 +00:00
|
|
|
|
|
|
|
// Create a Logger instance for testing
|
|
|
|
const logger = new Logger();
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should create a logger instance', () => {
|
|
|
|
assert(logger instanceof Logger);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should log messages with different log levels', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
// We're not testing console output directly, just ensuring no errors
|
|
|
|
logger.log('Regular log message');
|
|
|
|
logger.error('Error message');
|
|
|
|
logger.warn('Warning message');
|
|
|
|
logger.success('Success message');
|
|
|
|
|
|
|
|
// Just assert that the test runs without errors
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should create a logbox with title, content, and end', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just ensuring no errors occur
|
|
|
|
logger.logBoxTitle('Test Box', 40);
|
|
|
|
logger.logBoxLine('This is a test line');
|
|
|
|
logger.logBoxEnd();
|
|
|
|
|
|
|
|
// Just assert that the test runs without errors
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should handle width persistence between logbox calls', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
logger.logBoxTitle('Width Test', 45);
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// These should use the width from the title
|
|
|
|
logger.logBoxLine('Line 1');
|
|
|
|
logger.logBoxLine('Line 2');
|
|
|
|
logger.logBoxEnd();
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
let errorThrown = false;
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
try {
|
|
|
|
// This should work fine after the reset in logBoxEnd
|
|
|
|
logger.logBoxTitle('New Box', 30);
|
|
|
|
logger.logBoxLine('New line');
|
|
|
|
logger.logBoxEnd();
|
2025-10-18 16:01:38 +00:00
|
|
|
} catch (_error) {
|
2025-03-26 22:19:24 +00:00
|
|
|
errorThrown = true;
|
|
|
|
}
|
2025-10-18 16:01:38 +00:00
|
|
|
|
|
|
|
assertEquals(errorThrown, false);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should use default width when no width is specified', () => {
|
2025-03-28 16:19:43 +00:00
|
|
|
// This should automatically use the default width instead of throwing
|
2025-03-26 22:19:24 +00:00
|
|
|
let errorThrown = false;
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
try {
|
2025-03-28 16:19:43 +00:00
|
|
|
logger.logBoxLine('This should use default width');
|
|
|
|
logger.logBoxEnd();
|
2025-10-18 16:01:38 +00:00
|
|
|
} catch (_error) {
|
2025-03-26 22:19:24 +00:00
|
|
|
errorThrown = true;
|
|
|
|
}
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-28 16:19:43 +00:00
|
|
|
// Verify no error was thrown
|
2025-10-18 16:01:38 +00:00
|
|
|
assertEquals(errorThrown, false);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should create a complete logbox in one call', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just ensuring no errors occur
|
|
|
|
logger.logBox('Complete Box', [
|
|
|
|
'Line 1',
|
|
|
|
'Line 2',
|
2025-10-19 13:14:18 +00:00
|
|
|
'Line 3',
|
2025-03-26 22:19:24 +00:00
|
|
|
], 40);
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just assert that the test runs without errors
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should handle content that exceeds box width', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just ensuring no errors occur when content is too long
|
|
|
|
logger.logBox('Truncation Test', [
|
2025-10-19 13:14:18 +00:00
|
|
|
'This line is way too long and should be truncated because it exceeds the available space',
|
2025-03-26 22:19:24 +00:00
|
|
|
], 30);
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just assert that the test runs without errors
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should create dividers with custom characters', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just ensuring no errors occur
|
|
|
|
logger.logDivider(30);
|
|
|
|
logger.logDivider(20, '*');
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Just assert that the test runs without errors
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
2025-03-26 22:19:24 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('should create divider with default width', () => {
|
2025-03-28 16:19:43 +00:00
|
|
|
// This should use the default width
|
|
|
|
logger.logDivider(undefined, '-');
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-28 16:19:43 +00:00
|
|
|
// Just assert that the test runs without errors
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
2025-03-28 16:19:43 +00:00
|
|
|
});
|
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
Deno.test('Logger Demo', () => {
|
2025-03-26 22:19:24 +00:00
|
|
|
console.log('\n=== LOGGER DEMO ===\n');
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Basic logging
|
|
|
|
logger.log('Regular log message');
|
|
|
|
logger.error('Error message');
|
|
|
|
logger.warn('Warning message');
|
|
|
|
logger.success('Success message');
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Logbox with title, content lines, and end
|
|
|
|
logger.logBoxTitle('Configuration Loaded', 50);
|
|
|
|
logger.logBoxLine('SNMP Settings:');
|
|
|
|
logger.logBoxLine(' Host: 127.0.0.1');
|
|
|
|
logger.logBoxLine(' Port: 161');
|
|
|
|
logger.logBoxLine(' Version: 1');
|
|
|
|
logger.logBoxEnd();
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Complete logbox in one call
|
|
|
|
logger.logBox('UPS Status', [
|
|
|
|
'Power Status: onBattery',
|
|
|
|
'Battery Capacity: 75%',
|
2025-10-19 13:14:18 +00:00
|
|
|
'Runtime Remaining: 30 minutes',
|
2025-03-26 22:19:24 +00:00
|
|
|
], 45);
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Logbox with content that's too long for the width
|
|
|
|
logger.logBox('Truncation Example', [
|
|
|
|
'This line is short enough to fit within the box width',
|
2025-10-19 13:14:18 +00:00
|
|
|
'This line is way too long and will be truncated because it exceeds the available space for content within the logbox',
|
2025-03-26 22:19:24 +00:00
|
|
|
], 40);
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Demonstrating logbox width being remembered
|
|
|
|
logger.logBoxTitle('Width Persistence Example', 60);
|
|
|
|
logger.logBoxLine('These lines use the width from the title');
|
|
|
|
logger.logBoxLine('No need to specify the width again');
|
|
|
|
logger.logBoxEnd();
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-28 16:19:43 +00:00
|
|
|
// Demonstrating default width
|
|
|
|
console.log('\nDefault Width Example:');
|
|
|
|
logger.logBoxLine('This line uses the default width');
|
|
|
|
logger.logBoxLine('Still using default width');
|
|
|
|
logger.logBoxEnd();
|
2025-10-18 16:01:38 +00:00
|
|
|
|
2025-03-26 22:19:24 +00:00
|
|
|
// Divider example
|
|
|
|
logger.log('\nDivider example:');
|
|
|
|
logger.logDivider(30);
|
|
|
|
logger.logDivider(30, '*');
|
2025-03-28 16:19:43 +00:00
|
|
|
logger.logDivider(undefined, '=');
|
2025-03-26 22:19:24 +00:00
|
|
|
|
2025-10-18 16:01:38 +00:00
|
|
|
assert(true);
|
|
|
|
});
|