nc-photos/np_string/test/string_extension_test.dart

59 lines
1.5 KiB
Dart
Raw Normal View History

2023-08-25 18:37:17 +02:00
import 'package:np_string/src/string_extension.dart';
2023-02-20 15:21:57 +01:00
import 'package:test/test.dart';
2021-04-19 19:39:09 +02:00
void main() {
group("StringExtension", () {
test("trimLeftAny", () {
expect(".,.123.,.321.,.".trimLeftAny(".,"), "123.,.321.,.");
});
test("trimRightAny", () {
expect(".,.123.,.321.,.".trimRightAny(".,"), ".,.123.,.321");
});
test("trimAny", () {
expect(".,.123.,.321.,.".trimAny(".,"), "123.,.321");
});
2021-12-02 09:02:51 +01:00
group("slice", () {
const string = "hello world";
test("+start", () {
expect(string.slice(3), "lo world");
});
test("+start > length", () {
expect(string.slice(999), "");
});
test("+start +stop", () {
expect(string.slice(3, 5), "lo");
});
test("+start +stop > length", () {
expect(string.slice(3, 999), "lo world");
});
test("+start > +stop", () {
expect(string.slice(5, 3), "");
});
test("-start", () {
expect(string.slice(-5), "world");
});
test("-start < -length", () {
expect(string.slice(-999), "hello world");
});
test("-start -stop", () {
expect(string.slice(-5, -3), "wo");
});
test("-start -stop < -length", () {
expect(string.slice(-5, -999), "");
});
test("-start < -stop", () {
expect(string.slice(-3, -5), "");
});
test("+start -stop", () {
expect(string.slice(3, -5), "lo ");
});
test("-start +stop", () {
expect(string.slice(-5, 9), "wor");
});
});
2021-04-19 19:39:09 +02:00
});
}