| 1 | "use strict"; |
| 2 | |
| 3 | var tz = require("../../moment-timezone-utils").tz; |
| 4 | |
| 5 | function compare(test, source, expected) { |
| 6 | test.equal(tz.pack(source), expected, 'should be able to pack data'); |
| 7 | |
| 8 | test.done(); |
| 9 | } |
| 10 | |
| 11 | exports.pack = { |
| 12 | single : function (test) { |
| 13 | compare(test, |
| 14 | { |
| 15 | name : "Some/Zone_Name", |
| 16 | abbrs : ["ABC", "DEF", "ABC", "DEF", "GHI", "DEF"], |
| 17 | offsets : [60, 239, 60, 239, 60, 239], |
| 18 | untils : [ |
| 19 | -4259 * 60000, |
| 20 | -4139 * 60000, |
| 21 | -3900 * 60000, |
| 22 | -3780 * 60000, |
| 23 | -3541 * 60000, |
| 24 | Infinity |
| 25 | ] |
| 26 | }, |
| 27 | "Some/Zone_Name|ABC DEF GHI|10 3X 10|010121|-1aX 20 3X 20 3X|" |
| 28 | ); |
| 29 | }, |
| 30 | |
| 31 | 'single with population' : function (test) { |
| 32 | compare(test, |
| 33 | { |
| 34 | name : "Some/Zone_Name", |
| 35 | abbrs : ["ABC", "DEF", "ABC", "DEF", "GHI", "DEF"], |
| 36 | offsets : [60, 239, 60, 239, 60, 239], |
| 37 | untils : [ |
| 38 | -4259 * 60000, |
| 39 | -4139 * 60000, |
| 40 | -3900 * 60000, |
| 41 | -3780 * 60000, |
| 42 | -3541 * 60000, |
| 43 | Infinity |
| 44 | ], |
| 45 | population : 1234567 |
| 46 | }, |
| 47 | "Some/Zone_Name|ABC DEF GHI|10 3X 10|010121|-1aX 20 3X 20 3X|12e5" |
| 48 | ); |
| 49 | }, |
| 50 | |
| 51 | 'single with population under 1000' : function (test) { |
| 52 | compare(test, |
| 53 | { |
| 54 | name : "Some/Zone_Name", |
| 55 | abbrs : ["ABC"], |
| 56 | offsets : [60], |
| 57 | untils : [Infinity], |
| 58 | population : 999 |
| 59 | }, |
| 60 | "Some/Zone_Name|ABC|10|0||999" |
| 61 | ); |
| 62 | }, |
| 63 | |
| 64 | 'single with rounded up population' : function (test) { |
| 65 | compare(test, |
| 66 | { |
| 67 | name : "Some/Zone_Name", |
| 68 | abbrs : ["ABC"], |
| 69 | offsets : [60], |
| 70 | untils : [Infinity], |
| 71 | population : 455000001 |
| 72 | }, |
| 73 | "Some/Zone_Name|ABC|10|0||46e7" |
| 74 | ); |
| 75 | }, |
| 76 | |
| 77 | errors : function (test) { |
| 78 | test.throws(function () { |
| 79 | tz.pack({ |
| 80 | abbrs : ['ABC'], |
| 81 | offsets : [60], |
| 82 | untils : [1000] |
| 83 | }); |
| 84 | }, "Packing data without a name should throw an error"); |
| 85 | |
| 86 | test.throws(function () { |
| 87 | tz.pack({ |
| 88 | name : "", |
| 89 | abbrs : ['ABC'], |
| 90 | offsets : [60], |
| 91 | untils : [1000] |
| 92 | }); |
| 93 | }, "Packing data without a name should throw an error"); |
| 94 | |
| 95 | test.throws(function () { |
| 96 | tz.pack({ |
| 97 | name : "Test/Name", |
| 98 | offsets : [60], |
| 99 | untils : [1000] |
| 100 | }); |
| 101 | }, "Packing data without abbrs should throw an error"); |
| 102 | |
| 103 | test.throws(function () { |
| 104 | tz.pack({ |
| 105 | name : "Test/Name", |
| 106 | abbrs : ["ABC"], |
| 107 | untils : [1000] |
| 108 | }); |
| 109 | }, "Packing data without offsets should throw an error"); |
| 110 | |
| 111 | test.throws(function () { |
| 112 | tz.pack({ |
| 113 | name : "Test/Name", |
| 114 | abbrs : ["ABC"], |
| 115 | offsets : [60] |
| 116 | }); |
| 117 | }, "Packing data without untils should throw an error"); |
| 118 | |
| 119 | test.throws(function () { |
| 120 | tz.pack({ |
| 121 | name : "Test/Name", |
| 122 | abbrs : ['ABC'], |
| 123 | offsets : [60, 20], |
| 124 | untils : [1000] |
| 125 | }); |
| 126 | }, "Packing data with mismatched offset length should throw an error"); |
| 127 | |
| 128 | test.throws(function () { |
| 129 | tz.pack({ |
| 130 | name : "Test/Name", |
| 131 | abbrs : ['ABC', 'DEF'], |
| 132 | offsets : [60], |
| 133 | untils : [1000] |
| 134 | }); |
| 135 | }, "Packing data with mismatched abbr length should throw an error"); |
| 136 | |
| 137 | test.throws(function () { |
| 138 | tz.pack({ |
| 139 | name : "Test/Name", |
| 140 | abbrs : ['ABC'], |
| 141 | offsets : [60], |
| 142 | untils : [1000, 2000] |
| 143 | }); |
| 144 | }, "Packing data with mismatched untils length should throw an error"); |
| 145 | |
| 146 | test.done(); |
| 147 | } |
| 148 | }; |