From d798388026798ab99211da9eabe86c7a7f7facb4 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 2 Jan 2025 18:16:13 +0100 Subject: [PATCH] test(sanitizeAttributeNames): add basic test --- spec-es6/sanitize_attribute_name.spec.ts | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec-es6/sanitize_attribute_name.spec.ts diff --git a/spec-es6/sanitize_attribute_name.spec.ts b/spec-es6/sanitize_attribute_name.spec.ts new file mode 100644 index 000000000..fa01a4690 --- /dev/null +++ b/spec-es6/sanitize_attribute_name.spec.ts @@ -0,0 +1,43 @@ +import sanitizeAttributeName from "../src/services/sanitize_attribute_name" +import { describe, it, execute, expect } from "./mini_test"; + +// 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).toEqual(expected); + }) + }) +}) + +execute() \ No newline at end of file