Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Update assertI18nContains to ignore horizontal white space in string …
Browse files Browse the repository at this point in the history
…comparison.

RELNOTES: Update assertI18nContains to ignore horizontal white space in strings.

PiperOrigin-RevId: 500759951
Change-Id: I525c081f1db28c64e48a09ec635fe73f1336ddbe
  • Loading branch information
Closure Team authored and copybara-github committed Jan 9, 2023
1 parent e25a09a commit d407e5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion closure/goog/testing/i18n/asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ goog.testing.i18n.asserts.assertI18nEquals = function(a, b, opt_c) {
/**
* Asserts that needle, or a string i18n-equivalent to needle, is a substring of
* haystack. I18n-equivalent strings are set with addI18nMapping.
* Horizontal white space is removed before comparison.
*
* @param {string} needle The substring to search for.
* @param {string} haystack The string to search within.
Expand All @@ -136,7 +137,11 @@ goog.testing.i18n.asserts.assertI18nContains = function(needle, haystack) {
return;
}

assertContains(needle, haystack);
const wsFixedNeedle = goog.testing.i18n.whitespace.removeWhitespace(needle);
const wsFixedHaystack =
goog.testing.i18n.whitespace.removeWhitespace(haystack);

assertContains(wsFixedNeedle, wsFixedHaystack);
};


Expand Down
9 changes: 9 additions & 0 deletions closure/goog/testing/i18n/asserts_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ testSuite({
assertThrowsJsUnitException(() => {
asserts.assertI18nEquals('mappedValue', '** dummy');
});

// Check for containing with horizontal space matching

asserts.assertI18nContains('abc', ' abc\u1680');
asserts.assertI18nContains('abc', '\u202fabc \u3000');
asserts.assertI18nContains('abc', '\u202fabc \u3000');
asserts.assertI18nContains('a b c', '\u202fabc \u3000');
asserts.assertI18nContains('a\u202fb\t\xA0c', '\u202fabc \u3000');

},

testMappingWorks() {
Expand Down

0 comments on commit d407e5c

Please # to comment.