| 1 |
var vows = require("vows"), |
| 2 |
assert = require("assert"); |
| 3 |
|
| 4 |
var shp = require("../shp"); |
| 5 |
|
| 6 |
var suite = vows.describe("shp"); |
| 7 |
|
| 8 |
suite.addBatch({ |
| 9 |
"The header of a simple shapefile": { |
| 10 |
topic: readHeader("./test/boolean-property.shp"), |
| 11 |
"has the expected values": function(header) { |
| 12 |
assert.deepEqual(header, { |
| 13 |
fileCode: 9994, |
| 14 |
version: 1000, |
| 15 |
shapeType: 1, |
| 16 |
box: [1, 2, 17, 18] |
| 17 |
}); |
| 18 |
} |
| 19 |
}, |
| 20 |
|
| 21 |
"The header of an empty shapefile": { |
| 22 |
topic: readHeader("./test/empty.shp"), |
| 23 |
"has the expected values": function(header) { |
| 24 |
assert.deepEqual(header, { |
| 25 |
fileCode: 9994, |
| 26 |
version: 1000, |
| 27 |
shapeType: 3, |
| 28 |
box: [0, 0, 0, 0] |
| 29 |
}); |
| 30 |
} |
| 31 |
}, |
| 32 |
|
| 33 |
"The records of an empty shapefile": { |
| 34 |
topic: readRecords("./test/empty.shp"), |
| 35 |
"have the expected values": function(records) { |
| 36 |
assert.deepEqual(records, []); |
| 37 |
} |
| 38 |
}, |
| 39 |
|
| 40 |
"The records of a shapefile of points": { |
| 41 |
topic: readRecords("./test/points.shp"), |
| 42 |
"have the expected values": function(records) { |
| 43 |
assert.deepEqual(records, [ |
| 44 |
{shapeType: 1, x: 1, y: 2}, |
| 45 |
{shapeType: 1, x: 3, y: 4}, |
| 46 |
{shapeType: 1, x: 5, y: 6}, |
| 47 |
{shapeType: 1, x: 7, y: 8}, |
| 48 |
{shapeType: 1, x: 9, y: 10}, |
| 49 |
{shapeType: 1, x: 11, y: 12}, |
| 50 |
{shapeType: 1, x: 13, y: 14}, |
| 51 |
{shapeType: 1, x: 15, y: 16}, |
| 52 |
{shapeType: 1, x: 17, y: 18} |
| 53 |
]); |
| 54 |
} |
| 55 |
}, |
| 56 |
|
| 57 |
"The records of a shapefile of multipoints": { |
| 58 |
topic: readRecords("./test/multipoints.shp"), |
| 59 |
"have the expected values": function(records) { |
| 60 |
assert.deepEqual(records, [ |
| 61 |
{shapeType: 8, box: [1, 2, 9, 10], points: [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]}, |
| 62 |
{shapeType: 8, box: [11, 12, 19, 20], points: [[11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]} |
| 63 |
]); |
| 64 |
} |
| 65 |
}, |
| 66 |
|
| 67 |
"The records of a shapefile of polylines": { |
| 68 |
topic: readRecords("./test/polylines.shp"), |
| 69 |
"have the expected values": function(records) { |
| 70 |
assert.deepEqual(records, [ |
| 71 |
{shapeType: 3, box: [1, 2, 9, 10], parts: [0], points: [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]}, |
| 72 |
{shapeType: 3, box: [11, 12, 19, 20], parts: [0, 2], points: [[11, 12], [13, 14], [15, 16], [17, 18], [19, 20]]} |
| 73 |
]); |
| 74 |
} |
| 75 |
}, |
| 76 |
|
| 77 |
"The records of a shapefile of polygons": { |
| 78 |
topic: readRecords("./test/polygons.shp"), |
| 79 |
"have the expected values": function(records) { |
| 80 |
assert.deepEqual(records, [ |
| 81 |
{shapeType: 5, box: [0, 0, 1, 1], parts: [0], points: [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]}, |
| 82 |
{shapeType: 5, box: [0, 0, 4, 4], parts: [0, 5], points: [[0, 0], [0, 4], [4, 4], [4, 0], [0, 0], [1, 1], [3, 1], [3, 3], [1, 3], [1, 1]]}, |
| 83 |
{shapeType: 5, box: [2, 2, 5, 5], parts: [0, 5], points: [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2], [4, 4], [4, 5], [5, 5], [5, 4], [4, 4]]} |
| 84 |
]); |
| 85 |
} |
| 86 |
}, |
| 87 |
|
| 88 |
"The records of a shapefile with null features": { |
| 89 |
topic: readRecords("./test/null.shp"), |
| 90 |
"have the expected values": function(records) { |
| 91 |
assert.deepEqual(records, [ |
| 92 |
{shapeType: 1, x: 1, y: 2}, |
| 93 |
null, |
| 94 |
{shapeType: 1, x: 5, y: 6}, |
| 95 |
null, |
| 96 |
null, |
| 97 |
{shapeType: 1, x: 11, y: 12}, |
| 98 |
{shapeType: 1, x: 13, y: 14}, |
| 99 |
null, |
| 100 |
{shapeType: 1, x: 17, y: 18} |
| 101 |
]); |
| 102 |
} |
| 103 |
} |
| 104 |
}); |
| 105 |
|
| 106 |
function readHeader(path, encoding) { |
| 107 |
return function() { |
| 108 |
var callback = this.callback; |
| 109 |
shp.read(path, encoding, function(error, header, records) { |
| 110 |
callback(error, header); |
| 111 |
}); |
| 112 |
}; |
| 113 |
} |
| 114 |
|
| 115 |
function readRecords(path, encoding) { |
| 116 |
return function() { |
| 117 |
var callback = this.callback; |
| 118 |
shp.read(path, encoding, function(error, header, records) { |
| 119 |
callback(error, records); |
| 120 |
}); |
| 121 |
}; |
| 122 |
} |
| 123 |
|
| 124 |
suite.export(module); |