chrome-devtools-frontend
Version:
Chrome DevTools UI
43 lines (36 loc) • 1.74 kB
text/typescript
// Copyright 2025 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as TextUtils from '../../models/text_utils/text_utils.js';
import * as Elements from './elements.js';
describe('ElementsTreeElement', () => {
describe('convertUnicodeCharsToHTMLEntities', () => {
it('converts unicode characters to HTML entities', () => {
const input = '\u2002\u2002This string has spaces\xA0\xA0and other\u202Aunicode characters\u200A.';
const expected = {
text: '  This string has spaces and other‪unicode characters .',
entityRanges: [
new TextUtils.TextRange.SourceRange(0, 6),
new TextUtils.TextRange.SourceRange(6, 6),
new TextUtils.TextRange.SourceRange(34, 6),
new TextUtils.TextRange.SourceRange(40, 6),
new TextUtils.TextRange.SourceRange(55, 8),
new TextUtils.TextRange.SourceRange(81, 8),
],
};
const result = Elements.ElementsTreeElement.convertUnicodeCharsToHTMLEntities(input);
assert.strictEqual(result.text, expected.text);
assert.deepEqual(result.entityRanges, expected.entityRanges);
});
it('returns the original string if no unicode characters are present', () => {
const input = 'ThisStringHasNoWhitespace';
const expected = {
text: 'ThisStringHasNoWhitespace',
entityRanges: [],
};
const result = Elements.ElementsTreeElement.convertUnicodeCharsToHTMLEntities(input);
assert.strictEqual(result.text, expected.text);
assert.deepEqual(result.entityRanges, expected.entityRanges);
});
});
});