Skip to content

Commit 539d3ba

Browse files
rpedelabrianc
rpedela
authored andcommitted
Move string escaping tests to proper locations.
1 parent ffe51c2 commit 539d3ba

File tree

4 files changed

+306
-233
lines changed

4 files changed

+306
-233
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
var helper = require(__dirname + '/test-helper');
2+
3+
function createClient(callback) {
4+
var client = new Client(helper.config);
5+
client.connect(function(err) {
6+
return callback(client);
7+
});
8+
}
9+
10+
test('escapeLiteral: no special characters', function() {
11+
createClient(function(client) {
12+
var expected = "'hello world'";
13+
var actual = client.escapeLiteral('hello world');
14+
assert.equal(expected, actual);
15+
client.end();
16+
});
17+
});
18+
19+
test('escapeLiteral: contains double quotes only', function() {
20+
createClient(function(client) {
21+
var expected = "'hello \" world'";
22+
var actual = client.escapeLiteral('hello " world');
23+
assert.equal(expected, actual);
24+
client.end();
25+
});
26+
});
27+
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+
});
36+
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+
});
45+
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+
});
54+
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+
});
63+
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+
});
72+
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+
});
81+
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+
});
90+
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+
});
99+
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+
});
108+
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+
});
117+
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+
});
126+
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+
});
136+
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+
});
145+
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+
});

test/native/escape-tests.js

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)