-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
798aec0
commit 8b59197
Showing
11 changed files
with
131 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/commonMain/kotlin/me/nathanfallet/makth/usecases/IParseAlgorithmUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package me.nathanfallet.makth.usecases | ||
|
||
import me.nathanfallet.makth.interfaces.Action | ||
import me.nathanfallet.makth.interfaces.Value | ||
import me.nathanfallet.usecases.base.IPairUseCase | ||
import kotlin.js.JsExport | ||
import kotlin.js.JsName | ||
|
||
@JsExport | ||
interface IParseAlgorithmUseCase : IPairUseCase<String, Map<String, (List<Value>) -> Action>, List<Action>> { | ||
|
||
@JsName("invokeDefault") | ||
operator fun invoke(input: String): List<Action> { | ||
return invoke(input, emptyMap()) | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/commonMain/kotlin/me/nathanfallet/makth/usecases/IParseMathUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.nathanfallet.makth.usecases | ||
|
||
import me.nathanfallet.makth.interfaces.Value | ||
import me.nathanfallet.makth.resolvables.Context | ||
import me.nathanfallet.usecases.base.IPairUseCase | ||
import kotlin.js.JsExport | ||
|
||
@JsExport | ||
interface IParseMathUseCase : IPairUseCase<String, Context, Value> |
15 changes: 15 additions & 0 deletions
15
src/commonMain/kotlin/me/nathanfallet/makth/usecases/ParseAlgorithmUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package me.nathanfallet.makth.usecases | ||
|
||
import me.nathanfallet.makth.interfaces.Action | ||
import me.nathanfallet.makth.interfaces.Value | ||
import me.nathanfallet.makth.lexers.AlgorithmLexer | ||
import kotlin.js.JsExport | ||
|
||
@JsExport | ||
class ParseAlgorithmUseCase : IParseAlgorithmUseCase { | ||
|
||
override fun invoke(input1: String, input2: Map<String, (List<Value>) -> Action>): List<Action> { | ||
return AlgorithmLexer(input1).registerKeywords(input2).execute() | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/commonMain/kotlin/me/nathanfallet/makth/usecases/ParseMathUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package me.nathanfallet.makth.usecases | ||
|
||
import me.nathanfallet.makth.interfaces.Value | ||
import me.nathanfallet.makth.lexers.MathLexer | ||
import me.nathanfallet.makth.resolvables.Context | ||
import kotlin.js.JsExport | ||
|
||
@JsExport | ||
class ParseMathUseCase : IParseMathUseCase { | ||
|
||
override fun invoke(input1: String, input2: Context): Value { | ||
return MathLexer(input1).execute(input2) | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/commonTest/kotlin/me/nathanfallet/makth/usecases/ParseAlgorithmUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.nathanfallet.makth.usecases | ||
|
||
import me.nathanfallet.makth.actions.SetAction | ||
import me.nathanfallet.makth.lexers.AlgorithmLexerTest | ||
import me.nathanfallet.makth.numbers.integers.IntegerFactory | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ParseAlgorithmUseCaseTest { | ||
|
||
@Test | ||
fun testInvoke() { | ||
val useCase = ParseAlgorithmUseCase() | ||
assertEquals( | ||
listOf( | ||
SetAction("x", IntegerFactory.instantiate(2)) | ||
), | ||
useCase.invoke("set(x, 2)") | ||
) | ||
} | ||
|
||
@Test | ||
fun testInvokeWithCustomKeywords() { | ||
val useCase = ParseAlgorithmUseCase() | ||
assertEquals( | ||
listOf( | ||
AlgorithmLexerTest.CustomAction(IntegerFactory.instantiate(2)) | ||
), | ||
useCase.invoke("custom(2)", mapOf("custom" to AlgorithmLexerTest.CustomAction::handler)) | ||
) | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/commonTest/kotlin/me/nathanfallet/makth/usecases/ParseMathUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.nathanfallet.makth.usecases | ||
|
||
import me.nathanfallet.makth.numbers.integers.IntegerFactory | ||
import me.nathanfallet.makth.resolvables.Context | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ParseMathUseCaseTest { | ||
|
||
private val contextWithX = Context( | ||
mapOf( | ||
"x" to IntegerFactory.instantiate(2) | ||
) | ||
) | ||
|
||
@Test | ||
fun testInvoke() { | ||
val useCase = ParseMathUseCase() | ||
assertEquals( | ||
IntegerFactory.instantiate(4), | ||
useCase("2 * x", contextWithX) | ||
) | ||
} | ||
|
||
} |