mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { expect, describe, it } from "vitest";
 | 
						|
import sanitizeAttributeName from "../src/services/sanitize_attribute_name";
 | 
						|
 | 
						|
// fn value, expected value
 | 
						|
const testCases: [fnValue: string, expectedValue: string][] = [
 | 
						|
    ["testName", "testName"],
 | 
						|
    ["test_name", "test_name"],
 | 
						|
    ["test with space", "test_with_space"],
 | 
						|
    ["test:with:colon", "test:with:colon"],
 | 
						|
 | 
						|
    // numbers
 | 
						|
    ["123456", "123456"],
 | 
						|
    ["123:456", "123:456"],
 | 
						|
    ["123456 abc", "123456_abc"],
 | 
						|
 | 
						|
    // non-latin characters
 | 
						|
    ["ε", "ε"],
 | 
						|
    ["attribute ε", "attribute_ε"],
 | 
						|
 | 
						|
    // special characters
 | 
						|
    ["test/name", "test_name"],
 | 
						|
    ["test%name", "test_name"],
 | 
						|
    ["\/", "_"],
 | 
						|
 | 
						|
    // empty string
 | 
						|
    ["", "unnamed"]
 | 
						|
];
 | 
						|
 | 
						|
describe("sanitizeAttributeName unit tests", () => {
 | 
						|
    testCases.forEach((testCase) => {
 | 
						|
        return it(`'${testCase[0]}' should return '${testCase[1]}'`, () => {
 | 
						|
            const [value, expected] = testCase;
 | 
						|
            const actual = sanitizeAttributeName(value);
 | 
						|
            expect(actual).toStrictEqual(expected);
 | 
						|
        });
 | 
						|
    });
 | 
						|
}); |