• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {cropText} from './canvas_utils';
16
17test('cropHelper regular text', () => {
18  const tripleDot = '\u2026';
19  const emoji = '\uD83D\uDE00';
20  expect(
21    cropText(
22      'com.android.camera [4096]',
23      /* charWidth=*/ 5,
24      /* rectWidth=*/ 2 * 5,
25    ),
26  ).toBe('c');
27  expect(cropText('com.android.camera [4096]', 5, 4 * 5 + 2)).toBe(
28    'co' + tripleDot,
29  );
30  expect(cropText('com.android.camera [4096]', 5, 5 * 5 + 2)).toBe(
31    'com' + tripleDot,
32  );
33  expect(cropText('com.android.camera [4096]', 5, 13 * 5 + 2)).toBe(
34    'com.android' + tripleDot,
35  );
36  expect(cropText('com.android.camera [4096]', 5, 26 * 5 + 2)).toBe(
37    'com.android.camera [4096]',
38  );
39  expect(cropText(emoji + 'abc', 5, 2 * 5)).toBe(emoji);
40  expect(cropText(emoji + 'abc', 5, 5 * 5)).toBe(emoji + 'a' + tripleDot);
41});
42