tor-browser

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

test_addressComponent_name.js (4485B)


      1 "use strict";
      2 
      3 const VALID_TESTS = [
      4  ["John Doe", true],
      5  ["John O'Brian'", true],
      6  ["John O-Brian'", true],
      7  ["John Doe", true],
      8 ];
      9 
     10 // prettier-ignore
     11 const COMPARE_TESTS = [
     12  // Same
     13  ["John", "John", SAME],                             // first name
     14  ["John Doe", "John Doe", SAME],                     // first and last name
     15  ["John Middle Doe", "John Middle Doe", SAME],       // first, middle, and last name
     16  ["John Mid1 Mid2 Doe", "John Mid1 Mid2 Doe", SAME],
     17 
     18  // Same: case insenstive
     19  ["John Doe", "john doe", SAME],
     20 
     21  // Similar: whitespaces are merged
     22  ["John Doe", "John  Doe", SIMILAR],
     23 
     24  // Similar: asscent and base
     25  ["John Doe", "John Döe", SIMILAR], // asscent and base
     26 
     27  // A Contains B
     28  ["John Doe", "Doe", A_CONTAINS_B],                 // first + family name contains family name
     29  ["John Doe", "John", A_CONTAINS_B],                // first + family name contains first name
     30  ["John Middle Doe", "Doe", A_CONTAINS_B],          // [first, middle, last] contains [last]
     31  ["John Middle Doe", "John", A_CONTAINS_B],         // [first, middle, last] contains [first]
     32  ["John Middle Doe", "Middle", A_CONTAINS_B],       // [first, middle, last] contains [middle]
     33  ["John Middle Doe", "Middle Doe", A_CONTAINS_B],   // [first, middle, last] contains [middle, last]
     34  ["John Middle Doe", "John Middle", A_CONTAINS_B],  // [first, middle, last] contains [fisrt, middle]
     35  ["John Middle Doe", "John Doe", A_CONTAINS_B],        // [first, middle, last] contains [fisrt, last]
     36  ["John Mary Jane Doe", "John Doe", A_CONTAINS_B],  // [first, middle, last] contains [fisrt, last]
     37 
     38  // Different
     39  ["John Doe", "Jane Roe", DIFFERENT],
     40  ["John Doe", "Doe John", DIFFERENT],                // swap order
     41  ["John Middle Doe", "Middle John", DIFFERENT],
     42  ["John Middle Doe", "Doe Middle", DIFFERENT],
     43  ["John Doe", "John Roe.", DIFFERENT],               // different family name
     44  ["John Doe", "Jane Doe", DIFFERENT],                // different given name
     45  ["John Middle Doe", "Jane Michael Doe", DIFFERENT], // different middle name
     46 
     47  // Puncuation is either removed or replaced with white space
     48  ["John O'Brian", "John OBrian", SIMILAR],
     49  ["John O'Brian", "John O-Brian", SIMILAR],
     50  ["John O'Brian", "John O Brian", SIMILAR],
     51  ["John-Mary Doe", "JohnMary Doe", SIMILAR],
     52  ["John-Mary Doe", "John'Mary Doe", SIMILAR],
     53  ["John-Mary Doe", "John Mary Doe", SIMILAR],
     54  ["John-Mary Doe", "John Mary", A_CONTAINS_B],
     55 
     56  // Test Name Variants
     57  ["John Doe", "J. Doe", A_CONTAINS_B],               // first name to initial
     58  ["John Doe", "J. doe", A_CONTAINS_B],
     59  ["John Doe", "J. Doe", A_CONTAINS_B],               // first name to initial without '.'
     60 
     61  ["John Middle Doe", "J. Middle Doe", A_CONTAINS_B], // first name to initial, middle name unchanged
     62  ["John Middle Doe", "J. Doe", A_CONTAINS_B],        // first name to initial, no middle name
     63 
     64  ["John Middle Doe", "John M. Doe", A_CONTAINS_B],   // middle name to initial, first name unchanged
     65  ["John Middle Doe", "J. M. Doe", A_CONTAINS_B],     // first and middle name to initial
     66  ["John Middle Doe", "J M Doe", A_CONTAINS_B],       // first and middle name to initial without '.'
     67  ["John Middle Doe", "John M. Doe", A_CONTAINS_B],   // middle name with initial
     68 
     69  // Test Name Variants: multiple middle name
     70  ["John Mary Jane Doe", "J. MARY JANE Doe", A_CONTAINS_B],   // first to initial
     71  ["John Mary Jane Doe", "john. M. J. doe", A_CONTAINS_B],    // middle name to initial
     72  ["John Mary Jane Doe", "J. M. J. Doe", A_CONTAINS_B],       // first & middle name to initial
     73  ["John Mary Jane Doe", "J. M. Doe", A_CONTAINS_B],          // first & part of the middle name to initial
     74  ["John Mary Jane Doe", "John M. Doe", A_CONTAINS_B],
     75  ["John Mary Jane Doe", "J. Doe", A_CONTAINS_B],
     76 
     77  // Test Name Variants: merge initials
     78  ["John Middle Doe", "JM Doe", A_CONTAINS_B],
     79  ["John Mary Jane Doe", "JMJ. doe", A_CONTAINS_B],
     80 
     81  // Different: Don't consider the cases when family name is abbreviated
     82  ["John Middle Doe", "JMD", DIFFERENT],
     83  ["John Middle Doe", "John Middle D.", DIFFERENT],
     84  ["John Middle Doe", "J. M. D.", DIFFERENT],
     85 ];
     86 
     87 const TEST_FIELD_NAME = "name";
     88 
     89 add_setup(async () => {});
     90 
     91 add_task(async function test_isValid() {
     92  runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => {
     93    return { name: value };
     94  });
     95 });
     96 
     97 add_task(async function test_compare() {
     98  runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => {
     99    return { name: value };
    100  });
    101 });