1
+ /* eslint-disable @typescript-eslint/quotes */
1
2
import { randomBytes } from 'crypto' ;
2
3
import ERROR_MESSAGES from 'src/constants/error-messages' ;
3
4
import { CommandParsingError , RedirectionParsingError } from 'src/modules/cli/constants/errors' ;
@@ -20,64 +21,59 @@ import {
20
21
21
22
describe ( 'Cli helper' , ( ) => {
22
23
describe ( 'splitCliCommandLine' , ( ) => {
23
- it ( 'should correctly split simple command with args' , ( ) => {
24
- const input = 'memory usage key' ;
25
-
26
- const output = splitCliCommandLine ( input ) ;
27
-
28
- expect ( output ) . toEqual ( [ 'memory' , 'usage' , 'key' ] ) ;
29
- } ) ;
30
- it ( 'should correctly split command with special symbols in the args in the double quotes' , ( ) => {
31
- const input = 'set test "—"' ;
32
-
33
- const output = splitCliCommandLine ( input ) ;
34
- const buffer = Buffer . from ( 'e28094' , 'hex' ) ;
35
- expect ( output ) . toEqual ( [ 'set' , 'test' , buffer ] ) ;
36
- } ) ;
37
- // todo: enable after review splitCliCommandLine functionality
38
- xit ( 'should correctly split command with special symbols in the args in the single quotes' , ( ) => {
39
- const input = "set test '—'" ;
40
-
41
- const output = splitCliCommandLine ( input ) ;
42
-
43
- const buffer = Buffer . from ( 'e28094' , 'hex' ) ;
44
- expect ( output ) . toEqual ( [ 'set' , 'test' , buffer ] ) ;
45
- } ) ;
46
- it ( 'should correctly split simple command without args' , ( ) => {
47
- const input = 'info' ;
48
-
49
- const output = splitCliCommandLine ( input ) ;
50
-
51
- expect ( output ) . toEqual ( [ 'info' ] ) ;
52
- } ) ;
53
- it ( 'should correctly split command with double quotes' , ( ) => {
54
- const input = 'get "key name"' ;
55
-
56
- const output = splitCliCommandLine ( input ) ;
57
- expect ( output ) . toEqual ( [ 'get' , Buffer . from ( 'key name' ) ] ) ;
58
- } ) ;
59
- it ( 'should correctly split command with single quotes' , ( ) => {
60
- const input = "get 'key name'" ;
61
-
62
- const output = splitCliCommandLine ( input ) ;
63
-
64
- expect ( output ) . toEqual ( [ 'get' , 'key name' ] ) ;
65
- } ) ;
66
- it ( 'should correctly handle special character' , ( ) => {
67
- const input = 'set key "\\a\\b\\t\\n\\r"' ;
68
- const output = splitCliCommandLine ( input ) ;
69
-
70
- expect ( output ) . toEqual ( [
71
- 'set' ,
72
- 'key' ,
73
- Buffer . alloc ( 5 , String . fromCharCode ( 7 , 8 , 9 , 10 , 13 ) ) ,
74
- ] ) ;
75
- } ) ;
76
- it ( 'should correctly handle hexadecimal' , ( ) => {
77
- const input = 'set key "\\xac\\xed"' ;
78
- const output = splitCliCommandLine ( input ) ;
79
-
80
- expect ( output ) . toEqual ( [ 'set' , 'key' , Buffer . from ( [ 172 , 237 ] ) ] ) ;
24
+ [
25
+ {
26
+ input : 'memory usage key' ,
27
+ output : [ 'memory' , 'usage' , 'key' ] ,
28
+ } ,
29
+ {
30
+ input : 'set test "—"' ,
31
+ output : [ 'set' , 'test' , '—' ] ,
32
+ } ,
33
+ {
34
+ input : "set test '—'" ,
35
+ output : [ 'set' , 'test' , '—' ] ,
36
+ } ,
37
+ {
38
+ input : 'info' ,
39
+ output : [ 'info' ] ,
40
+ } ,
41
+ {
42
+ input : 'get "key name"' ,
43
+ output : [ 'get' , 'key name' ] ,
44
+ } ,
45
+ {
46
+ input : `get "key ' name"` ,
47
+ output : [ 'get' , `key ' name` ] ,
48
+ } ,
49
+ {
50
+ input : `get "key \\" name"` ,
51
+ output : [ 'get' , `key " name` ] ,
52
+ } ,
53
+ {
54
+ input : "get 'key name'" ,
55
+ output : [ 'get' , 'key name' ] ,
56
+ } ,
57
+ {
58
+ input : `s"et" ~\\'\\nk"k "ey' 1` ,
59
+ output : [ 'set' , `~\\\\nk"k "ey` , '1' ] ,
60
+ } ,
61
+ {
62
+ input : 'set key "\\a\\b\\t\\n\\r"' ,
63
+ output : [ 'set' , 'key' , `\u0007\u0008\u0009\n\r` ] ,
64
+ } ,
65
+ {
66
+ input : 'set key "\\xac\\xed"' ,
67
+ output : [ 'set' , 'key' , Buffer . from ( [ 172 , 237 ] ) ] ,
68
+ } ,
69
+ {
70
+ input : `ACL SETUSER t on nopass ~'\\x00' &* +@all` ,
71
+ output : [ 'ACL' , 'SETUSER' , 't' , 'on' , 'nopass' , '~\\x00' , '&*' , '+@all' ] ,
72
+ } ,
73
+ ] . forEach ( ( tc ) => {
74
+ it ( `should return ${ JSON . stringify ( tc . output ) } for command ${ tc . input } ` , async ( ) => {
75
+ expect ( splitCliCommandLine ( tc . input ) ) . toEqual ( tc . output ) ;
76
+ } ) ;
81
77
} ) ;
82
78
it ( 'should throw [CLI_INVALID_QUOTES_CLOSING] error for command with double quotes' , ( ) => {
83
79
const input = 'get "key"a' ;
0 commit comments