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)
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)
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)
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)
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)
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)
def testCanScanPercent(self): scanner = Scanner("%") tokens = list(scanner.scan()) self.assertEqual([TokenPercent(), TokenEof()], tokens)
def testCanScanOffsetWithTrailingChars(self): scanner = Scanner("+100,") tokens = list(scanner.scan()) self.assertEqual([TokenOffset( [100]), TokenComma(), TokenEof()], tokens)
def testCanScanOffset(self): scanner = Scanner("+100") tokens = list(scanner.scan()) self.assertEqual([TokenOffset([100]), TokenEof()], tokens)
def testCanScanBackwardSearch(self): scanner = Scanner("?foo?") tokens = list(scanner.scan()) self.assertEqual([TokenSearchBackward('foo'), TokenEof()], tokens)
def testCanScanForwardSearch(self): scanner = Scanner("/foo/") tokens = list(scanner.scan()) self.assertEqual([TokenSearchForward('foo'), TokenEof()], tokens)
def testCanScanDollar(self): scanner = Scanner(";") tokens = list(scanner.scan()) self.assertEqual([TokenSemicolon(), TokenEof()], tokens)
def testCanScanNegativeOffset(self): scanner = Scanner(".-100") tokens = list(scanner.scan()) self.assertEqual([TokenDot(), TokenOffset([-100]), TokenEof()], tokens)
def testCanScanEmptyRange(self): scanner = Scanner("s") tokens = list(scanner.scan()) self.assertEqual([TokenCommandSubstitute(None), TokenEof()], tokens) self.assertEqual(1, scanner.state.position)
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)
def testCanParseRedirection(self): scanner = Scanner("w>>") tokens = list(scanner.scan()) params = {'++': '', 'file_name': '', '>>': True, 'cmd': ''} self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
def testCanInstantiate(self): scanner = Scanner("'a") tokens = list(scanner.scan()) self.assertEqual([TokenMark('a'), TokenEof()], tokens)
def testCanInstantiateAlias(self): scanner = Scanner("w") tokens = list(scanner.scan()) params = {'++': '', 'file_name': '', '>>': False, 'cmd': ''} self.assertEqual([TokenCommandWrite(params), TokenEof()], tokens)
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)
def testCanScanDollar(self): scanner = Scanner(",") tokens = list(scanner.scan()) self.assertEqual([TokenComma(), TokenEof()], tokens)
def testCanScanDigits(self): scanner = Scanner("100") tokens = list(scanner.scan()) self.assertEqual([TokenDigits('100'), TokenEof()], tokens)
def testCanInstantiate(self): scanner = Scanner("substitute") tokens = list(scanner.scan()) self.assertEqual([TokenCommandSubstitute(params=None), TokenEof()], tokens)