Elizabeth Mitchell a2bb8458d2 chore(sass): move to internal
PiperOrigin-RevId: 536458468
2023-05-30 11:23:00 -07:00

201 lines
5.6 KiB
SCSS

//
// Copyright 2021 Google LLC
// SPDX-License-Identifier: Apache-2.0
//
// go/keep-sorted start
@use 'sass:list';
@use 'sass:meta';
@use 'true' as test;
// go/keep-sorted end
// go/keep-sorted start
@use '../string-ext';
// go/keep-sorted end
@include test.describe('string-ext') {
@include test.describe('has-prefix()') {
@include test.it('should return true if the string has the prefix') {
@include test.assert-true(string-ext.has-prefix('foo', 'f'));
}
@include test.it(
'should return false if the string does not have the prefix'
) {
@include test.assert-false(string-ext.has-prefix('foo', 'b'));
}
}
@include test.describe('has-suffix()') {
@include test.it('should return true if the string has the suffix') {
@include test.assert-true(string-ext.has-suffix('foo', 'o'));
}
@include test.it(
'should return false if the string does not have the suffix'
) {
@include test.assert-false(string-ext.has-suffix('foo', 'b'));
}
}
@include test.describe('trim-repeating-prefix()') {
@include test.it('should return the string with the prefix removed') {
@include test.assert-equal(
string-ext.trim-repeating-prefix('foo', 'fo'),
'o'
);
}
@include test.it(
'should return the string with a repeating prefix removed'
) {
@include test.assert-equal(
string-ext.trim-repeating-prefix('babar', 'ba'),
'r'
);
}
@include test.it('should do nothing if the prefix does not exist') {
@include test.assert-equal(
string-ext.trim-repeating-prefix('foo', 'bar'),
'foo'
);
}
}
@include test.describe('trim-prefix()') {
@include test.it('should only trim the prefix once') {
@include test.assert-equal(string-ext.trim-prefix('babar', 'ba'), 'bar');
}
}
@include test.describe('trim-repeating-suffix()') {
@include test.it('should return the string with the suffix removed') {
@include test.assert-equal(
string-ext.trim-repeating-suffix('babar', 'bar'),
'ba'
);
}
@include test.it(
'should return the string with a repeating suffix removed'
) {
@include test.assert-equal(
string-ext.trim-repeating-suffix('foo', 'o'),
'f'
);
}
@include test.it('should do nothing if the suffix does not exist') {
@include test.assert-equal(
string-ext.trim-repeating-suffix('foo', 'bar'),
'foo'
);
}
}
@include test.describe('trim-suffix()') {
@include test.it('should only trim the suffix once') {
@include test.assert-equal(string-ext.trim-suffix('foo', 'o'), 'fo');
}
}
@include test.describe('trim-repeating()') {
@include test.it('should trim the same repeating prefix and suffix') {
@include test.assert-equal(
string-ext.trim-repeating(' foo bar ', ' '),
'foo bar'
);
}
@include test.it('should trim different repeating prefixes and suffixes') {
@include test.assert-equal(
string-ext.trim-repeating('fffoo barrr', $prefix: 'f', $suffix: 'r'),
'oo ba'
);
}
}
@include test.describe('trim()') {
@include test.it('should trim the a single prefix and suffix') {
@include test.assert-equal(
string-ext.trim(' foo bar ', ' '),
' foo bar '
);
}
@include test.it('should trim different prefixes and suffixes') {
@include test.assert-equal(
string-ext.trim('fffoo barrr', $prefix: 'f', $suffix: 'r'),
'ffoo barr'
);
}
}
@include test.describe('replace()') {
@include test.it('should replace a pattern') {
@include test.assert-equal(
string-ext.replace('foo bar baz', 'foo', 'quux'),
'quux bar baz'
);
@include test.assert-equal(
string-ext.replace('foo bar baz', 'bar', 'quux'),
'foo quux baz'
);
@include test.assert-equal(
string-ext.replace('foo bar baz', 'baz', 'quux'),
'foo bar quux'
);
}
@include test.it('should return the string if pattern dont match') {
@include test.assert-equal(
string-ext.replace('foo bar baz', 'quux', 'womp'),
'foo bar baz'
);
}
@include test.it('replaces only first match') {
@include test.assert-equal(
string-ext.replace('womp womp', 'womp', 'doo'),
'doo womp'
);
}
}
@include test.describe('split()') {
@include test.it('should return a list') {
$result: string-ext.split('foo bar baz');
@include test.assert-equal(meta.type-of($result), 'list');
}
@include test.it('should return ordered substrings') {
$result: string-ext.split('foo bar baz');
$expected: (foo bar baz);
@include test.assert-equal(list.length($result), 3);
@include test.assert-equal($result, $expected);
}
@include test.it('should handle comma separated lists') {
$result: string-ext.split('foo, bar, baz');
$expected: (foo bar baz);
@include test.assert-equal(list.length($result), 3);
@include test.assert-equal($result, $expected);
}
@include test.it('should handle slash separated lists') {
$result: string-ext.split('foo/ bar/ baz');
$expected: (foo bar baz);
@include test.assert-equal(list.length($result), 3);
@include test.assert-equal($result, $expected);
}
@include test.it('should one-item list for simple strings') {
$result: string-ext.split('foo');
$expected: list.append((), foo);
@include test.assert-equal($result, $expected);
}
}
}