nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

test_search_coordinates.js (6731B)


      1 import {CoordinatesProvider} from '~/lib/leaflet.control.search/providers/coordinates';
      2 
      3 const coords = new CoordinatesProvider();
      4 
      5 suite('CoordinatesProvider - parse good coordinates');
      6 [
      7     // Well formatted
      8     ['55 37', ['55° 37°', '37° 55°']],
      9     ['55° 55°', ['55° 55°']],
     10     ['55.94920° 36.82205°', ['55.9492° 36.82205°', '36.82205° 55.9492°']],
     11     ['N 55.93382° E 36.93604°', ['N 55.93382° E 36.93604°']],
     12     ['N 55°52.981′ E 36°59.540′', ['N 55°52.981′ E 36°59.54′']],
     13     ['N 55°49′02.95″ E 37°03′09.95″', ['N 55°49′2.95″ E 37°3′9.95″']],
     14     ['-55° 37°', ['-55° 37°', '37° -55°']],
     15     ['-55.94920 36.82205', ['-55.9492° 36.82205°', '36.82205° -55.9492°']],
     16     ['S 55.93382° E 36.93604°', ['S 55.93382° E 36.93604°']],
     17     ['S 55°52.981′ E 36°59.540′', ['S 55°52.981′ E 36°59.54′']],
     18     ['S 55°49′02.95″ E 37°03′09.95″', ['S 55°49′2.95″ E 37°3′9.95″']],
     19     ['55° -37°', ['55° -37°', '-37° 55°']],
     20     ['55.94920 -36.82205', ['55.9492° -36.82205°', '-36.82205° 55.9492°']],
     21     ['N 55.93382° W 36.93604°', ['N 55.93382° W 36.93604°']],
     22     ['N 55°52.981′ W 36°59.540′', ['N 55°52.981′ W 36°59.54′']],
     23     ['N 55°49′02.95″ W 37°03′09.95″', ['N 55°49′2.95″ W 37°3′9.95″']],
     24 
     25     // swap lat/lon
     26     ['S 1 2 3 E 4 5 6', ['S 1°2′3″ E 4°5′6″']],
     27     ['E 1 2 3 S 4 5 6', ['S 4°5′6″ E 1°2′3″']],
     28     ['N 1 2 E 4 5', ['N 1°2′ E 4°5′']],
     29     ['E 1 2 N 4 5', ['N 4°5′ E 1°2′']],
     30     ['N 1 E 4', ['N 1° E 4°']],
     31     ['E 1 N 4', ['N 4° E 1°']],
     32 
     33     // minimal whitespaces, placing hemispheres
     34     ['N55.93382 E36.93604', ['N 55.93382° E 36.93604°']],
     35     ['55.93382N36.93604E', ['N 55.93382° E 36.93604°']],
     36     ['N55.93382,36.93604E', ['N 55.93382° E 36.93604°']],
     37     ['S55°52.981′ W36°59.540′', ['S 55°52.981′ W 36°59.54′']],
     38     ['S55°52.981′,36°59.540′W', ['S 55°52.981′ W 36°59.54′']],
     39     ['55°52.981′S36°59.540′W', ['S 55°52.981′ W 36°59.54′']],
     40     ['36°59.540′W55°52.981′S', ['S 55°52.981′ W 36°59.54′']],
     41     ['N55°49′02.95″,W37°03′09.95″', ['N 55°49′2.95″ W 37°3′9.95″']],
     42     ['55°49′02.95″N37°03′09.95″W', ['N 55°49′2.95″ W 37°3′9.95″']],
     43     ['N55°49′02.95″,37°03′09.95″W', ['N 55°49′2.95″ W 37°3′9.95″']],
     44 
     45     // types of hemispheres
     46     ['s 55.93382 w 36.93604', ['S 55.93382° W 36.93604°']],
     47     ['55.93382 юш 36.93604 зд', ['S 55.93382° W 36.93604°']],
     48     ['55.93382 ю ш 36.93604 з д', ['S 55.93382° W 36.93604°']],
     49     ['55.93382 ю. ш. 36.93604 з. д.', ['S 55.93382° W 36.93604°']],
     50     ['55.93382 с.ш. 36.93604 в.д.', ['N 55.93382° E 36.93604°']],
     51     [`43°20'13"С, 42°27'24"В`, ['N 43°20′13″ E 42°27′24″']], // eslint-disable-line quotes
     52     [`43°20'13"N, 42°27'24"В`, ['N 43°20′13″ E 42°27′24″']], // eslint-disable-line quotes
     53     ["57°57'11.65''C|33°16'8.37''В", ['N 57°57′11.65″ E 33°16′8.37″']], // eslint-disable-line quotes
     54 
     55     // margin values
     56     ['0 0', ['0° 0°']],
     57     ['-0 -0', ['0° 0°']],
     58     ['N 0 E 0', ['N 0° E 0°']],
     59     ['N 0 0 E 0 0', ['N 0°0′ E 0°0′']],
     60     ['N 0 0 0 E 0 0 0', ['N 0°0′0″ E 0°0′0″']],
     61     ['90 180', ['90° 180°']],
     62     ['-90 -180', ['-90° -180°']],
     63     ['N 90 E180', ['N 90° E 180°']],
     64     ['N 89 59 E179 59', ['N 89°59′ E 179°59′']],
     65     ['N 89 59 59 E179 59 59', ['N 89°59′59″ E 179°59′59″']],
     66 
     67     // floating point
     68     ['55,2 37,6', ['55.2° 37.6°', '37.6° 55.2°']],
     69     ['N 55,93382° E 36,93604°', ['N 55.93382° E 36.93604°']],
     70     ['S 55°52,981′ E 36°59,540′', ['S 55°52.981′ E 36°59.54′']],
     71     ['S 55°49′02,95″ E 37°03′09,95″', ['S 55°49′2.95″ E 37°3′9.95″']],
     72     ['55.2,37.6', ['55.2° 37.6°', '37.6° 55.2°']],
     73 
     74     // junk
     75     ['55.94920-36.82205', ['55.9492° 36.82205°', '36.82205° 55.9492°']],
     76     ['- 55.94920- 36.82205-', ['55.9492° 36.82205°', '36.82205° 55.9492°']],
     77 
     78     ['N 43º 12 13  E 58º 14 15', ['N 43°12′13″ E 58°14′15″']],
     79     ['N 43о 12 13  E 58О 14 15', ['N 43°12′13″ E 58°14′15″']], // rus
     80     ['N 43o 12 13  E 58O 14 15', ['N 43°12′13″ E 58°14′15″']], // lat
     81 
     82     // without hemispheres
     83     ['1 2.8 3 4.9', ['N 1°2.8′ E 3°4.9′', 'N 3°4.9′ E 1°2.8′']],
     84     ['1 2 3.8 4 5 6.9', ['N 1°2′3.8″ E 4°5′6.9″', 'N 4°5′6.9″ E 1°2′3.8″']],
     85     ['1 2 1 2', ['N 1°2′ E 1°2′']],
     86     ['1 2 3 1 2 3', ['N 1°2′3″ E 1°2′3″']],
     87 ].forEach(function ([query, expectedResult]) {
     88     test(`Parse ${query}`, async function () {
     89         assert.isTrue(coords.isOurQuery(query));
     90         const result = await coords.search(query);
     91         assert.notProperty(result, 'error');
     92         assert.property(result, 'results');
     93         const titles = result.results.map((item) => item.title);
     94         assert.deepEqual(expectedResult, titles);
     95     });
     96 });
     97 
     98 suite('CoordinatesProvider - not coordinates');
     99 
    100 [
    101     '',
    102     'aaa',
    103     '111',
    104     '1.23',
    105     '-1.23',
    106     '1 a',
    107     '55 a 37',
    108     '55 37 a',
    109     'a 55 37',
    110     '55a37',
    111     '55 37a',
    112     'a55 37',
    113     '8 мая 122/43',
    114     'wee',
    115 ].forEach(function (query) {
    116     test(`Not a coordinates string ${query}`, async function () {
    117         assert.isFalse(coords.isOurQuery(query));
    118     });
    119 });
    120 
    121 suite('CoordinatesProvider - invalid coordinates');
    122 
    123 [
    124     '1 2 3',
    125     '1 2 3 4 5',
    126     'n1 2 3 e 4 5 6 w',
    127     'N 90 1 E 1 1',
    128     'N 1 1 E 180 1',
    129     'N 1 60 1 E 1 1',
    130     'N 1 1 1 E 60 1',
    131     'N 90 1 0 E 1 1 1',
    132     'N 1 1 1 E 180 1 0',
    133     '91 92',
    134     '89 181',
    135     'N 91 e 180',
    136     'N 90 e 181',
    137     'N 1 60 e 2 3',
    138     'N 1 1 e 2 60',
    139     'N 1 1 60 e 2 2 2',
    140     'N 1 1 1 e 2 2 60',
    141     '55.2,37,6',
    142     'n1 2 e 3 4 5 6',
    143     'N1 2 3 4 E 4 5 6 7',
    144     'N -1 E 2',
    145     'N 1 E -2',
    146     'N -1 2 E 3 4',
    147     'N 1 -2 E 3 4',
    148     'N 1 2 E -3 4',
    149     'N 1 2 E 3 -4',
    150     'N -1 2 3 E 4 5 6',
    151     'N 1 -2 3 E 4 5 6',
    152     'N 1 2 -3 E 4 5 6',
    153     'N 1 2 3 E -4 5 6',
    154     'N 1 2 3 E 4 -5 6',
    155     'N 1 2 3 E 4 5 -6',
    156     'N 1.1 2 3 E 4 5 6',
    157     'N 1 2.1 3 E 4 5 6',
    158     'N 1 2 3 E 4.1 5 6',
    159     'N 1 2 3 E 4 5.1 6',
    160     'N 1 2',
    161     '1 E 2',
    162     '1 2 N',
    163     'N 1 2 3 4',
    164     '1 2 E 3 4',
    165     '1 2 3 4 E',
    166     'N 1 2 3 4 5 6',
    167     '1 2 3 E 4 5 6',
    168     '1 2 3 4 5 6 E',
    169 ].forEach(function (query) {
    170     test(`Invalid coordinates ${query}`, async function () {
    171         assert.isTrue(coords.isOurQuery(query));
    172         const result = await coords.search(query);
    173         assert.notProperty(result, 'results');
    174         assert.propertyVal(result, 'error', 'Invalid coordinates');
    175     });
    176 });