<s> import sublime <EOL> import unittest <EOL> from unittest . mock import patch , MagicMock <EOL> from Terminality . macro import Macro <EOL> def file_content ( region ) : <EOL> contents = """<STR_LIT>""" <EOL> return contents [ region . begin ( ) : region . end ( ) ] <EOL> MockView = MagicMock ( spec = sublime . View ) <EOL> MockView . substr = MagicMock ( side_effect = file_content ) <EOL> MockView . file_name . return_value = "<STR_LIT>" <EOL> MockWindow = MagicMock ( spec = sublime . Window ) <EOL> MockWindow . active_view . return_value = MockView <EOL> MockWindow . folders . return_value = [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> class TestMacroParser ( unittest . TestCase ) : <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_none ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_empty ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_predefined_macro1 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT:file>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_predefined_macro2 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_predefined_macro3 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_predefined_macro4 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_predefined_macro5 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro1 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro2 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro3 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT:1> , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> None , <EOL> [ None , None ] <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro4 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT:1> , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> None , <EOL> [ None , None ] , <EOL> "<STR_LIT>" <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro5 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT:1> , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> None , <EOL> [ None , None ] <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro6 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro7 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro8 ( self , active_window ) : <EOL> MockView . sel . return_value = [ sublime . Region ( <NUM_LIT:5> , <NUM_LIT:10> ) ] <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro9 ( self , active_window ) : <EOL> MockView . sel . return_value = [ sublime . Region ( <NUM_LIT:5> , <NUM_LIT:10> ) ] <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_required_macro10 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_recursion_macro ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_recursion_macro2 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_recursion_macro3 ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_substring_macro ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" ] <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" ] <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) <EOL> @ patch ( '<STR_LIT>' , return_value = MockWindow ) <EOL> def test_regex_macro ( self , active_window ) : <EOL> macros = { <EOL> "<STR_LIT:test>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" ] <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" ] <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ] , <EOL> "<STR_LIT>" : [ <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ] <EOL> } <EOL> } <EOL> self . assertEqual ( <EOL> Macro . parse_macro ( <EOL> string = macros [ "<STR_LIT:test>" ] , <EOL> custom_macros = macros [ "<STR_LIT>" ] , <EOL> required = macros [ "<STR_LIT>" ] <EOL> ) , <EOL> macros [ "<STR_LIT>" ] <EOL> ) </s>
