Skip to content

Commit c33e89e

Browse files
committed
fixed format tests
1 parent 4f8d983 commit c33e89e

File tree

1 file changed

+51
-34
lines changed
  • core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api

1 file changed

+51
-34
lines changed

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
44
import io.kotest.matchers.shouldNotBe
5-
import io.kotest.matchers.string.shouldContain
65
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.blue
76
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red
87
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb
@@ -13,7 +12,6 @@ import org.jetbrains.kotlinx.dataframe.samples.api.firstName
1312
import org.jetbrains.kotlinx.dataframe.samples.api.isHappy
1413
import org.jetbrains.kotlinx.dataframe.samples.api.name
1514
import org.jetbrains.kotlinx.dataframe.samples.api.weight
16-
import org.junit.Ignore
1715
import org.junit.Test
1816

1917
class FormatTests : TestBase() {
@@ -24,7 +22,7 @@ class FormatTests : TestBase() {
2422
val html = formatted.toHtml().toString()
2523

2624
// Should contain CSS background-color styling
27-
html shouldContain "background-color:#ff0000"
25+
(html.split("background-color:#ff0000").size - 1) shouldBe 7
2826
// Format operation should produce a FormattedFrame
2927
formatted::class.simpleName shouldBe "FormattedFrame"
3028
}
@@ -34,7 +32,7 @@ class FormatTests : TestBase() {
3432
val formatted = df.format { age }.with { textColor(blue) }
3533
val html = formatted.toHtml().toString()
3634

37-
html shouldContain "color:#0000ff"
35+
(html.split("color:#0000ff").size - 1) shouldBe 14
3836
formatted::class.simpleName shouldBe "FormattedFrame"
3937
}
4038

@@ -43,34 +41,53 @@ class FormatTests : TestBase() {
4341
val formatted = df.format { age }.with { background(white) and textColor(black) and bold }
4442
val html = formatted.toHtml().toString()
4543

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
5048
}
5149

5250
@Test
5351
fun `format with italic and underline`() {
5452
val formatted = df.format { age }.with { italic and underline }
5553
val html = formatted.toHtml().toString()
5654

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
6159
}
6260

63-
// TODO #1356
64-
@Ignore
6561
@Test
66-
fun `format with italic and underline in nested group`() {
62+
fun `format with italic and underline nested in group`() {
6763
val formatted = df.format { name.firstName }.with { italic and underline }
6864
val html = formatted.toHtml().toString()
6965

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
7491
}
7592

7693
@Test
@@ -80,7 +97,7 @@ class FormatTests : TestBase() {
8097
val html = formatted.toHtml().toString()
8198

8299
// Custom color should be applied
83-
html shouldContain "background-color:#8040c0"
100+
(html.split("background-color:#8040c0").size - 1) shouldBe 7
84101
}
85102

86103
@Test
@@ -158,13 +175,13 @@ class FormatTests : TestBase() {
158175
val formatted = df.format { age }.linearBg(15 to blue, 45 to red)
159176
val html = formatted.toHtml().toString()
160177

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
168185
formatted::class.simpleName shouldBe "FormattedFrame"
169186
}
170187

@@ -175,13 +192,13 @@ class FormatTests : TestBase() {
175192
}
176193
val html = formatted.toHtml().toString()
177194

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
185202
formatted::class.simpleName shouldBe "FormattedFrame"
186203
}
187204

0 commit comments

Comments
 (0)