コード例 #1
0
 def testSplitKeepingQuotes_withMatchingPattern(self):
     self.assertListEqual(
         QuoteParser.split_keeping_quotes("aCaba'AAc'", self.LOWERCASE),
         ['', 'C', '', '', "'AAc'"])
     self.assertListEqual(
         QuoteParser.split_keeping_quotes('aCaba"AAc"', self.LOWERCASE),
         ['', 'C', '', '', '"AAc"'])
コード例 #2
0
 def testFindUnquotedSymbols_matchesForSimpleSymbols(self):
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols("abaCaba'ABAc'", self.LOWERCASE),
         {0, 1, 2, 4, 5, 6})
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols('abaCaba"ABAc"', self.LOWERCASE),
         {0, 1, 2, 4, 5, 6})
コード例 #3
0
 def testNextState_afterNonQuote(self):
     self.assertEqual(QuoteParser._next_state(_State.UNQUOTED, '`'),
                      _State.UNQUOTED)
     self.assertEqual(QuoteParser._next_state(_State.IN_SINGLE, '`'),
                      _State.IN_SINGLE)
     self.assertEqual(QuoteParser._next_state(_State.IN_DOUBLE, '`'),
                      _State.IN_DOUBLE)
コード例 #4
0
 def testNextState_afterSingleQuote(self):
     self.assertEqual(QuoteParser._next_state(_State.UNQUOTED, "'"),
                      _State.IN_SINGLE)
     self.assertEqual(QuoteParser._next_state(_State.IN_SINGLE, "'"),
                      _State.UNQUOTED)
     self.assertEqual(QuoteParser._next_state(_State.IN_DOUBLE, "'"),
                      _State.IN_DOUBLE)
コード例 #5
0
 def testFindExpandableVariables_withExpandableVariables(self):
     self.assertSetEqual(QuoteParser.find_expandable_variables('echo $5'),
                         {5})
     self.assertSetEqual(QuoteParser.find_expandable_variables('$variable'),
                         {0})
     self.assertSetEqual(
         QuoteParser.find_expandable_variables('echo "$5 $6" | $7'),
         {6, 9, 15})
コード例 #6
0
 def testSplitKeepingQuotes_noMatchingPattern(self):
     self.assertListEqual(
         QuoteParser.split_keeping_quotes('', self.UPPERCASE), [''])
     self.assertListEqual(
         QuoteParser.split_keeping_quotes("aba'ABAcABA'", self.UPPERCASE),
         ["aba'ABAcABA'"])
     self.assertListEqual(
         QuoteParser.split_keeping_quotes('aba"ABAcABA"', self.UPPERCASE),
         ['aba"ABAcABA"'])
コード例 #7
0
 def testFindUnquotedSymbols_matchingQuotes(self):
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols(r'''""''', self.QUOTES), {0, 1})
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols(r'''"'"''"'"''', self.QUOTES),
         {0, 2, 3, 4, 5, 7})
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols(r'''a"b"'c'd''', self.QUOTES),
         {1, 3, 4, 6})
コード例 #8
0
 def testFindUnquotedSymbols_noMatchesSimpleSymbols(self):
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols('', self.UPPERCASE), set())
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols("abacaba'ABAcABA'",
                                           self.UPPERCASE), set())
     self.assertSetEqual(
         QuoteParser.find_unquoted_symbols('abacaba"ABAcABA"',
                                           self.UPPERCASE), set())
コード例 #9
0
    def read():
        """ Reads lines from the input.

         New lines continue to be queried while the quotes do not match,
         or while the input ends with a pipe.
         """
        result = input('$ ')
        while not QuoteParser.quotes_match(result) or result.rstrip().endswith(
                '|'):
            result += os.linesep + input('> ')
        return result
コード例 #10
0
 def testRemoveQuotes_quotesInsideQuotes(self):
     self.assertEqual(QuoteParser.remove_quotes(r'''"''"'''), "''")
     self.assertEqual(QuoteParser.remove_quotes(r"""'""'"""), '""')
     self.assertEqual(
         QuoteParser.remove_quotes(r'''"'quote'"'"removal"'"'test'"'''),
         r"""'quote'"removal"'test'""")
コード例 #11
0
 def testRemoveQuotes_simpleQuotes(self):
     self.assertEqual(QuoteParser.remove_quotes('""'), '')
     self.assertEqual(QuoteParser.remove_quotes("''"), '')
     self.assertEqual(
         QuoteParser.remove_quotes(r'''"quote"'removal'"test"'''),
         'quoteremovaltest')
コード例 #12
0
 def testRemoveQuotes_noQuotes(self):
     self.assertEqual(QuoteParser.remove_quotes(''), '')
     self.assertEqual(
         QuoteParser.remove_quotes('expression without quotes'),
         'expression without quotes')
コード例 #13
0
 def testFindExpandableVariables_noExpandableVariables(self):
     self.assertSetEqual(QuoteParser.find_expandable_variables('echo 5'),
                         set())
     self.assertSetEqual(QuoteParser.find_expandable_variables(''), set())
     self.assertSetEqual(QuoteParser.find_expandable_variables("echo '$5"),
                         set())
コード例 #14
0
 def testQuotesMatch_trailingDoubleQuote(self):
     self.assertFalse(QuoteParser.quotes_match('hello "world'))
     self.assertFalse(QuoteParser.quotes_match('"'))
コード例 #15
0
 def testQuotesMatch_trailingSingleQuote(self):
     self.assertFalse(QuoteParser.quotes_match("hello 'world"))
     self.assertFalse(QuoteParser.quotes_match("'"))
コード例 #16
0
 def testQuotesMatch_quotesMatch(self):
     self.assertTrue(QuoteParser.quotes_match(''))
     self.assertTrue(QuoteParser.quotes_match(r''''hello' "world"'''))