mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-10-31 13:34:12 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| /*
 | |
|  * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
 | |
|  * SPDX-License-Identifier: AGPL-3.0-only
 | |
|  */
 | |
| 
 | |
| import { diffArrays } from '@/misc/diff-arrays.js';
 | |
| 
 | |
| describe(diffArrays, () => {
 | |
| 	it('should return empty result when both inputs are null', () => {
 | |
| 		const result = diffArrays(null, null);
 | |
| 		expect(result.added).toHaveLength(0);
 | |
| 		expect(result.removed).toHaveLength(0);
 | |
| 	});
 | |
| 
 | |
| 	it('should return empty result when both inputs are empty', () => {
 | |
| 		const result = diffArrays([], []);
 | |
| 		expect(result.added).toHaveLength(0);
 | |
| 		expect(result.removed).toHaveLength(0);
 | |
| 	});
 | |
| 
 | |
| 	it('should remove before when added is empty', () => {
 | |
| 		const result = diffArrays([1, 2, 3], []);
 | |
| 		expect(result.added).toHaveLength(0);
 | |
| 		expect(result.removed).toEqual([1, 2, 3]);
 | |
| 	});
 | |
| 
 | |
| 	it('should deduplicate before when added is empty', () => {
 | |
| 		const result = diffArrays([1, 1, 2, 2, 3], []);
 | |
| 		expect(result.added).toHaveLength(0);
 | |
| 		expect(result.removed).toEqual([1, 2, 3]);
 | |
| 	});
 | |
| 
 | |
| 	it('should remove after when before is empty', () => {
 | |
| 		const result = diffArrays([], [1, 2, 3]);
 | |
| 		expect(result.added).toEqual([1, 2, 3]);
 | |
| 		expect(result.removed).toHaveLength(0);
 | |
| 	});
 | |
| 
 | |
| 	it('should deduplicate after when before is empty', () => {
 | |
| 		const result = diffArrays([], [1, 1, 2, 2, 3]);
 | |
| 		expect(result.added).toEqual([1, 2, 3]);
 | |
| 		expect(result.removed).toHaveLength(0);
 | |
| 	});
 | |
| 
 | |
| 	it('should return diff when both have values', () => {
 | |
| 		const result = diffArrays(
 | |
| 			['a', 'b', 'c', 'd'],
 | |
| 			['a', 'c', 'e', 'f'],
 | |
| 		);
 | |
| 		expect(result.added).toEqual(['e', 'f']);
 | |
| 		expect(result.removed).toEqual(['b', 'd']);
 | |
| 	});
 | |
| });
 |