Skip to content

Commit

Permalink
Added a vararg variant of the group function (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyTails authored May 9, 2022
1 parent 83e01fe commit 6ccaea0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

val groupId = "com.theonlytails"
val libVersion = "0.1.5"
val libVersion = "0.1.6"

group = groupId
version = libVersion
Expand Down
30 changes: 27 additions & 3 deletions src/main/kotlin/com/theonlytails/ketex/groups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,33 @@ class KetexGroup(private val type: KetexGroupType, private val name: String) : K
}

context(KetexFragment)
@KetexMarker
inline fun group(
@KetexMarker
inline fun group(
type: KetexGroupType = KetexGroupType.Capture,
name: String = "",
block: KetexGroup.() -> Unit,
) = KetexGroup(type, name).apply(block)
) = KetexGroup(type, name).apply(block)

context(KetexFragment)
@KetexMarker
fun group(vararg tokens: String) = group {
tokens.forEach { +it }
}

context(KetexFragment)
@KetexMarker
fun group(vararg tokens: Char) = group {
tokens.forEach { +it }
}

context(KetexFragment)
@KetexMarker
fun group(vararg tokens: CharRange) = group {
tokens.forEach { +it }
}

context(KetexFragment)
@KetexMarker
fun group(vararg tokens: KetexToken) = group {
tokens.forEach { +it }
}
9 changes: 9 additions & 0 deletions src/test/kotlin/KetexTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,13 @@ class KetexTest {
}
)
}

@Test
fun `group with vararg`() {
assertEquals("""(abc)""",
regexAsString {
+group("abc")
}
)
}
}

1 comment on commit 6ccaea0

@vercel
Copy link

@vercel vercel bot commented on 6ccaea0 May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.