@@ -111,4 +111,76 @@ describe("Exhaustive postcode test", function () {
111111 done ( ) ;
112112 } ) ;
113113 } ) ;
114- } ) ;
114+ describe ( "Area parsing" , function ( ) {
115+ it ( "should return the correct area" , function ( done ) {
116+ this . timeout ( 60000 ) ;
117+ testData . forEach ( function ( testPostcode ) {
118+ var pc = testPostcode [ 0 ] ,
119+ postcode = new Postcode ( pc ) ,
120+ downcasePostcode = new Postcode ( pc . toLowerCase ( ) ) ,
121+ unspacedPostcode = new Postcode ( pc . replace ( / \s / , "" ) ) ,
122+ testArea ;
123+ if ( pc . length === 7 ) {
124+ // Since this isn't normalised in dataset, best we can do is see if normalised data matches
125+ assert . equal ( postcode . area ( ) , downcasePostcode . area ( ) ) ;
126+ assert . equal ( postcode . area ( ) , unspacedPostcode . area ( ) ) ;
127+ } else {
128+ // Any space indicates incode/outcode
129+ testArea = pc . match ( / \s .* / ) [ 0 ] . replace ( / \s / , "" ) ;
130+ assert . equal ( postcode . area ( ) , testArea ) ;
131+ assert . equal ( downcasePostcode . area ( ) , testArea ) ;
132+ assert . equal ( unspacedPostcode . area ( ) , testArea ) ;
133+ }
134+ } ) ;
135+ done ( ) ;
136+ } ) ;
137+ } ) ;
138+ describe ( "Sector parsing" , function ( ) {
139+ it ( "should return the correct sector" , function ( done ) {
140+ this . timeout ( 60000 ) ;
141+ testData . forEach ( function ( testPostcode ) {
142+ var pc = testPostcode [ 0 ] ,
143+ postcode = new Postcode ( pc ) ,
144+ downcasePostcode = new Postcode ( pc . toLowerCase ( ) ) ,
145+ unspacedPostcode = new Postcode ( pc . replace ( / \s / , "" ) ) ,
146+ testSector ;
147+ if ( pc . length === 7 ) {
148+ // Since this isn't normalised in dataset, best we can do is see if normalised data matches
149+ assert . equal ( postcode . sector ( ) , downcasePostcode . sector ( ) ) ;
150+ assert . equal ( postcode . sector ( ) , unspacedPostcode . sector ( ) ) ;
151+ } else {
152+ // Any space indicates incode/outcode
153+ testSector = pc . match ( / \s .* / ) [ 0 ] . replace ( / \s / , "" ) ;
154+ assert . equal ( postcode . sector ( ) , testSector ) ;
155+ assert . equal ( downcasePostcode . sector ( ) , testSector ) ;
156+ assert . equal ( unspacedPostcode . sector ( ) , testSector ) ;
157+ }
158+ } ) ;
159+ done ( ) ;
160+ } ) ;
161+ } ) ;
162+ describe ( "Unit parsing" , function ( ) {
163+ it ( "should return the correct unit" , function ( done ) {
164+ this . timeout ( 60000 ) ;
165+ testData . forEach ( function ( testPostcode ) {
166+ var pc = testPostcode [ 0 ] ,
167+ postcode = new Postcode ( pc ) ,
168+ downcasePostcode = new Postcode ( pc . toLowerCase ( ) ) ,
169+ unspacedPostcode = new Postcode ( pc . replace ( / \s / , "" ) ) ,
170+ testUnit ;
171+ if ( pc . length === 7 ) {
172+ // Since this isn't normalised in dataset, best we can do is see if normalised data matches
173+ assert . equal ( postcode . unit ( ) , downcasePostcode . unit ( ) ) ;
174+ assert . equal ( postcode . unit ( ) , unspacedPostcode . unit ( ) ) ;
175+ } else {
176+ // Any space indicates incode/outcode
177+ testUnit = pc . match ( / \s .* / ) [ 0 ] . replace ( / \s / , "" ) ;
178+ assert . equal ( postcode . unit ( ) , testUnit ) ;
179+ assert . equal ( downcasePostcode . unit ( ) , testUnit ) ;
180+ assert . equal ( unspacedPostcode . unit ( ) , testUnit ) ;
181+ }
182+ } ) ;
183+ done ( ) ;
184+ } ) ;
185+ } ) ;
186+ } ) ;
0 commit comments