Skip to content

Commit

Permalink
test(sanitizeAttributeNames): add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
pano9000 committed Jan 2, 2025
1 parent 1053da3 commit d798388
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec-es6/sanitize_attribute_name.spec.ts
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d798388

Please sign in to comment.