Пример #1
0
 def test_read_single_backslash(self):
     io = StringIO()
     unicode_str = u"\"string \e e \""
     io.write(unicode_str)
     scanner = Scanner()
     scanner.file_input = io
     with self.assertRaises(TokenMismatchException):
         scanner.advance()
Пример #2
0
 def test_read_unterminated_string(self):
     io = StringIO()
     unicode_str = u"\"string \\uc223 "
     io.write(unicode_str)
     scanner = Scanner()
     scanner.file_input = io
     with self.assertRaises(TokenMismatchException):
         scanner.advance()
Пример #3
0
    def test_read_false(self):
        io = StringIO()
        io.write(u"false")
        scanner = Scanner()
        scanner.file_input = io
        scanner.advance()
        scanner.require_token(TokenType.false)

        self.assertEqual(scanner.token, Token(TokenType.false, u"false"))
Пример #4
0
    def test_read_null(self):
        io = StringIO()
        io.write(u"null")
        scanner = Scanner()
        scanner.file_input = io
        scanner.advance()
        scanner.require_token(TokenType.null)

        self.assertEqual(scanner.token, Token(TokenType.null, u"null"))
Пример #5
0
    def test_read_integer_with_fraction_and_exponent(self):
        io = StringIO()
        unicode_str = u"1142.234e12"
        io.write(unicode_str)
        scanner = Scanner()
        scanner.file_input = io
        scanner.advance()
        scanner.require_token(TokenType.number)

        self.assertEqual(scanner.token, Token(TokenType.number, unicode_str))
Пример #6
0
    def test_read_integer(self):
        io = StringIO()
        unicode_str = u"1342"
        io.write(unicode_str)
        scanner = Scanner()
        scanner.file_input = io
        scanner.advance()
        scanner.require_token(TokenType.number)

        self.assertEqual(scanner.token, Token(TokenType.number, unicode_str))
Пример #7
0
    def test_read_string(self):
        io = StringIO()
        unicode_str = u"\" \\\\ \\\" \\/ \\b \\n \\t \\r \\f 123 abc \\u32ef\""
        io.write(unicode_str)
        scanner = Scanner()
        scanner.file_input = io
        scanner.advance()
        scanner.require_token(TokenType.string)

        self.assertEqual(scanner.token, Token(TokenType.string, unicode_str))