75 lines
1.8 KiB
Dart
75 lines
1.8 KiB
Dart
import "package:test/test.dart";
|
|
import "package:clawd_code/src/utils/string_utils.dart";
|
|
|
|
|
|
void main() {
|
|
group("escapeRegExp", () {
|
|
test("escapes dot and star", () {
|
|
expect(escapeRegExp("a.b*c"), equals(r"a\.b\*c"));
|
|
});
|
|
|
|
test("plain string unchanged", () {
|
|
expect(escapeRegExp("hello"), equals("hello"));
|
|
});
|
|
});
|
|
|
|
group("capitalize", () {
|
|
test("uppercases first char", () {
|
|
expect(capitalize("foo"), equals("Foo"));
|
|
});
|
|
|
|
test("empty string stays empty", () {
|
|
expect(capitalize(""), equals(""));
|
|
});
|
|
|
|
test("doesnt lowercase rest", () {
|
|
expect(capitalize("fOOBAR"), equals("FOOBAR"));
|
|
});
|
|
});
|
|
|
|
group("plural", () {
|
|
test("singular for 1", () {
|
|
expect(plural(1, "file"), equals("file"));
|
|
});
|
|
|
|
test("appends s for other counts", () {
|
|
expect(plural(3, "file"), equals("files"));
|
|
});
|
|
|
|
test("uses custom plural form", () {
|
|
expect(plural(2, "entry", "entries"), equals("entries"));
|
|
});
|
|
});
|
|
|
|
group("firstLineOf", () {
|
|
test("returns full string when no newline", () {
|
|
expect(firstLineOf("hello world"), equals("hello world"));
|
|
});
|
|
|
|
test("returns only first line", () {
|
|
expect(firstLineOf("line1\nline2\nline3"), equals("line1"));
|
|
});
|
|
});
|
|
|
|
group("countChar", () {
|
|
test("counts occurrences", () {
|
|
expect(countChar("banana", "a"), equals(3));
|
|
});
|
|
|
|
test("zero when not found", () {
|
|
expect(countChar("hello", "z"), equals(0));
|
|
});
|
|
});
|
|
|
|
group("truncate", () {
|
|
test("short string unchanged", () {
|
|
expect(truncate("hi", 10), equals("hi"));
|
|
});
|
|
|
|
test("truncates long string with ellipsis", () {
|
|
final result = truncate("hello world", 8);
|
|
expect(result.length, lessThanOrEqualTo(8));
|
|
expect(result.endsWith("..."), isTrue);
|
|
});
|
|
});
|
|
}
|