-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(type-utils): add unit tests for requiresQuoting (#8691)
* test: add testCase * test: fix test case result * docs: add comment in testcase and function
- Loading branch information
1 parent
1763889
commit ba1eb20
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { requiresQuoting } from '../src'; | ||
|
||
describe('getDeclaration', () => { | ||
describe('valid identifier', () => { | ||
it('upper and lower case alphabet', () => { | ||
const name = 'c'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('upper and lower case alphabet with number not first', () => { | ||
const name = 'foo1234Bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('start with dollorSign', () => { | ||
const name = '$bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
it('include dollorSign not start position', () => { | ||
const name = 'foo$bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('start with underScore', () => { | ||
const name = '_bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
it('include underScore not start position', () => { | ||
const name = 'foo_bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('non-alphabet characters', () => { | ||
const name = 'café'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('invalid identifier', () => { | ||
// This test case is written because it is possible to access object properties, but dot annotation is not accessible. | ||
it('only number', () => { | ||
const name = '12345'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(true); | ||
}); | ||
it('start with number', () => { | ||
const name = '1axcef'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(true); | ||
}); | ||
it('start with dash', () => { | ||
const name = '-bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(true); | ||
}); | ||
it('include dash not start position', () => { | ||
const name = 'foo-bar'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(true); | ||
}); | ||
it('empty string', () => { | ||
const name = ''; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(true); | ||
}); | ||
it('include special symbol at first', () => { | ||
const name = '!asdfs'; | ||
const result = requiresQuoting(name); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('include special symbol at middle', () => { | ||
const name = 'asd!fs'; | ||
const result = requiresQuoting(name); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); |