Skip to content

Commit 0bf10f0

Browse files
committed
test: Add test cases
- isCorrectParenthesis - getNested
1 parent 97f0701 commit 0bf10f0

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/rules/hiveTypeRules.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { getNested, isCorrectParenthesis } from './hiveTypeRules';
2+
3+
describe('Test isCorrectParenthesis function', () => {
4+
/* TRUE */
5+
it('올바른 괄호쌍', () => {
6+
expect(isCorrectParenthesis('array<int>')).toBe(true);
7+
});
8+
9+
/* FALSE */
10+
it('열고 닫히는 괄호 개수 불일치', () => {
11+
expect(isCorrectParenthesis('array<<int>')).toBe(false);
12+
});
13+
14+
it('열고 닫히는 괄호쌍 불일치', () => {
15+
expect(isCorrectParenthesis('array<varchar(10>)')).toBe(false);
16+
});
17+
18+
it('가장 바깥 괄호쌍이 여럿', () => {
19+
expect(isCorrectParenthesis('array<int><int>')).toBe(false);
20+
});
21+
});
22+
23+
describe('Test getNested function', () => {
24+
it('Nested', () => {
25+
expect(getNested('array<int>')).toBe('int');
26+
});
27+
28+
it('Nested in Nested', () => {
29+
expect(getNested('struct<tag:array<int>>')).toBe('tag:array<int>');
30+
});
31+
});

src/rules/hiveTypeRules.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const primitiveTypes = [
1919
'BINARY',
2020
];
2121

22-
const isCorrectParenthesis = (type: string) => {
22+
export const isCorrectParenthesis = (type: string) => {
2323
const openParen = [];
2424
let alreadyAllClosed = false;
2525

@@ -43,13 +43,13 @@ const isCorrectParenthesis = (type: string) => {
4343
* @param text 문자열 내에 '<'가 존재하고, 마지막 문자가 '>'인 문자열
4444
* @returns '<'와 '>' 내의 문자열을 반환
4545
*/
46-
const getNested = (text: string) => text.slice(text.indexOf('<') + 1, -1);
46+
export const getNested = (text: string) => text.slice(text.indexOf('<') + 1, -1);
4747

4848
/**
4949
* separator로 문자열을 토큰화합니다.
5050
* @description 괄호 안의 separator는 무시합니다.
5151
*/
52-
const tokenize = (types: string, separator: string) => {
52+
export const tokenize = (types: string, separator: string) => {
5353
const ret: string[] = [];
5454
let isInParenthesis = 0;
5555
types.split(separator).forEach(type => {
@@ -72,7 +72,7 @@ const tokenize = (types: string, separator: string) => {
7272
* @param colName 양끝 공백이 없는 문자열
7373
* @returns 올바른 형식의 컬럼 이름인지 여부
7474
*/
75-
const isValidColName = (colName: string): boolean => {
75+
export const isValidColName = (colName: string): boolean => {
7676
if (colName === '' || colName === '``') return false;
7777

7878
if (/[,|:|(|)|<|>|\s|]/.test(colName)) return false;
@@ -93,7 +93,7 @@ const isValidColName = (colName: string): boolean => {
9393
* 타입이 Hive 형식에 맞는지 확인합니다.
9494
* @description 이 함수는 isCorrectParenthesis()가 true임을 가정합니다.
9595
*/
96-
const checkValidDataType = (rawType: string): boolean => {
96+
export const checkValidDataType = (rawType: string): boolean => {
9797
const checkValidPrimitiveType = (type: string) =>
9898
primitiveTypes.includes(type.toUpperCase()) ||
9999
/^CHAR\s*\(\s*\d+\s*\)$/is.test(type) ||

0 commit comments

Comments
 (0)