@@ -2,7 +2,6 @@ package org.jetbrains.kotlinx.dataframe.api
2
2
3
3
import io.kotest.matchers.shouldBe
4
4
import io.kotest.matchers.shouldNotBe
5
- import io.kotest.matchers.string.shouldContain
6
5
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.blue
7
6
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red
8
7
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb
@@ -13,7 +12,6 @@ import org.jetbrains.kotlinx.dataframe.samples.api.firstName
13
12
import org.jetbrains.kotlinx.dataframe.samples.api.isHappy
14
13
import org.jetbrains.kotlinx.dataframe.samples.api.name
15
14
import org.jetbrains.kotlinx.dataframe.samples.api.weight
16
- import org.junit.Ignore
17
15
import org.junit.Test
18
16
19
17
class FormatTests : TestBase () {
@@ -24,7 +22,7 @@ class FormatTests : TestBase() {
24
22
val html = formatted.toHtml().toString()
25
23
26
24
// Should contain CSS background-color styling
27
- html shouldContain " background-color:#ff0000"
25
+ ( html.split( " background-color:#ff0000" ).size - 1 ) shouldBe 7
28
26
// Format operation should produce a FormattedFrame
29
27
formatted::class .simpleName shouldBe " FormattedFrame"
30
28
}
@@ -34,7 +32,7 @@ class FormatTests : TestBase() {
34
32
val formatted = df.format { age }.with { textColor(blue) }
35
33
val html = formatted.toHtml().toString()
36
34
37
- html shouldContain " color:#0000ff"
35
+ ( html.split( " color:#0000ff" ).size - 1 ) shouldBe 14
38
36
formatted::class .simpleName shouldBe " FormattedFrame"
39
37
}
40
38
@@ -43,34 +41,53 @@ class FormatTests : TestBase() {
43
41
val formatted = df.format { age }.with { background(white) and textColor(black) and bold }
44
42
val html = formatted.toHtml().toString()
45
43
46
- html shouldContain " background-color:#ffffff"
47
- html shouldContain " color"
48
- html shouldContain " font-weight"
49
- html shouldContain " bold"
44
+ ( html.split( " background-color:#ffffff" ).size - 1 ) shouldBe 7
45
+ ( html.split( " color:#000000 " ).size - 1 ) shouldBe 14
46
+ ( html.split( " font-weight:bold " ).size - 1 ) shouldBe 7
47
+ ( html.split( " font-weight: bold" ).size - 1 ) shouldBe 7
50
48
}
51
49
52
50
@Test
53
51
fun `format with italic and underline` () {
54
52
val formatted = df.format { age }.with { italic and underline }
55
53
val html = formatted.toHtml().toString()
56
54
57
- html shouldContain " font-style"
58
- html shouldContain " italic"
59
- html shouldContain " text-decoration"
60
- html shouldContain " underline"
55
+ ( html.split( " font-style:italic " ).size - 1 ) shouldBe 7
56
+ ( html.split( " font-style: italic" ).size - 1 ) shouldBe 7
57
+ ( html.split( " text-decoration:underline " ).size - 1 ) shouldBe 7
58
+ ( html.split( " text-decoration: underline" ).size - 1 ) shouldBe 7
61
59
}
62
60
63
- // TODO #1356
64
- @Ignore
65
61
@Test
66
- fun `format with italic and underline in nested group` () {
62
+ fun `format with italic and underline nested in group` () {
67
63
val formatted = df.format { name.firstName }.with { italic and underline }
68
64
val html = formatted.toHtml().toString()
69
65
70
- html shouldContain " font-style"
71
- html shouldContain " italic"
72
- html shouldContain " text-decoration"
73
- html shouldContain " underline"
66
+ (html.split(" font-style:italic" ).size - 1 ) shouldBe 7
67
+ (html.split(" font-style:italic" ).size - 1 ) shouldBe 7
68
+ (html.split(" text-decoration:underline" ).size - 1 ) shouldBe 7
69
+ (html.split(" text-decoration:underline" ).size - 1 ) shouldBe 7
70
+ }
71
+
72
+ @Test
73
+ fun `format with italic and underline for entire group` () {
74
+ val formatted = df
75
+ .format().with { background(white) }
76
+ .format { age }.with { background(blue) and textColor(white) }
77
+ .format { name }.with { background(green) }
78
+ .format { name.firstName }.with { italic and underline }
79
+ .format { name.colsOf<String >() }.where { it.startsWith(" C" ) }.with { background(red) }
80
+
81
+ val html = formatted.toHtml().toString()
82
+
83
+ (html.split(" background-color:#ffffff" ).size - 1 ) shouldBe 21
84
+ (html.split(" background-color:#00ff00" ).size - 1 ) shouldBe 16
85
+ (html.split(" background-color:#0000ff" ).size - 1 ) shouldBe 7
86
+ (html.split(" background-color:#ff0000" ).size - 1 ) shouldBe 5
87
+ (html.split(" font-style:italic" ).size - 1 ) shouldBe 7
88
+ (html.split(" font-style:italic" ).size - 1 ) shouldBe 7
89
+ (html.split(" text-decoration:underline" ).size - 1 ) shouldBe 7
90
+ (html.split(" text-decoration:underline" ).size - 1 ) shouldBe 7
74
91
}
75
92
76
93
@Test
@@ -80,7 +97,7 @@ class FormatTests : TestBase() {
80
97
val html = formatted.toHtml().toString()
81
98
82
99
// Custom color should be applied
83
- html shouldContain " background-color:#8040c0"
100
+ ( html.split( " background-color:#8040c0" ).size - 1 ) shouldBe 7
84
101
}
85
102
86
103
@Test
@@ -158,13 +175,13 @@ class FormatTests : TestBase() {
158
175
val formatted = df.format { age }.linearBg(15 to blue, 45 to red)
159
176
val html = formatted.toHtml().toString()
160
177
161
- html shouldContain " background-color:#0000ff"
162
- html shouldContain " background-color:#2a00d4"
163
- html shouldContain " background-color:#d4002a"
164
- html shouldContain " background-color:#7f007f"
165
- html shouldContain " background-color:#2a00d4"
166
- html shouldContain " background-color:#7f007f"
167
- html shouldContain " background-color:#ff0000"
178
+ ( html.split( " background-color:#0000ff" ).size - 1 ) shouldBe 1
179
+ ( html.split( " background-color:#2a00d4" ).size - 1 ) shouldBe 2
180
+ ( html.split( " background-color:#d4002a" ).size - 1 ) shouldBe 1
181
+ ( html.split( " background-color:#7f007f" ).size - 1 ) shouldBe 2
182
+ ( html.split( " background-color:#2a00d4" ).size - 1 ) shouldBe 2
183
+ ( html.split( " background-color:#7f007f" ).size - 1 ) shouldBe 2
184
+ ( html.split( " background-color:#ff0000" ).size - 1 ) shouldBe 1
168
185
formatted::class .simpleName shouldBe " FormattedFrame"
169
186
}
170
187
@@ -175,13 +192,13 @@ class FormatTests : TestBase() {
175
192
}
176
193
val html = formatted.toHtml().toString()
177
194
178
- html shouldContain " color:#0000ff"
179
- html shouldContain " color:#2a00d4"
180
- html shouldContain " color:#d4002a"
181
- html shouldContain " color:#7f007f"
182
- html shouldContain " color:#2a00d4"
183
- html shouldContain " color:#7f007f"
184
- html shouldContain " color:#ff0000"
195
+ ( html.split( " color:#0000ff" ).size - 1 ) shouldBe 2
196
+ ( html.split( " color:#2a00d4" ).size - 1 ) shouldBe 4
197
+ ( html.split( " color:#d4002a" ).size - 1 ) shouldBe 2
198
+ ( html.split( " color:#7f007f" ).size - 1 ) shouldBe 4
199
+ ( html.split( " color:#2a00d4" ).size - 1 ) shouldBe 4
200
+ ( html.split( " color:#7f007f" ).size - 1 ) shouldBe 4
201
+ ( html.split( " color:#ff0000" ).size - 1 ) shouldBe 2
185
202
formatted::class .simpleName shouldBe " FormattedFrame"
186
203
}
187
204
0 commit comments