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()
 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()
    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"))
    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"))
    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))
    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))
    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))