def test_syntax_incomplete_004(self): terminput = '${cmd} ${' tagstokens = TagsTokens().init_with_input(terminput).check_syntax() print(tagstokens) self.assertTrue(tagstokens.valid) self.assertTrue(tagstokens.incomplete) self.assertEqual(tagstokens.token_error, '') self.assertEqual(tagstokens.stack, ['BRACEPARAM'])
def test_syntax_error_008(self): terminput = '$(${"}"(\') $( ${ (\' \'' tagstokens = TagsTokens().init_with_input(terminput).check_syntax() print(tagstokens) self.assertFalse(tagstokens.valid) self.assertFalse(tagstokens.incomplete) self.assertEqual(tagstokens.token_error, 'bad substitution') self.assertEqual(tagstokens.stack, [])
def test_syntax_incomplete_006(self): terminput = 'ls && ' tagstokens = TagsTokens().init_with_input(terminput).check_syntax() print(tagstokens) self.assertTrue(tagstokens.valid) self.assertTrue(tagstokens.incomplete) self.assertEqual(tagstokens.token_error, '') self.assertEqual(tagstokens.stack, ['CMDAND'])
def test_syntax_incomplete_003(self): terminput = '$(${cmd}"' tagstokens = TagsTokens().init_with_input(terminput).check_syntax() print(tagstokens) self.assertTrue(tagstokens.valid) self.assertTrue(tagstokens.incomplete) self.assertEqual(tagstokens.token_error, '') self.assertEqual(tagstokens.stack, ['CMDSUBST1', 'DQUOTES'])
def test_end_brace_001(self): term_input = '' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual([], tt.tags) self.assertEqual([], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_tags_006(self): tokens = [ 'echo', ' ', '${', 'var', '}', '_', '$var', '${', 'var2', '}', '_' ] tags = TagsTokens(tokens).get_tags().check_syntax().tags self.assertEqual([ 'STMT', 'SPACES', 'BRACEPARAM', 'STMT', 'END_BRACE', 'STMT', 'VAR', 'BRACEPARAM', 'STMT', 'END_BRACE', 'STMT' ], tags)
def test_trunc_valid_001(self): term_input = '>a' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['TRUNC', 'STMT'], tt.tags) self.assertEqual(['>', 'a'], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_subsh_001(self): term_input = '()' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['SUBSH', 'END_BRACKET'], tt.tags) self.assertEqual(['(', ')'], tt.tokens) self.assertEqual(['SUBSH', 'END_BRACKET'], tt.stack) self.assertFalse(tt.valid) self.assertFalse(tt.incomplete)
def test_selecter_end_001(self): term_input = ';;' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['SELECTER_END'], tt.tags) self.assertEqual([';;'], tt.tokens) self.assertEqual(['SELECTER_END'], tt.stack) self.assertFalse(tt.valid) self.assertFalse(tt.incomplete)
def test_tags_007(self): tokens = [ 'echo', ' ', 'text', '>>', 'file', ' ', '>>', ' ', 'file2', '\n' ] tags = TagsTokens(tokens).get_tags().check_syntax().tags self.assertEqual([ 'STMT', 'SPACES', 'STMT', 'APPEND', 'STMT', 'SPACES', 'APPEND', 'SPACES', 'STMT', 'NEW_LINE' ], tags)
def test_basic_valid_006(self): """Test newline in raw input.""" term_input = '\n' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual([], tt.tags) self.assertEqual([], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_valid_004(self): """Test command with terminator.""" term_input = 'cmd;' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['STMT', 'END_COMMAND'], tt.tags) self.assertEqual(['cmd', ';'], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_valid_001(self): """Basic test no input -> no tags no tokens.""" term_input = '' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual([], tt.tags) self.assertEqual([], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_append_001(self): term_input = '>>' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['APPEND'], tt.tags) self.assertEqual(['>>'], tt.tokens) # self.assertEqual([], tt.stack) self.assertEqual('>>', tt.token_error) self.assertFalse(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_invalid_001(self): """Test BACKGROUND_JOBS alone.""" term_input = '&' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['BACKGROUND_JOBS'], tt.tags) self.assertEqual(['&'], tt.tokens) self.assertEqual(['BACKGROUND_JOBS'], tt.stack) self.assertFalse(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_valid_008(self): """Test BACKGROUND_JOBS and spacing in token input.""" tokens = [' ', 'cmd', ' \t', '&', ' \t'] tt = TagsTokens(tokens).get_tags().check_syntax() print(tt) self.assertEqual(['STMT', 'SPACES', 'BACKGROUND_JOBS'], tt.tags) self.assertEqual(['cmd', ' \t', '&'], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_valid_005(self): """Test terminator alone.""" term_input = ';' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['END_COMMAND'], tt.tags) self.assertEqual([';'], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_valid_003(self): """Just one command with lots spaces around=. Test srip methode.""" term_input = ' cmd ' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual(['STMT'], tt.tags) self.assertEqual(['cmd'], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_basic_valid_007(self): """Test newline in raw input.""" tokens = ['\n'] tt = TagsTokens(tokens).get_tags().check_syntax() print(tt) self.assertEqual(['NEW_LINE'], tt.tags) # self.assertEqual(['\n'], tt.tokens) self.assertEqual([], tt.stack) self.assertTrue(tt.valid) self.assertFalse(tt.incomplete)
def test_tags_005(self): tokens = [ 'echo', ' ', '1', '&&', '\n', '<(', 'LOL', ')', '||', '\n', 'LOL', '\n' ] tags = TagsTokens(tokens).get_tags().check_syntax().tags self.assertEqual([ 'STMT', 'SPACES', 'STMT', 'CMDAND', 'NEW_LINE', 'CMDSUBST3', 'STMT', 'END_BRACKET', 'CMDOR', 'NEW_LINE', 'STMT', 'NEW_LINE' ], tags)
def test_subsh_004(self): term_input = 'cmd&&(cmd); cmd' tt = TagsTokens().init_with_input(term_input).check_syntax() print(tt) self.assertEqual([ 'STMT', 'CMDAND', 'SUBSH', 'STMT', 'END_BRACKET', 'END_COMMAND', 'SPACES', 'STMT' ], tt.tags) self.assertEqual(['cmd', '&&', '(', 'cmd', ')', ';', ' ', 'cmd'], tt.tokens) self.assertEqual([], tt.stack) self.assertFalse(tt.valid) self.assertFalse(tt.incomplete)
def default(self, line): line = [char for char in line if char in string.printable] line = "".join(line) self.content += line + "\n" TAGSTOKENS = TagsTokens().init_with_input(self.content).check_syntax() if TAGSTOKENS.valid and not TAGSTOKENS.incomplete: TREE = AST(TAGSTOKENS) run = Executor(TREE) self.content = "" self.prompt = "a prompt > " elif TAGSTOKENS.incomplete: self.prompt = "{} > ".format( ' '.join([tag.lower() for tag in TAGSTOKENS.stack])) else: print('Close all this command tokens: {}'.format( str(TAGSTOKENS.token_error))) self.prompt = "error prompt > " self.content = "" gv.HEREDOCS = [] gv.DONTPRINT = True
def test_tags_008(self): tokens = [ '>(', '<(', 'echo', ' ', 'test', ' ', '>', ' ', 'file.txt', ')', ')', ' ', '&&', ' \t\t', '$VAR_TEST', '|', ' ', 'cat', ' ', '<<', ' ', 'HERE', '\n', 'testHERE', '\n', 'HERE' ] # this line is magical disappear # by heredocs gesture tags = TagsTokens(tokens).get_tags().check_syntax().tags self.assertEqual( [ 'CMDSUBST2', 'CMDSUBST3', 'STMT', 'SPACES', 'STMT', 'SPACES', 'TRUNC', 'SPACES', 'STMT', 'END_BRACKET', 'END_BRACKET', 'SPACES', 'CMDAND', 'SPACES', 'VAR', 'PIPE', 'SPACES', 'STMT', 'SPACES', 'HEREDOC', 'SPACES', 'STMT', 'NEW_LINE', # 'STMT', 'NEW_LINE', 'STMT' ], tags)
def test_tags_001(self): tokens = ['ls', ' ', '-l', '\n'] tags = TagsTokens(tokens).get_tags().check_syntax().tags self.assertEqual(['STMT', 'SPACES', 'STMT', 'NEW_LINE'], tags)
def test_tags_quotes_011(self): term_inputs = "'\"${CMD}\"'" tags = TagsTokens().init_with_input(term_inputs).check_syntax().tags self.assertEqual( ['QUOTE', 'STMT', 'STMT', 'STMT', 'STMT', 'STMT', 'END_QUOTE'], tags)
def test_tags_003(self): tokens = ['VAR', ' ', '+=', ' ', '0', '\n'] tags = TagsTokens(tokens).get_tags().check_syntax().tags self.assertEqual( ['STMT', 'SPACES', 'CONCATENATION', 'SPACES', 'STMT', 'NEW_LINE'], tags)
def test_tags_double_quotes_011(self): term_inputs = '" CMD CMD "' tags = TagsTokens().init_with_input(term_inputs).check_syntax().tags self.assertEqual( ['DQUOTES', 'STMT', 'STMT', 'STMT', 'STMT', 'STMT', 'END_DQUOTES'], tags)
def test_tags_double_quotes_005(self): term_inputs = '"${CMD}"' tags = TagsTokens().init_with_input(term_inputs).check_syntax().tags self.assertEqual( ['DQUOTES', 'BRACEPARAM', 'STMT', 'END_BRACE', 'END_DQUOTES'], tags)
def test_tags_double_quotes_004(self): term_inputs = '"$(CMD)"' tags = TagsTokens().init_with_input(term_inputs).check_syntax().tags self.assertEqual( ['DQUOTES', 'CMDSUBST1', 'STMT', 'END_BRACKET', 'END_DQUOTES'], tags)
def test_tags_009(self): term_inputs = ' \\ a ' tags = TagsTokens().init_with_input(term_inputs).check_syntax().tags self.assertEqual(['STMT', 'STMT'], tags)