-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update Dict.update function to take an alter function * update Aggregate.scala with missing functions and mismatched types * update sdk functions * align sdk.Regex more closely with elm\/regex * - Revert Result.map3 param signature to `fn: (A, B, C) => V` - change counter implementation for Regex.find * added unit test for Regex.find and Regex.split
- Loading branch information
1 parent
a2f86e9
commit d250c91
Showing
5 changed files
with
105 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package morphir.sdk | ||
|
||
object ResultList { | ||
|
||
type ResultList[E, A] = List.List[Result.Result[E, A]] | ||
|
||
/** Turn a list of results into a single result keeping all errors. | ||
*/ | ||
def keepAllErrors[E, A](results: ResultList[E, A]): Result.Result[List[E], List[A]] = { | ||
val oks: List[A] = List.filterMap(Result.toMaybe[E, A])(results) | ||
val errs: List[E] = List.filterMap((result: Result[E, A]) => | ||
result match { | ||
case Result.Err(e) => Maybe.Just(e) | ||
case Result.Ok(_) => Maybe.Nothing | ||
} | ||
)(results) | ||
|
||
errs match { | ||
case Nil => Result.Ok(oks) | ||
case _ => Result.Err(errs) | ||
} | ||
} | ||
|
||
} |
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,48 @@ | ||
package morphir.sdk | ||
|
||
import zio.test._ | ||
|
||
object RegexSpec extends DefaultRunnableSpec { | ||
|
||
val splitPattern: Regex.Regex = | ||
Maybe.withDefault(Regex.never)(Regex.fromString("""[^\w\s]+""")) | ||
|
||
val splitScenarios = Seq( | ||
("morphir.sdk", List("morphir", "sdk")), | ||
("morphir:sdk", List("morphir", "sdk")) | ||
) | ||
|
||
val wordPattern: Regex.Regex = | ||
Maybe.withDefault(Regex.never)(Regex.fromString("""([a-zA-Z][a-z]*|[0-9]+)""")) | ||
|
||
val findScenarios = Seq( | ||
("Morphir", List("Morphir")), | ||
("SDK", List("S", "D", "K")), | ||
("camelCaseName", List("camel", "Case", "Name")) | ||
) | ||
|
||
def spec = suite("Regex Spec")( | ||
suite(s"""Regex.split with $splitPattern pattern""")( | ||
splitScenarios.map { case (testString, expectedOutput) => | ||
test(s"""split("$testString") == $expectedOutput""") { | ||
assert(Regex.split(splitPattern)(testString))( | ||
Assertion.equalTo(expectedOutput) | ||
) | ||
} | ||
}: _* | ||
), | ||
suite(s"""Regex.find with $wordPattern pattern""")( | ||
findScenarios.map { case (testString, expectedOutput) => | ||
test(s"""find("$testString").map(_.match) == $expectedOutput""") { | ||
assert( | ||
Regex | ||
.find(wordPattern)(testString) | ||
.map(_._match) | ||
)( | ||
Assertion.equalTo(expectedOutput) | ||
) | ||
} | ||
}: _* | ||
) | ||
) | ||
} |