@@ -7,147 +7,66 @@ function createClient(callback) {
7
7
} ) ;
8
8
}
9
9
10
- test ( 'escapeLiteral: no special characters' , function ( ) {
11
- createClient ( function ( client ) {
12
- var expected = "'hello world'" ;
13
- var actual = client . escapeLiteral ( 'hello world' ) ;
10
+ var testLit = function ( testName , input , expected ) {
11
+ test ( testName , function ( ) {
12
+ var client = new Client ( helper . config ) ;
13
+ var actual = client . escapeLiteral ( input ) ;
14
14
assert . equal ( expected , actual ) ;
15
- client . end ( ) ;
16
15
} ) ;
17
- } ) ;
16
+ } ;
18
17
19
- test ( 'escapeLiteral: contains double quotes only' , function ( ) {
20
- createClient ( function ( client ) {
21
- var expected = "'hello \" world'" ;
22
- var actual = client . escapeLiteral ( 'hello " world' ) ;
18
+ var testIdent = function ( testName , input , expected ) {
19
+ test ( testName , function ( ) {
20
+ var client = new Client ( helper . config ) ;
21
+ var actual = client . escapeIdentifier ( input ) ;
23
22
assert . equal ( expected , actual ) ;
24
- client . end ( ) ;
25
23
} ) ;
26
- } ) ;
24
+ } ;
27
25
28
- test ( 'escapeLiteral: contains single quotes only' , function ( ) {
29
- createClient ( function ( client ) {
30
- var expected = "'hello \'\' world'" ;
31
- var actual = client . escapeLiteral ( 'hello \' world' ) ;
32
- assert . equal ( expected , actual ) ;
33
- client . end ( ) ;
34
- } ) ;
35
- } ) ;
26
+ testLit ( 'escapeLiteral: no special characters' ,
27
+ 'hello world' , "'hello world'" ) ;
36
28
37
- test ( 'escapeLiteral: contains backslashes only' , function ( ) {
38
- createClient ( function ( client ) {
39
- var expected = " E'hello \\\\ world'" ;
40
- var actual = client . escapeLiteral ( 'hello \\ world' ) ;
41
- assert . equal ( expected , actual ) ;
42
- client . end ( ) ;
43
- } ) ;
44
- } ) ;
29
+ testLit ( 'escapeLiteral: contains double quotes only' ,
30
+ 'hello " world' , "'hello \" world'" ) ;
45
31
46
- test ( 'escapeLiteral: contains single quotes and double quotes' , function ( ) {
47
- createClient ( function ( client ) {
48
- var expected = "'hello '' \" world'" ;
49
- var actual = client . escapeLiteral ( 'hello \' " world' ) ;
50
- assert . equal ( expected , actual ) ;
51
- client . end ( ) ;
52
- } ) ;
53
- } ) ;
32
+ testLit ( 'escapeLiteral: contains single quotes only' ,
33
+ 'hello \' world' , "'hello \'\' world'" ) ;
54
34
55
- test ( 'escapeLiteral: contains double quotes and backslashes' , function ( ) {
56
- createClient ( function ( client ) {
57
- var expected = " E'hello \\\\ \" world'" ;
58
- var actual = client . escapeLiteral ( 'hello \\ " world' ) ;
59
- assert . equal ( expected , actual ) ;
60
- client . end ( ) ;
61
- } ) ;
62
- } ) ;
35
+ testLit ( 'escapeLiteral: contains backslashes only' ,
36
+ 'hello \\ world' , " E'hello \\\\ world'" ) ;
63
37
64
- test ( 'escapeLiteral: contains single quotes and backslashes' , function ( ) {
65
- createClient ( function ( client ) {
66
- var expected = " E'hello \\\\ '' world'" ;
67
- var actual = client . escapeLiteral ( 'hello \\ \' world' ) ;
68
- assert . equal ( expected , actual ) ;
69
- client . end ( ) ;
70
- } ) ;
71
- } ) ;
38
+ testLit ( 'escapeLiteral: contains single quotes and double quotes' ,
39
+ 'hello \' " world' , "'hello '' \" world'" ) ;
72
40
73
- test ( 'escapeLiteral: contains single quotes, double quotes, and backslashes' , function ( ) {
74
- createClient ( function ( client ) {
75
- var expected = " E'hello \\\\ '' \" world'" ;
76
- var actual = client . escapeLiteral ( 'hello \\ \' " world' ) ;
77
- assert . equal ( expected , actual ) ;
78
- client . end ( ) ;
79
- } ) ;
80
- } ) ;
41
+ testLit ( 'escapeLiteral: contains double quotes and backslashes' ,
42
+ 'hello \\ " world' , " E'hello \\\\ \" world'" ) ;
81
43
82
- test ( 'escapeIdentifier: no special characters' , function ( ) {
83
- createClient ( function ( client ) {
84
- var expected = '"hello world"' ;
85
- var actual = client . escapeIdentifier ( 'hello world' ) ;
86
- assert . equal ( expected , actual ) ;
87
- client . end ( ) ;
88
- } ) ;
89
- } ) ;
44
+ testLit ( 'escapeLiteral: contains single quotes and backslashes' ,
45
+ 'hello \\ \' world' , " E'hello \\\\ '' world'" ) ;
90
46
91
- test ( 'escapeIdentifier: contains double quotes only' , function ( ) {
92
- createClient ( function ( client ) {
93
- var expected = '"hello "" world"' ;
94
- var actual = client . escapeIdentifier ( 'hello " world' ) ;
95
- assert . equal ( expected , actual ) ;
96
- client . end ( ) ;
97
- } ) ;
98
- } ) ;
47
+ testLit ( 'escapeLiteral: contains single quotes, double quotes, and backslashes' ,
48
+ 'hello \\ \' " world' , " E'hello \\\\ '' \" world'" ) ;
99
49
100
- test ( 'escapeIdentifier: contains single quotes only' , function ( ) {
101
- createClient ( function ( client ) {
102
- var expected = '"hello \' world"' ;
103
- var actual = client . escapeIdentifier ( 'hello \' world' ) ;
104
- assert . equal ( expected , actual ) ;
105
- client . end ( ) ;
106
- } ) ;
107
- } ) ;
50
+ testIdent ( 'escapeIdentifier: no special characters' ,
51
+ 'hello world' , '"hello world"' ) ;
108
52
109
- test ( 'escapeIdentifier: contains backslashes only' , function ( ) {
110
- createClient ( function ( client ) {
111
- var expected = '"hello \\ world"' ;
112
- var actual = client . escapeIdentifier ( 'hello \\ world' ) ;
113
- assert . equal ( expected , actual ) ;
114
- client . end ( ) ;
115
- } ) ;
116
- } ) ;
53
+ testIdent ( 'escapeIdentifier: contains double quotes only' ,
54
+ 'hello " world' , '"hello "" world"' ) ;
117
55
118
- test ( 'escapeIdentifier: contains single quotes and double quotes' , function ( ) {
119
- createClient ( function ( client ) {
120
- var expected = '"hello \' "" world"' ;
121
- var actual = client . escapeIdentifier ( 'hello \' " world' ) ;
122
- assert . equal ( expected , actual ) ;
123
- client . end ( ) ;
124
- } ) ;
125
- } ) ;
56
+ testIdent ( 'escapeIdentifier: contains single quotes only' ,
57
+ 'hello \' world' , '"hello \' world"' ) ;
126
58
127
- test ( 'escapeIdentifier: contains double quotes and backslashes' , function ( ) {
128
- return createClient ( function ( client ) {
129
- var expected = '"hello \\ "" world"' ;
130
- var actual = client . escapeIdentifier ( 'hello \\ " world' ) ;
131
- assert . equal ( expected , actual ) ;
132
- client . end ( ) ;
133
- return ;
134
- } ) ;
135
- } ) ;
59
+ testIdent ( 'escapeIdentifier: contains backslashes only' ,
60
+ 'hello \\ world' , '"hello \\ world"' ) ;
136
61
137
- test ( 'escapeIdentifier: contains single quotes and backslashes' , function ( ) {
138
- createClient ( function ( client ) {
139
- var expected = '"hello \\ \' world"' ;
140
- var actual = client . escapeIdentifier ( 'hello \\ \' world' ) ;
141
- assert . equal ( expected , actual ) ;
142
- client . end ( ) ;
143
- } ) ;
144
- } ) ;
62
+ testIdent ( 'escapeIdentifier: contains single quotes and double quotes' ,
63
+ 'hello \' " world' , '"hello \' "" world"' ) ;
145
64
146
- test ( 'escapeIdentifier: contains single quotes, double quotes, and backslashes' , function ( ) {
147
- createClient ( function ( client ) {
148
- var expected = '"hello \\ \' "" world"' ;
149
- var actual = client . escapeIdentifier ( 'hello \\ \' " world' ) ;
150
- assert . equal ( expected , actual ) ;
151
- client . end ( ) ;
152
- } ) ;
153
- } ) ;
65
+ testIdent ( 'escapeIdentifier: contains double quotes and backslashes' ,
66
+ 'hello \\ " world' , '"hello \\ "" world"' ) ;
67
+
68
+ testIdent ( 'escapeIdentifier: contains single quotes and backslashes' ,
69
+ 'hello \\ \' world' , '"hello \\ \' world"' ) ;
70
+
71
+ testIdent ( 'escapeIdentifier: contains single quotes, double quotes, and backslashes' ,
72
+ 'hello \\ \' " world' , '"hello \\ \' "" world"' ) ;
0 commit comments