• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {StringUtils} from './string_utils';
18
19describe('StringUtils', () => {
20  it('parses bigint', () => {
21    expect(StringUtils.parseBigIntStrippingUnit('-10')).toEqual(-10n);
22    expect(StringUtils.parseBigIntStrippingUnit('-10 unit')).toEqual(-10n);
23    expect(StringUtils.parseBigIntStrippingUnit('-10unit')).toEqual(-10n);
24    expect(StringUtils.parseBigIntStrippingUnit(' -10 unit ')).toEqual(-10n);
25
26    expect(StringUtils.parseBigIntStrippingUnit('0')).toEqual(0n);
27    expect(StringUtils.parseBigIntStrippingUnit('0 unit')).toEqual(0n);
28    expect(StringUtils.parseBigIntStrippingUnit('0unit')).toEqual(0n);
29    expect(StringUtils.parseBigIntStrippingUnit(' 0 unit ')).toEqual(0n);
30
31    expect(StringUtils.parseBigIntStrippingUnit('10')).toEqual(10n);
32    expect(StringUtils.parseBigIntStrippingUnit('10 unit')).toEqual(10n);
33    expect(StringUtils.parseBigIntStrippingUnit('10unit')).toEqual(10n);
34    expect(StringUtils.parseBigIntStrippingUnit(' 10 unit ')).toEqual(10n);
35
36    expect(() => StringUtils.parseBigIntStrippingUnit('invalid')).toThrow();
37    expect(() => StringUtils.parseBigIntStrippingUnit('invalid 10 unit')).toThrow();
38  });
39});
40