1// Copyright (C) 2019 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 {splitIfTooBig} from './flamegraph';
16
17test('textGoingToMultipleLines', () => {
18  const text = 'Dummy text to go to multiple lines.';
19
20  const lineSplitter = splitIfTooBig(text, 7 + 32, text.length);
21
22  expect(lineSplitter).toEqual({
23    lines: ['Dummy t', 'ext to ', 'go to m', 'ultiple', ' lines.'],
24    lineWidth: 7
25  });
26});
27
28test('emptyText', () => {
29  const text = '';
30
31  const lineSplitter = splitIfTooBig(text, 10, 5);
32
33  expect(lineSplitter).toEqual({lines: [], lineWidth: 5});
34});
35
36test('textEnoughForOneLine', () => {
37  const text = 'Dummy text to go to one lines.';
38
39  const lineSplitter = splitIfTooBig(text, text.length + 32, text.length);
40
41  expect(lineSplitter).toEqual({lines: [text], lineWidth: text.length});
42});
43
44test('textGoingToTwoLines', () => {
45  const text = 'Dummy text to go to two lines.';
46
47  const lineSplitter = splitIfTooBig(text, text.length / 2 + 32, text.length);
48
49  expect(lineSplitter).toEqual({
50    lines: ['Dummy text to g', 'o to two lines.'],
51    lineWidth: text.length / 2
52  });
53});
54