-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_builder_test.dart
66 lines (54 loc) · 1.93 KB
/
string_builder_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import "package:test/test.dart";
import 'string_builder.dart';
void main() {
test("Empty StringBuilder should be the empty String", () {
StringBuilder sb = new StringBuilder();
expect(sb.toString(), equals(""));
});
test("StringBuilder should support adding codepoints", () {
StringBuilder sb = new StringBuilder();
expect(sb.length, equals(0));
sb.appendChar("h".runes.first);
sb.appendChar("e".runes.first);
sb.appendChar("l".runes.first);
sb.appendChar("l".runes.first);
sb.appendChar("o".runes.first);
expect(sb.toString(), equals("hello"));
});
test("StringBuilder should support adding strings", () {
StringBuilder sb = new StringBuilder();
sb.appendString("h");
sb.appendString("ello");
expect(sb.toString(), equals("hello"));
});
test("StringBuilder should support adding codepoints and strings", () {
StringBuilder sb = new StringBuilder();
sb.appendChar("h".runes.first);
sb.appendChar("e".runes.first);
sb.appendChar("l".runes.first);
sb.appendChar("l".runes.first);
sb.appendChar("o".runes.first);
sb.appendString(", world");
expect(sb.toString(), equals("hello, world"));
});
test("StringBuilder should support chaining", () {
StringBuilder sb = new StringBuilder()
.appendChar("h".runes.first)
.appendChar("e".runes.first)
.appendString("ll")
.appendChar("o".runes.first);
sb.appendChar(",".runes.first);
sb.appendChar(" ".runes.first).appendString("world");
expect(sb.toString(), equals("hello, world"));
});
test("StringBuilder should support unicode and report the correct length",
() {
StringBuilder sb = new StringBuilder();
sb.appendChar("😀".runes.first);
sb.appendChar("♜".runes.first);
sb.appendString("🤡");
sb.appendString("Þ");
expect(sb.toString(), equals("😀♜🤡Þ"));
expect(sb.length, equals("😀♜🤡Þ".runes.length));
});
}