From 6ccaea0220d1e25ad4b7d712fa5e7f2dcb088522 Mon Sep 17 00:00:00 2001 From: TheOnlyTails Date: Mon, 9 May 2022 18:53:15 +0300 Subject: [PATCH] Added a vararg variant of the `group` function (#7) --- build.gradle.kts | 2 +- .../kotlin/com/theonlytails/ketex/groups.kt | 30 +++++++++++++++++-- src/test/kotlin/KetexTest.kt | 9 ++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8125cba..31521aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,7 +23,7 @@ plugins { } val groupId = "com.theonlytails" -val libVersion = "0.1.5" +val libVersion = "0.1.6" group = groupId version = libVersion diff --git a/src/main/kotlin/com/theonlytails/ketex/groups.kt b/src/main/kotlin/com/theonlytails/ketex/groups.kt index 000e624..f666085 100644 --- a/src/main/kotlin/com/theonlytails/ketex/groups.kt +++ b/src/main/kotlin/com/theonlytails/ketex/groups.kt @@ -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) \ No newline at end of file +) = 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 } +} diff --git a/src/test/kotlin/KetexTest.kt b/src/test/kotlin/KetexTest.kt index 2aa6a20..dab3b6a 100644 --- a/src/test/kotlin/KetexTest.kt +++ b/src/test/kotlin/KetexTest.kt @@ -325,4 +325,13 @@ class KetexTest { } ) } + + @Test + fun `group with vararg`() { + assertEquals("""(abc)""", + regexAsString { + +group("abc") + } + ) + } }