Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a vararg variant of the group function #7

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
)
}
}