hstore.test.js
3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* jshint camelcase: false */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, dialect = Support.getTestDialect()
, hstore = require("../../lib/dialects/postgres/hstore")
chai.config.includeStack = true
if (dialect.match(/^postgres/)) {
describe('[POSTGRES Specific] hstore', function() {
describe('stringify', function() {
it('should handle empty objects correctly', function(done) {
expect(hstore.stringify({ })).to.equal('')
done()
})
it('should handle null values correctly', function(done) {
expect(hstore.stringify({ null: null })).to.equal('"null"=>NULL')
done()
})
it('should handle null values correctly', function(done) {
expect(hstore.stringify({ foo: null })).to.equal('"foo"=>NULL')
done()
})
it('should handle empty string correctly', function(done) {
expect(hstore.stringify({foo : ""})).to.equal('"foo"=>\"\"')
done()
})
it('should handle a string with backslashes correctly', function(done) {
expect(hstore.stringify({foo : "\\"})).to.equal('"foo"=>"\\\\"')
done()
})
it('should handle a string with double quotes correctly', function(done) {
expect(hstore.stringify({foo : '""a"'})).to.equal('"foo"=>"\\"\\"a\\""')
done()
})
it('should handle a string with single quotes correctly', function(done) {
expect(hstore.stringify({foo : "''a'"})).to.equal('"foo"=>"\'\'\'\'a\'\'"')
done()
})
it('should handle simple objects correctly', function(done) {
expect(hstore.stringify({ test: 'value' })).to.equal('"test"=>"value"')
done()
})
})
describe('parse', function() {
it('should handle a null object correctly', function(done) {
expect(hstore.parse(null)).to.deep.equal(null)
done()
})
it('should handle empty string correctly', function(done) {
expect(hstore.parse('"foo"=>\"\"')).to.deep.equal({foo : ""})
done()
})
it('should handle a string with double quotes correctly', function(done) {
expect(hstore.parse('"foo"=>"\\\"\\\"a\\\""')).to.deep.equal({foo : "\"\"a\""})
done()
})
it('should handle a string with single quotes correctly', function(done) {
expect(hstore.parse('"foo"=>"\'\'\'\'a\'\'"')).to.deep.equal({foo : "''a'"})
done()
})
it('should handle a string with backslashes correctly', function(done) {
expect(hstore.parse('"foo"=>"\\\\"')).to.deep.equal({foo : "\\"})
done()
})
it('should handle empty objects correctly', function(done) {
expect(hstore.parse('')).to.deep.equal({ })
done()
})
it('should handle simple objects correctly', function(done) {
expect(hstore.parse('"test"=>"value"')).to.deep.equal({ test: 'value' })
done()
})
})
describe('stringify and parse', function() {
it('should stringify then parse back the same structure', function(done){
var testObj = {foo : "bar", count : "1", emptyString : "", quotyString : '""', extraQuotyString : '"""a"""""', backslashes : '\\f023', moreBackslashes : '\\f\\0\\2\\1', backslashesAndQuotes : '\\"\\"uhoh"\\"', nully : null};
expect(hstore.parse(hstore.stringify(testObj))).to.deep.equal(testObj);
expect(hstore.parse(hstore.stringify(hstore.parse(hstore.stringify(testObj))))).to.deep.equal(testObj);
done()
})
})
})
}