• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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 {getSliceId, isSliceish} from './query_table';
16
17describe('getSliceId', () => {
18  test('get slice_id if present when no other clues are available', () => {
19    expect(getSliceId({})).toBe(undefined);
20    expect(getSliceId({id: 123})).toBe(undefined);
21    expect(getSliceId({slice_id: 456})).toBe(456);
22    expect(getSliceId({id: 123, slice_id: 456})).toBe(456);
23
24    expect(getSliceId({type: 'foo'})).toBe(undefined);
25    expect(getSliceId({type: 'foo', id: 123})).toBe(undefined);
26    expect(getSliceId({type: 'foo', slice_id: 456})).toBe(456);
27    expect(getSliceId({type: 'foo', id: 123, slice_id: 456})).toBe(456);
28  });
29
30  test('get id if present when row looks like a slice', () => {
31    expect(getSliceId({type: 'slice'})).toBe(undefined);
32    expect(getSliceId({type: 'slice', id: 123})).toBe(123);
33    expect(getSliceId({type: 'slice', slice_id: 456})).toBe(undefined);
34    expect(getSliceId({type: 'slice', id: 123, slice_id: 456})).toBe(123);
35  });
36});
37
38test('isSliceish', () => {
39  expect(isSliceish({})).toBeFalsy();
40  expect(isSliceish({ts: 123, dur: 456})).toBeFalsy();
41  expect(isSliceish({ts: 123, dur: 456, track_id: 798})).toBeTruthy();
42  expect(isSliceish({ts: 123n, dur: 456n})).toBeFalsy();
43  expect(isSliceish({ts: 123n, dur: 456n, track_id: 798n})).toBeTruthy();
44  expect(isSliceish({ts: 123.4, dur: 456.7, track_id: 798.9})).toBeFalsy();
45  expect(isSliceish({ts: '123', dur: '456', track_id: '789'})).toBeFalsy();
46});
47