From 1b0ee601ac368a22725def9c54da8a48c529385f Mon Sep 17 00:00:00 2001 From: Revone Date: Wed, 20 Nov 2024 17:29:44 +1300 Subject: [PATCH] fix: Fix the bug where a regex replacement error occurs when test cases contain both .toBeUndefined() and .toBe or .toEqual. --- CHANGELOG.md | 2 +- package-lock.json | 52 +++++++++---------- package.json | 12 ++--- .../linked-list/doubly-linked-list.ts | 16 +++--- testToExample.ts | 14 ++--- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90663e0..9483a24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.53.2](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) +## [v1.53.3](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) ### Changes diff --git a/package-lock.json b/package-lock.json index 83e6ec9..4a81316 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.53.2", + "version": "1.53.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.53.2", + "version": "1.53.3", "license": "MIT", "devDependencies": { "@eslint/compat": "^1.2.2", @@ -19,11 +19,11 @@ "@typescript-eslint/eslint-plugin": "^8.12.1", "@typescript-eslint/parser": "^8.12.1", "auto-changelog": "^2.5.0", - "avl-tree-typed": "^1.53.1", + "avl-tree-typed": "^1.53.2", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.53.1", - "bst-typed": "^1.53.1", - "data-structure-typed": "^1.53.1", + "binary-tree-typed": "^1.53.2", + "bst-typed": "^1.53.2", + "data-structure-typed": "^1.53.2", "dependency-cruiser": "^16.5.0", "doctoc": "^2.2.1", "eslint": "^9.13.0", @@ -32,7 +32,7 @@ "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "fast-glob": "^3.3.2", - "heap-typed": "^1.53.1", + "heap-typed": "^1.53.2", "istanbul-badges-readme": "^1.9.0", "jest": "^29.7.0", "js-sdsl": "^4.4.2", @@ -3437,13 +3437,13 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.53.1.tgz", - "integrity": "sha512-4k54zM7lNtz37FSgNstoGlRSqN9kO1y98Lz7+8RXAoOtYe1McIUyJYhuukOFJi6XshEQDFHaxz/zklZJFqLq/g==", + "version": "1.53.2", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.53.2.tgz", + "integrity": "sha512-jGt2jUKu5hyscy6HKMpNIeqwI9lFZc23Cgaj/drbmobMsMLWMnsa0FKE17jPKsTkR7+BNzi37CvZ84Y6J4KpAA==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.1" + "data-structure-typed": "^1.53.2" } }, "node_modules/babel-jest": { @@ -3602,13 +3602,13 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.53.1.tgz", - "integrity": "sha512-Ym/VfNG8iRhBUxxlCFArQSbf46m39voLVXdKbLzP/G3Sb3N7xwSwMTRC2Evx9lEWnhMmg4WHXsqZByun2xIljw==", + "version": "1.53.2", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.53.2.tgz", + "integrity": "sha512-1cxBo5XvlCaBWn9TchqWBO8r7M2rUdLnX9b1BGH5+rs9Ch6zKJejVLEVjpwwg7PtUvUC2wB0NHpQRcXWReZ2Hg==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.1" + "data-structure-typed": "^1.53.2" } }, "node_modules/brace-expansion": { @@ -3691,13 +3691,13 @@ } }, "node_modules/bst-typed": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.53.1.tgz", - "integrity": "sha512-pSAIStgqneF4kTbbJJU7tcTMUBvchUXoID9fpKmcpsLHzG0jgfmMnGYZBZlRQXYJkUAsiFHeDaDMbK6W2muBQA==", + "version": "1.53.2", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.53.2.tgz", + "integrity": "sha512-TYQDT2/6hBUzNKvw8cylT+FBu3s0MZW0JhoibDg2u65XdsOL79WOvGtEVFJOWhRmDe6yjJLnZWz+iIpOtpkSjw==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.1" + "data-structure-typed": "^1.53.2" } }, "node_modules/buffer-from": { @@ -4069,9 +4069,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.53.1.tgz", - "integrity": "sha512-D3KDDnf6zY7vW45ht/U467UCVx1Zs6E3uVlGe4HSa+qvMHtPZMZahU5X8HbQVfzHZ1wg7NBKW6OtQdy0YzbuSQ==", + "version": "1.53.2", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.53.2.tgz", + "integrity": "sha512-TOPCOnFk3JPYiAdMJ+3VXRq4YR7MWtuZZzQJilV4lsBxlc1d50CA1kisic0YikKri3TT3YRmzRjaFfRAJh6big==", "dev": true, "license": "MIT" }, @@ -5946,13 +5946,13 @@ } }, "node_modules/heap-typed": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.53.1.tgz", - "integrity": "sha512-4/fHFXV3YLC0wvi+H3IXTRF4t2CzU1AcaB8PZvU/vR5V7lTPHNAb9IUGj9bC1f/7tmz/3a38r1Mx0xJVPIhzaw==", + "version": "1.53.2", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.53.2.tgz", + "integrity": "sha512-5aT12YbIeXyD6uJ0SEpDNUqQCfp8058ynQBhhzEQWOQEh1pfCVN50oIQmXde7CWzZTVTr3IMTxIUWAvdFIAYyQ==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.1" + "data-structure-typed": "^1.53.2" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index 2e4d911..461800d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.53.3", + "version": "1.53.4", "description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", @@ -70,11 +70,11 @@ "@typescript-eslint/eslint-plugin": "^8.12.1", "@typescript-eslint/parser": "^8.12.1", "auto-changelog": "^2.5.0", - "avl-tree-typed": "^1.53.1", + "avl-tree-typed": "^1.53.2", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.53.1", - "bst-typed": "^1.53.1", - "data-structure-typed": "^1.53.1", + "binary-tree-typed": "^1.53.2", + "bst-typed": "^1.53.2", + "data-structure-typed": "^1.53.2", "dependency-cruiser": "^16.5.0", "doctoc": "^2.2.1", "eslint": "^9.13.0", @@ -83,7 +83,7 @@ "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "fast-glob": "^3.3.2", - "heap-typed": "^1.53.1", + "heap-typed": "^1.53.2", "istanbul-badges-readme": "^1.9.0", "jest": "^29.7.0", "js-sdsl": "^4.4.2", diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts index bb2a157..09765d4 100644 --- a/src/data-structures/linked-list/doubly-linked-list.ts +++ b/src/data-structures/linked-list/doubly-linked-list.ts @@ -353,8 +353,8 @@ export class DoublyLinkedListNode { * cache.set('c', 3); * cache.set('d', 4); // This will eliminate 'a' * - * console.log(cache.get('a')).toBeUndefined(); - * expect(cache.get('b')); // 2 + * console.log(cache.get('a')); // undefined + * console.log(cache.get('b')); // 2 * console.log(cache.get('c')); // 3 * console.log(cache.get('d')); // 4 * @@ -368,8 +368,8 @@ export class DoublyLinkedListNode { * cache.set('d', 4); // This will eliminate 'b' * * console.log(cache.get('a')); // 1 - * console.log(cache.get('b')).toBeUndefined(); - * expect(cache.get('c')); // 3 + * console.log(cache.get('b')); // undefined + * console.log(cache.get('c')); // 3 * console.log(cache.get('d')); // 4 * * // Should support updating existing keys @@ -385,8 +385,8 @@ export class DoublyLinkedListNode { * cache.set('b', 2); * * console.log(cache.delete('a')); // true - * console.log(cache.get('a')).toBeUndefined(); - * expect(cache.size); // 1 + * console.log(cache.get('a')); // undefined + * console.log(cache.size); // 1 * * // Should support clearing cache * cache.clear(); @@ -431,11 +431,11 @@ export class DoublyLinkedListNode { * * // 3. Find first lyric when timestamp is less than first entry * const earlyTimeLyric = lyricsList.findBackward(lyric => lyric.time <= -1000); - * console.log(earlyTimeLyric).toBeUndefined(); + * console.log(earlyTimeLyric); // undefined * * // 4. Find last lyric when timestamp is after last entry * const lateTimeLyric = lyricsList.findBackward(lyric => lyric.time <= 50000); - * expect(lateTimeLyric?.text); // 'And I will try to fix you' + * console.log(lateTimeLyric?.text); // 'And I will try to fix you' * @example * // cpu process schedules * class Process { diff --git a/testToExample.ts b/testToExample.ts index 57d46e7..2208d93 100644 --- a/testToExample.ts +++ b/testToExample.ts @@ -59,13 +59,6 @@ function extractExamplesFromFile(filePath: string): { name: string; body: string } const transformedBody = exampleBody - .replace( - /expect\((.*?)\)\.(toEqual|toBe|toStrictEqual|toHaveLength|toMatchObject)\((.*?)\);/gs, // Use `s` flag for multiline - (match, actual, method, expected) => { - expected = expected.replace(/\n/g, '\n //') - return `console.log(${actual}); // ${expected}`; - } - ) .replace( /expect\((.*?)\)\.(toBeUndefined|toBeNull)\(\);/g, (match, actual, method) => { @@ -73,6 +66,13 @@ function extractExamplesFromFile(filePath: string): { name: string; body: string return `console.log(${actual}); // ${expectedValue}`; } ) + .replace( + /expect\((.*?)\)\.(toEqual|toBe|toStrictEqual|toHaveLength|toMatchObject)\((.*?)\);/gs, // Use `s` flag for multiline + (match, actual, method, expected) => { + expected = expected.replace(/\n/g, '\n //') + return `console.log(${actual}); // ${expected}`; + } + ) .trim(); examples.push({ name: exampleName, body: transformedBody });