Skip to content

Commit 82d87b6

Browse files
authored
Merge pull request #8 from celtric/remove_unnecessary_operator_overload
Remove unnecessary operator overload
2 parents a1a528a + 7abbd4c commit 82d87b6

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
}
1414

1515
group "org.celtric.kotlin"
16-
version "0.1.0"
16+
version "0.1.1"
1717

1818
apply plugin: "kotlin"
1919
apply plugin: "maven-publish"

src/main/kotlin/org/celtric/kotlin/html/_building_blocks.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ fun List<Node>.render(opt: Options = Options()) = joinToString("") {
8888
}
8989

9090
operator fun List<Node>.plus(text: String): List<Node> = plus(Text(text))
91-
// TODO: can the call to the overloaded plus operator be delegated without this casting hack?
92-
@Suppress("UNCHECKED_CAST")
93-
operator fun List<Node>.plus(node: Node): List<Node> = ((this as List<Any>) + node) as List<Node>
94-
@Suppress("UNCHECKED_CAST")
95-
operator fun List<Node>.plus(nodes: List<Node>): List<Node> = ((this as List<Any>) + nodes) as List<Node>
9691

9792
//---[ Attributes ]---------------------------------------------------------------------//
9893

@@ -104,5 +99,5 @@ private fun Attributes.renderAttributes(prefix: String = "") =
10499
.joinToString("") { (key, value) -> " " + prefix + key + value }
105100

106101
class AllAttributes(val common: Attributes, val other: Attributes, val data: Attributes) {
107-
fun render() = common.renderAttributes() + other.renderAttributes()+ data.renderAttributes("data-")
102+
fun render() = common.renderAttributes() + other.renderAttributes() + data.renderAttributes("data-")
108103
}

src/test/kotlin/org/celtric/kotlin/html/ListsTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,13 @@ internal class ListsTest {
3838
</ul>
3939
""")
4040
}
41+
42+
@Test fun `the way lists are grouped when combined is irrelevant`() {
43+
val elem = li("Element")
44+
val reference = elem + elem + elem + elem
45+
46+
((elem) + (elem + elem + elem)).assertRendersSameAs(reference)
47+
((elem + elem) + (elem + elem)).assertRendersSameAs(reference)
48+
((elem + elem + elem) + (elem)).assertRendersSameAs(reference)
49+
}
4150
}

src/test/kotlin/org/celtric/kotlin/html/utils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ fun Node.assertRendersMultiline(expected: String) {
1919
fun List<Node>.assertRendersMultiline(expected: String) {
2020
Assertions.assertEquals(expected.trimIndent() + "\n", render(testRenderingOptions))
2121
}
22+
23+
fun List<Node>.assertRendersSameAs(other: List<Node>) {
24+
Assertions.assertEquals(other.render(testRenderingOptions), render(testRenderingOptions))
25+
}

0 commit comments

Comments
 (0)