@@ -7,147 +7,66 @@ function createClient(callback) {
77 } ) ;
88}
99
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 ) ;
1414 assert . equal ( expected , actual ) ;
15- client . end ( ) ;
1615 } ) ;
17- } ) ;
16+ } ;
1817
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 ) ;
2322 assert . equal ( expected , actual ) ;
24- client . end ( ) ;
2523 } ) ;
26- } ) ;
24+ } ;
2725
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'" ) ;
3628
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'" ) ;
4531
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'" ) ;
5434
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'" ) ;
6337
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'" ) ;
7240
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'" ) ;
8143
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'" ) ;
9046
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'" ) ;
9949
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"' ) ;
10852
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"' ) ;
11755
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"' ) ;
12658
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"' ) ;
13661
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"' ) ;
14564
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