-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com> Co-Authored-By: Nitsan Avni <nitsanav@gmail.com> Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com> Co-Authored-By: T. E. Green <78671457+Tegsy@users.noreply.github.com>
- Loading branch information
1 parent
dc968ab
commit 10a0da5
Showing
2 changed files
with
12 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
from typing import Generic, Callable, Tuple, Any | ||
|
||
from approvaltests import verify_all | ||
from approvaltests.inline.types import T1, T2, T3, NT1, NT2 | ||
|
||
from approvaltests.inline.types import T1, T2, T3, NT1, NT2, NT3 | ||
|
||
class Parse3(Generic[T1, T2, T3]): | ||
def __init__( | ||
self, text: str, transformer: Callable[[str], Tuple[T1, T2, int]], options | ||
self, text: str, transformer: Callable[[str], Tuple[T1, T2, T3]], options | ||
) -> None: | ||
self.text = text | ||
self._transformer = transformer | ||
self.options = options | ||
|
||
def verify_all(self, transform: Callable[[T1, T2, T3], Any]): | ||
from approvaltests.inline.parse import Parse | ||
|
||
verify_all( | ||
"", | ||
Parse.parse_inputs(self.text, self._transformer), | ||
lambda s: f"{s[0]}, {s[1]}, {s[2]} -> {transform(s[0], s[1],s[2])}", | ||
lambda s: f"{s[0]}, {s[1]}, {s[2]} -> {transform(s[0], s[1], s[2])}", | ||
options=self.options.inline(), | ||
) | ||
|
||
def transform2( | ||
self, transform1: Callable[[T1], NT1], transform2: Callable[[T2], NT2] | ||
) -> "Parse2[NT1, NT2]": | ||
def transformer(s: str) -> Tuple[NT1, NT2]: | ||
t1, t2 = self._transformer(s) | ||
return (transform1(t1), transform2(t2)) | ||
def transform3( | ||
self, transform1: Callable[[T1], NT1], transform2: Callable[[T2], NT2], transform3: Callable[[T3], NT3] | ||
) -> "Parse3[NT1, NT2, NT3]": | ||
def transformer(s: str) -> Tuple[NT1, NT2, NT3]: | ||
t1, t2, t3 = self._transformer(s) | ||
return (transform1(t1), transform2(t2), transform3(t3)) | ||
|
||
return Parse2(self.text, transformer, self.options) | ||
return Parse3(self.text, transformer, self.options) |