tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_addressComponent_postal_code.js (1777B)


      1 "use strict";
      2 
      3 const VALID_TESTS = [
      4  { region: "US" },
      5  ["1234", false], // too short
      6  ["12345", true],
      7  ["123456", false], // too long
      8  ["1234A", false], // contain non-digit character
      9  ["12345-123", false],
     10  ["12345-1234", true],
     11  ["12345-12345", false],
     12  ["12345-1234A", false],
     13  ["12345 1234", true], // Do we want to allow this?
     14  ["12345_1234", false], // Do we want to allow this?
     15 
     16  { region: "CA" },
     17  ["M5T 1R5", true],
     18  ["M5T1R5", true], // no space between the first and second parts is allowed
     19  ["S4S 6X3", true],
     20  ["M5T", false], // Only the first part
     21  ["1R5", false], // Only the second part
     22  ["D1B 1A1", false], // invalid first character, D
     23  ["M5T 1R5A", false], // extra character at the end
     24  ["M5T 1R5-", false], // extra character at the end
     25  ["M5T-1R5", false], // hyphen in the wrong place
     26  ["MT5 1R5", false], // missing letter in the first part
     27  ["M5T 1R", false], // missing letter in the second part
     28  ["M5T 1R55", false], // extra digit at the end
     29  ["M5T 1R", false], // missing digit in the second part
     30  ["M5T 1R5Q", false], // invalid second-to-last letter, Q
     31 ];
     32 
     33 const COMPARE_TESTS = [
     34  { region: "US" },
     35  ["12345", "12345", SAME],
     36  ["M5T 1R5", "m5t 1r5", SAME],
     37  ["12345-1234", "12345 1234", SAME],
     38  ["12345-1234", "12345", A_CONTAINS_B],
     39  ["12345-1234", "12345#1234", SAME], // B is invalid
     40  ["12345-1234", "1234", A_CONTAINS_B], // B is invalid
     41 ];
     42 
     43 const TEST_FIELD_NAME = "postal-code";
     44 
     45 add_setup(async () => {});
     46 
     47 add_task(async function test_isValid() {
     48  runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => {
     49    return { "postal-code": value };
     50  });
     51 });
     52 
     53 add_task(async function test_compare() {
     54  runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => {
     55    return { "postal-code": value };
     56  });
     57 });