From ec3298535ebe1d6602df9196b81c92d4a88b4821 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 16 Aug 2016 15:31:23 +0100 Subject: Introduce hex literals (#832) * Introduce hex keyword token * Support hex literals * Include tests for hex literals * Document hex literals --- test/libsolidity/SolidityScanner.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/libsolidity/SolidityScanner.cpp') diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 624614d2..31b75f25 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -324,6 +324,42 @@ BOOST_AUTO_TEST_CASE(invalid_short_unicode_string_escape) BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); } +BOOST_AUTO_TEST_CASE(valid_hex_literal) +{ + Scanner scanner(CharStream("{ hex\"00112233FF\"")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); + BOOST_CHECK_EQUAL(scanner.next(), Token::StringLiteral); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), std::string("\x00\x11\x22\x33\xFF", 5)); +} + +BOOST_AUTO_TEST_CASE(invalid_short_hex_literal) +{ + Scanner scanner(CharStream("{ hex\"00112233F\"")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(invalid_hex_literal_with_space) +{ + Scanner scanner(CharStream("{ hex\"00112233FF \"")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(invalid_hex_literal_with_wrong_quotes) +{ + Scanner scanner(CharStream("{ hex\"00112233FF'")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(invalid_hex_literal_nonhex_string) +{ + Scanner scanner(CharStream("{ hex\"hello\"")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit