/Users/deen/code/yugabyte-db/src/yb/util/bytes_formatter-test.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/util/bytes_formatter.h" |
15 | | |
16 | | #include <string> |
17 | | #include <gtest/gtest.h> |
18 | | |
19 | | using std::string; |
20 | | |
21 | | namespace yb { |
22 | | namespace util { |
23 | | |
24 | 1 | TEST(BytesFormatterTest, TestSingleQuotes) { |
25 | 1 | ASSERT_EQ( |
26 | 1 | "'foo\\'bar\"baz'", |
27 | 1 | FormatBytesAsStr("foo'bar\"baz", QuotesType::kSingleQuotes)); |
28 | 1 | ASSERT_EQ( |
29 | 1 | "'\\x01\\x02\\x03\\xfe\\xff'", |
30 | 1 | FormatBytesAsStr("\x01\x02\x03\xfe\xff", QuotesType::kSingleQuotes)); |
31 | 1 | ASSERT_EQ("'foo\\\\bar'", FormatBytesAsStr("foo\\bar", QuotesType::kSingleQuotes)); |
32 | 1 | } |
33 | | |
34 | 1 | TEST(BytesFormatterTest, TestDoubleQuotes) { |
35 | 1 | ASSERT_EQ( |
36 | 1 | "\"foo'bar\\\"baz\"", |
37 | 1 | FormatBytesAsStr("foo'bar\"baz", QuotesType::kDoubleQuotes)); |
38 | 1 | ASSERT_EQ( |
39 | 1 | "\"\\x01\\x02\\x03\\xfe\\xff\"", |
40 | 1 | FormatBytesAsStr("\x01\x02\x03\xfe\xff", QuotesType::kDoubleQuotes)); |
41 | 1 | ASSERT_EQ("\"foo\\\\bar\"", FormatBytesAsStr("foo\\bar", QuotesType::kDoubleQuotes)); |
42 | 1 | } |
43 | | |
44 | 1 | TEST(BytesFormatterTest, TestMaxLength) { |
45 | 1 | const string input_str("foo'bar\"baz"); |
46 | 1 | ASSERT_EQ( |
47 | 1 | "\"fo<...9 bytes skipped>\"", |
48 | 1 | FormatBytesAsStr(input_str, QuotesType::kDoubleQuotes, 3)); |
49 | 1 | ASSERT_EQ( |
50 | 1 | "\"foo'<...7 bytes skipped>\"", |
51 | 1 | FormatBytesAsStr(input_str, QuotesType::kDoubleQuotes, 5)); |
52 | 1 | ASSERT_EQ( |
53 | 1 | "\"foo'bar\\\"<...3 bytes skipped>\"", |
54 | 1 | FormatBytesAsStr(input_str, QuotesType::kDoubleQuotes, 10)); |
55 | 1 | ASSERT_EQ( |
56 | 1 | "\"foo'bar\\\"baz\"", |
57 | 1 | FormatBytesAsStr(input_str, QuotesType::kDoubleQuotes, 20)); |
58 | 1 | } |
59 | | |
60 | | } // namespace util |
61 | | } // namespace yb |