23import {
messages } from
'../modules/messageReference';
29suite(
'MessageProvider Test Suite',
function () {
35 suite(
'Basic Message Retrieval', () => {
40 test(
'should retrieve simple messages without parameters', () => {
42 const refreshMessage =
getMessage(
"fileRefreshed");
43 assert.ok(typeof refreshMessage ===
'string');
44 assert.ok(refreshMessage.length > 0);
45 assert.strictEqual(refreshMessage,
"Refreshing file content.");
47 const saveFailed =
getMessage(
"fileSaveFailed");
48 assert.ok(typeof saveFailed ===
'string');
49 assert.strictEqual(saveFailed,
"Failed to save the file, please try saving it again.");
56 test(
'should handle messages with single parameters', () => {
57 const testPath =
'/test/path/file.json';
58 const fileLoaded =
getMessage(
"fileLoaded", testPath);
60 assert.ok(typeof fileLoaded ===
'string');
61 assert.ok(fileLoaded.includes(testPath));
62 assert.strictEqual(fileLoaded, `File ${testPath} loaded!`);
69 test(
'should handle messages with multiple parameters', () => {
70 const oldPath =
'/old/path';
71 const newPath =
'/new/path';
72 const pathUpdated =
getMessage(
"filePathUpdated", oldPath, newPath);
74 assert.ok(typeof pathUpdated ===
'string');
75 assert.ok(pathUpdated.includes(oldPath));
76 assert.ok(pathUpdated.includes(newPath));
77 assert.strictEqual(pathUpdated, `The
path has been updated from ${oldPath} to ${newPath}.`);
85 suite(
'Parameter Substitution', () => {
90 test(
'should handle various data types as parameters', () => {
92 const stringParam =
getMessage(
"fileUnloaded",
"test.json");
93 assert.ok(stringParam.includes(
"test.json"));
96 const numberParam =
getMessage(
"fileLoaded", 12345);
97 assert.ok(numberParam.includes(
"12345"));
100 const booleanParam =
getMessage(
"fileLoaded",
true);
101 assert.ok(booleanParam.includes(
"true"));
108 test(
'should handle undefined and null parameters gracefully', () => {
109 const undefinedParam =
getMessage(
"fileLoaded", undefined);
110 assert.ok(typeof undefinedParam ===
'string');
111 assert.ok(undefinedParam.includes(
"undefined"));
113 const nullParam =
getMessage(
"fileLoaded",
null);
114 assert.ok(typeof nullParam ===
'string');
115 assert.ok(nullParam.includes(
"null"));
122 test(
'should handle empty string parameters', () => {
123 const emptyParam =
getMessage(
"fileLoaded",
"");
124 assert.ok(typeof emptyParam ===
'string');
125 assert.strictEqual(emptyParam,
"File loaded!");
132 test(
'should handle special characters in parameters', () => {
133 const specialChars =
'/path/with spaces & symbols!@#$%.json';
134 const result =
getMessage(
"fileLoaded", specialChars);
135 assert.ok(result.includes(specialChars));
136 assert.strictEqual(result, `File ${specialChars} loaded!`);
144 suite(
'Message Reference Validation', () => {
149 test(
'should contain all expected message keys', () => {
150 const expectedKeys = [
156 'fileExcludedActivationDisabled',
162 const englishMessages =
messages.en;
163 expectedKeys.forEach(key => {
164 assert.ok(key in englishMessages, `Message key
'${key}' should exist in English
messages`);
165 assert.ok(typeof englishMessages[key] ===
'function', `Message
'${key}' should be a
function`);
173 test(
'should have functions that return strings', () => {
175 const englishMessages =
messages.en;
176 const fileLoaded = englishMessages.fileLoaded(
'/test/path');
177 assert.strictEqual(typeof fileLoaded,
'string');
179 const parseError = englishMessages.fileParseError(
'/test/file',
'syntax error');
180 assert.strictEqual(typeof parseError,
'string');
182 const cwdUpdated = englishMessages.cwdUpdated(
'/old',
'/new');
183 assert.strictEqual(typeof cwdUpdated,
'string');
190 test(
'should validate message function signatures', () => {
191 const englishMessages =
messages.en;
193 assert.ok(englishMessages.fileLoaded.length >= 1,
'fileLoaded should accept at least 1 parameter');
194 assert.ok(englishMessages.fileUnloaded.length >= 1,
'fileUnloaded should accept at least 1 parameter');
195 assert.ok(englishMessages.cwdDoesNotExist.length >= 1,
'cwdDoesNotExist should accept at least 1 parameter');
198 assert.ok(englishMessages.fileParseError.length >= 2,
'fileParseError should accept at least 2 parameters');
199 assert.ok(englishMessages.filePathUpdated.length >= 2,
'filePathUpdated should accept at least 2 parameters');
200 assert.ok(englishMessages.cwdUpdated.length >= 2,
'cwdUpdated should accept at least 2 parameters');
203 assert.ok(englishMessages.fileRefreshed.length === 0,
'fileRefreshed should accept 0 parameters');
204 assert.ok(englishMessages.fileExcludedActivationDisabled.length === 0,
'fileExcludedActivationDisabled should accept 0 parameters');
205 assert.ok(englishMessages.fileSaveFailed.length === 0,
'fileSaveFailed should accept 0 parameters');
213 suite(
'Error Handling', () => {
218 test(
'should handle invalid message keys gracefully', () => {
222 const result =
getMessage(
"nonExistentMessage" as any);
224 assert.strictEqual(typeof result,
'string');
227 assert.ok(error instanceof Error);
235 test(
'should handle too many parameters gracefully', () => {
237 const result =
getMessage(
"fileRefreshed",
"extra",
"parameters",
"should",
"be",
"ignored");
238 assert.strictEqual(typeof result,
'string');
239 assert.strictEqual(result,
"Refreshing file content.");
246 test(
'should handle too few parameters gracefully', () => {
248 const result =
getMessage(
"filePathUpdated",
"/only/one/param");
249 assert.strictEqual(typeof result,
'string');
250 assert.ok(result.includes(
"/only/one/param"));
258 suite(
'Message Content Validation', () => {
263 test(
'should have meaningful error messages', () => {
264 const filePath =
'/test/file.json';
265 const error =
'Syntax error at line 5';
267 const parseError =
getMessage(
"fileParseError", filePath, error);
268 assert.ok(parseError.includes(filePath),
'Parse error should include file path');
269 assert.ok(parseError.includes(error),
'Parse error should include error details');
270 assert.ok(parseError.toLowerCase().includes(
'error'),
'Parse error should mention error');
277 test(
'should have informative status messages', () => {
278 const absolutePath =
'/absolute/path/to/file.json';
279 const loadedMsg =
getMessage(
"fileLoaded", absolutePath);
281 assert.ok(loadedMsg.includes(absolutePath),
'Loaded message should include file path');
282 assert.ok(loadedMsg.toLowerCase().includes(
'loaded'),
'Loaded message should mention loaded');
284 const refreshMsg =
getMessage(
"fileRefreshed");
285 assert.ok(refreshMsg.toLowerCase().includes(
'refresh'),
'Refresh message should mention refresh');
292 test(
'should have clear directory change messages', () => {
293 const oldCwd =
'/old/directory';
294 const newCwd =
'/new/directory';
296 const cwdUpdate =
getMessage(
"cwdUpdated", oldCwd, newCwd);
297 assert.ok(cwdUpdate.includes(oldCwd),
'CWD update should include old directory');
298 assert.ok(cwdUpdate.includes(newCwd),
'CWD update should include new directory');
299 assert.ok(cwdUpdate.toLowerCase().includes(
'updated'),
'CWD update should mention update');
301 const nonExistentPath =
'/nonexistent/path';
302 const cwdError =
getMessage(
"cwdDoesNotExist", nonExistentPath);
303 assert.ok(cwdError.includes(nonExistentPath),
'CWD error should include path');
311 suite(
'Integration and Consistency', () => {
316 test(
'should maintain consistent message formatting', () => {
318 const loadedMsg =
getMessage(
"fileLoaded",
"/test/file");
319 const unloadedMsg =
getMessage(
"fileUnloaded",
"/test/file");
322 assert.ok(loadedMsg.endsWith(
'!') || loadedMsg.endsWith(
'.'),
'Loaded message should end with punctuation');
324 assert.ok(typeof unloadedMsg ===
'string' && unloadedMsg.length > 0,
'Unloaded message should be a valid string');
331 test(
'should handle concurrent message generation', () => {
333 const promises = Array.from({ length: 100 }, (_, i) => {
334 return new Promise<string>((resolve) => {
335 const message =
getMessage(
"fileLoaded", `/test/file${i}.json`);
340 return Promise.all(
promises).then(results => {
341 assert.strictEqual(results.length, 100);
342 results.forEach((message, index) => {
343 assert.ok(message.includes(`file${index}.json`));
352 test(
'should support message caching if implemented', () => {
358 assert.strictEqual(message1, message2);
361 const paramMsg1 =
getMessage(
"fileLoaded",
"/same/path");
362 const paramMsg2 =
getMessage(
"fileLoaded",
"/same/path");
363 assert.strictEqual(paramMsg1, paramMsg2);
371 suite(
'Performance and Memory', () => {
376 test(
'should handle large parameter strings efficiently', () => {
377 const largePath =
'/very/long/path/with/many/segments/'.repeat(100) +
'file.json';
378 const startTime = Date.now();
380 const result =
getMessage(
"fileLoaded", largePath);
381 const elapsed = Date.now() - startTime;
383 assert.ok(elapsed < 100,
'Message generation should complete quickly even with large parameters');
384 assert.ok(result.includes(largePath));
391 test(
'should handle rapid successive calls efficiently', () => {
392 const startTime = Date.now();
394 for (let i = 0; i < 1000; i++) {
396 getMessage(
"fileLoaded", `/test/file${i}.json`);
399 const elapsed = Date.now() - startTime;
400 assert.ok(elapsed < 1000,
'Rapid message generation should complete within reasonable time');
import *as fsp from fs promises
import *as assert from assert
export const getMessage
Exported function for direct message retrieval.
export const messages
Complete message dictionary for all supported languages with type-safe function interfaces @export Ex...