proxygen
json_pointer_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <folly/json_pointer.h>
20 
23 
24 class JsonPointerTest : public ::testing::Test {};
25 
26 TEST_F(JsonPointerTest, ValidPointers) {
29  ElementsAreArray(std::vector<std::string>{}));
32  json_pointer::parse("/1/2/3").tokens(),
33  ElementsAreArray({"1", "2", "3"}));
35  json_pointer::parse("/~0~1/~0/10").tokens(),
36  ElementsAreArray({"~/", "~", "10"}));
37 }
38 
39 TEST_F(JsonPointerTest, InvalidPointers) {
40  EXPECT_EQ(
41  json_pointer::parse_error::invalid_first_character,
42  json_pointer::try_parse("a").error());
43  EXPECT_EQ(
44  json_pointer::parse_error::invalid_escape_sequence,
45  json_pointer::try_parse("/~").error());
46  EXPECT_EQ(
47  json_pointer::parse_error::invalid_escape_sequence,
48  json_pointer::try_parse("/~x").error());
49 }
50 
51 TEST_F(JsonPointerTest, IsPrefixTo) {
53  json_pointer::parse("/a/b").is_prefix_of(json_pointer::parse("/a/b/c")));
55  json_pointer::parse("/a/b").is_prefix_of(json_pointer::parse("/a/d/e")));
57  json_pointer::parse("/a/b/c").is_prefix_of(json_pointer::parse("/a/b")));
58 }
size_t parse(const char *buf, size_t len)
Definition: test.c:1591
TEST_F(JsonPointerTest, ValidPointers)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
internal::ElementsAreArrayMatcher< typename::std::iterator_traits< Iter >::value_type > ElementsAreArray(Iter first, Iter last)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_THAT(value, matcher)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
static const char tokens[256]
Definition: http_parser.c:184