-
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.
* Implemented preprocessor * Add tests for preprocessor and fix bugs uncovered by testing * Add test for put_cursor_marker * Update stdlib tests to include preprocessor and changed cursor marker logic a bit * Add postprocessing to main
- Loading branch information
Showing
4 changed files
with
92 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from homotopy.snippet_provider import snippetProvider | ||
|
||
import re | ||
|
||
|
||
class Preprocessor: | ||
cursor_marker = "[{cursor_marker}]" | ||
|
||
@staticmethod | ||
def expand_decorators(snippet_text): | ||
return re.sub( | ||
r'\[\[(.*?)\]\]', | ||
lambda match_group: snippetProvider[match_group.group(1)], | ||
snippet_text) | ||
|
||
@staticmethod | ||
def put_cursor_marker(snippet_text): | ||
return snippet_text + "&" + Preprocessor.cursor_marker |
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,28 @@ | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
|
||
from homotopy.preprocessor import Preprocessor | ||
|
||
|
||
class TestPreprocessor(TestCase): | ||
@patch('homotopy.snippet_provider.SnippetProvider.__getitem__') | ||
def test_expand_decorators(self, mock_provider): | ||
data = { | ||
"def": "expansion", | ||
"def1": "expansion1", | ||
"def2": "expansion2" | ||
} | ||
|
||
mock_provider.side_effect = lambda x: x if x not in data else data[x] | ||
|
||
self.assertEqual("noExpansion", Preprocessor.expand_decorators("noExpansion")) | ||
|
||
self.assertEqual("test_expansion", Preprocessor.expand_decorators("test_[[def]]")) | ||
|
||
self.assertEqual("multiple_expansion1_expansions_expansion2", | ||
Preprocessor.expand_decorators("multiple_[[def1]]_expansions_[[def2]]")) | ||
|
||
def test_put_cursor_marker(self): | ||
cursor_marker = "[{cursor_marker}]" | ||
|
||
self.assertEqual("snippet&" + cursor_marker, Preprocessor.put_cursor_marker("snippet")) |
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