зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1820522 - Implement heuristics to determine whether two city names are the same, different, or mergeable r=mtigley
Differential Revision: https://phabricator.services.mozilla.com/D173806
This commit is contained in:
Родитель
b129167923
Коммит
a036e89931
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
|
||||
const VALID_TESTS = [["New York City", true]];
|
||||
|
||||
const COMPARE_TESTS = [
|
||||
["New York City", "New York City", SAME],
|
||||
["New York City", "new york city", SAME],
|
||||
["New York City", "New York City", SIMILAR], // Merge whitespace
|
||||
["Happy Valley-Goose Bay", "Happy Valley Goose Bay", SIMILAR], // Replace punctuation with whitespace
|
||||
["New York City", "New York", A_CONTAINS_B],
|
||||
["New York", "NewYork", DIFFERENT],
|
||||
["New York City", "City New York", DIFFERENT],
|
||||
];
|
||||
|
||||
const TEST_FIELD_NAME = "City";
|
||||
|
||||
add_task(async function test_isValid() {
|
||||
runIsValidTest(VALID_TESTS, TEST_FIELD_NAME, value => {
|
||||
return { "address-level2": value };
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function test_compare() {
|
||||
runCompareTest(COMPARE_TESTS, TEST_FIELD_NAME, value => {
|
||||
return { "address-level2": value };
|
||||
});
|
||||
});
|
|
@ -8,6 +8,8 @@ support-files =
|
|||
../fixtures/**
|
||||
|
||||
[test_activeStatus.js]
|
||||
[test_addressComponent_city.js]
|
||||
head = head_addressComponent.js
|
||||
[test_addressComponent_country.js]
|
||||
head = head_addressComponent.js
|
||||
[test_addressComponent_email.js]
|
||||
|
|
|
@ -235,7 +235,41 @@ class PostalCode extends AddressField {}
|
|||
* City name.
|
||||
* See autocomplete="address-level1"
|
||||
*/
|
||||
class City extends AddressField {}
|
||||
class City extends AddressField {
|
||||
#city = null;
|
||||
|
||||
constructor(value, region) {
|
||||
super(value, region);
|
||||
|
||||
const options = {
|
||||
ignore_case: true,
|
||||
};
|
||||
this.#city = this.normalizeUserValue(options);
|
||||
}
|
||||
|
||||
get city() {
|
||||
return this.#city;
|
||||
}
|
||||
|
||||
equals(other) {
|
||||
return this.city == other.city;
|
||||
}
|
||||
|
||||
contains(other) {
|
||||
const options = {
|
||||
ignore_case: true,
|
||||
replace_punctuation: " ",
|
||||
merge_whitespace: true,
|
||||
};
|
||||
|
||||
const selfTokens = new Tokens(this.normalizeUserValue(options));
|
||||
const otherTokens = new Tokens(other.normalizeUserValue(options));
|
||||
|
||||
return otherTokens.isSubsetInOrder(selfTokens, (a, b) =>
|
||||
this.localeCompare(a, b)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* State.
|
||||
|
|
Загрузка…
Ссылка в новой задаче