Пример #1
0
    def testCanParsePlusPlusNobin(self):
        scanner = Scanner("w ++nobinary")
        tokens = list(scanner.scan())
        params = {'++': 'nobinary', 'file_name': '', '>>': False, 'cmd': ''}
        self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)

        scanner = Scanner("w ++nobin")
        tokens = list(scanner.scan())
        params = {'++': 'nobinary', 'file_name': '', '>>': False, 'cmd': ''}
        self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #2
0
    def testCanParsePlusPlusEdit(self):
        scanner = Scanner("w ++edit")
        tokens = list(scanner.scan())
        params = {'++': 'edit', 'file_name': '', '>>': False, 'cmd': ''}
        self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)

        scanner = Scanner("w ++fileformat")
        tokens = list(scanner.scan())
        params = {'++': 'fileformat', 'file_name': '', '>>': False, 'cmd': ''}
        self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #3
0
 def testCanParseCommandAbsorbsEveryThing(self):
     scanner = Scanner("w !dostuff here")
     tokens = list(scanner.scan())
     params = {
         '++': '',
         'file_name': '',
         '>>': False,
         'cmd': 'dostuff here'
     }
     self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #4
0
 def testCanScanDotOffsetSearchForward(self):
     scanner = Scanner(".+10/foobar/")
     tokens = list(scanner.scan())
     self.assertEqual([
         TokenDot(),
         TokenOffset([10]),
         TokenSearchForward('foobar'),
         TokenEof()
     ], tokens)
     self.assertEqual(12, scanner.state.position)
Пример #5
0
 def testCanScanSubstituteParamatersWithCount(self):
     scanner = Scanner("substitute:foo:bar: 10")
     tokens = list(scanner.scan())
     params = {
         "search_term": "foo",
         "replacement": "bar",
         "flags": [],
         "count": 10
     }
     self.assertEqual([TokenCommandSubstitute(params), TokenEof()], tokens)
Пример #6
0
    def testCanParsePlusPlusFileencoding(self):
        scanner = Scanner("w ++fileencoding")
        tokens = list(scanner.scan())
        params = {
            '++': 'fileencoding',
            'file_name': '',
            '>>': False,
            'cmd': ''
        }
        self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)

        scanner = Scanner("w ++enc")
        tokens = list(scanner.scan())
        params = {
            '++': 'fileencoding',
            'file_name': '',
            '>>': False,
            'cmd': ''
        }
        self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #7
0
 def testCanScanPercent(self):
     scanner = Scanner("%")
     tokens = list(scanner.scan())
     self.assertEqual([TokenPercent(), TokenEof()], tokens)
Пример #8
0
 def testCanScanOffsetWithTrailingChars(self):
     scanner = Scanner("+100,")
     tokens = list(scanner.scan())
     self.assertEqual([TokenOffset(
         [100]), TokenComma(), TokenEof()], tokens)
Пример #9
0
 def testCanScanOffset(self):
     scanner = Scanner("+100")
     tokens = list(scanner.scan())
     self.assertEqual([TokenOffset([100]), TokenEof()], tokens)
Пример #10
0
 def testCanScanBackwardSearch(self):
     scanner = Scanner("?foo?")
     tokens = list(scanner.scan())
     self.assertEqual([TokenSearchBackward('foo'), TokenEof()], tokens)
Пример #11
0
 def testCanScanForwardSearch(self):
     scanner = Scanner("/foo/")
     tokens = list(scanner.scan())
     self.assertEqual([TokenSearchForward('foo'), TokenEof()], tokens)
Пример #12
0
 def testCanScanDollar(self):
     scanner = Scanner(";")
     tokens = list(scanner.scan())
     self.assertEqual([TokenSemicolon(), TokenEof()], tokens)
Пример #13
0
 def testCanScanNegativeOffset(self):
     scanner = Scanner(".-100")
     tokens = list(scanner.scan())
     self.assertEqual([TokenDot(), TokenOffset([-100]), TokenEof()], tokens)
Пример #14
0
 def testCanScanEmptyRange(self):
     scanner = Scanner("s")
     tokens = list(scanner.scan())
     self.assertEqual([TokenCommandSubstitute(None), TokenEof()], tokens)
     self.assertEqual(1, scanner.state.position)
Пример #15
0
 def testCanParseRedirectionFollowedByFilenameSeparated(self):
     scanner = Scanner("w>> foo.txt")
     tokens = list(scanner.scan())
     params = {'++': '', 'file_name': 'foo.txt', '>>': True, 'cmd': ''}
     self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #16
0
 def testCanParseRedirection(self):
     scanner = Scanner("w>>")
     tokens = list(scanner.scan())
     params = {'++': '', 'file_name': '', '>>': True, 'cmd': ''}
     self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #17
0
 def testCanInstantiate(self):
     scanner = Scanner("'a")
     tokens = list(scanner.scan())
     self.assertEqual([TokenMark('a'), TokenEof()], tokens)
Пример #18
0
 def testCanInstantiateAlias(self):
     scanner = Scanner("w")
     tokens = list(scanner.scan())
     params = {'++': '', 'file_name': '', '>>': False, 'cmd': ''}
     self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #19
0
 def testCanParseCommandAndDetectFileName(self):
     scanner = Scanner("w foo.txt")
     tokens = list(scanner.scan())
     params = {'++': '', 'file_name': 'foo.txt', '>>': False, 'cmd': ''}
     self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
Пример #20
0
 def testCanScanDollar(self):
     scanner = Scanner(",")
     tokens = list(scanner.scan())
     self.assertEqual([TokenComma(), TokenEof()], tokens)
Пример #21
0
 def testCanScanDigits(self):
     scanner = Scanner("100")
     tokens = list(scanner.scan())
     self.assertEqual([TokenDigits('100'), TokenEof()], tokens)
Пример #22
0
 def testCanInstantiate(self):
     scanner = Scanner("substitute")
     tokens = list(scanner.scan())
     self.assertEqual([TokenCommandSubstitute(params=None),
                       TokenEof()], tokens)