├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .golangci.yml ├── LICENSE ├── Makefile ├── NOTICE ├── README.md ├── api.go ├── api_test.go ├── astnodetype_string.go ├── cmd └── jpgo │ └── main.go ├── compliance ├── basic.json ├── boolean.json ├── current.json ├── escape.json ├── filters.json ├── functions.json ├── identifiers.json ├── indices.json ├── literal.json ├── multiselect.json ├── ormatch.json ├── pipe.json ├── slice.json ├── syntax.json ├── unicode.json └── wildcard.json ├── compliance_test.go ├── functions.go ├── fuzz ├── jmespath.go └── testdata │ ├── expr-1 │ ├── expr-10 │ ├── expr-100 │ ├── expr-101 │ ├── expr-102 │ ├── expr-103 │ ├── expr-104 │ ├── expr-105 │ ├── expr-106 │ ├── expr-107 │ ├── expr-108 │ ├── expr-109 │ ├── expr-110 │ ├── expr-112 │ ├── expr-115 │ ├── expr-118 │ ├── expr-119 │ ├── expr-12 │ ├── expr-120 │ ├── expr-121 │ ├── expr-122 │ ├── expr-123 │ ├── expr-126 │ ├── expr-128 │ ├── expr-129 │ ├── expr-13 │ ├── expr-130 │ ├── expr-131 │ ├── expr-132 │ ├── expr-133 │ ├── expr-134 │ ├── expr-135 │ ├── expr-136 │ ├── expr-137 │ ├── expr-138 │ ├── expr-139 │ ├── expr-14 │ ├── expr-140 │ ├── expr-141 │ ├── expr-142 │ ├── expr-143 │ ├── expr-144 │ ├── expr-145 │ ├── expr-146 │ ├── expr-147 │ ├── expr-148 │ ├── expr-149 │ ├── expr-15 │ ├── expr-150 │ ├── expr-151 │ ├── expr-152 │ ├── expr-153 │ ├── expr-155 │ ├── expr-156 │ ├── expr-157 │ ├── expr-158 │ ├── expr-159 │ ├── expr-16 │ ├── expr-160 │ ├── expr-161 │ ├── expr-162 │ ├── expr-163 │ ├── expr-164 │ ├── expr-165 │ ├── expr-166 │ ├── expr-167 │ ├── expr-168 │ ├── expr-169 │ ├── expr-17 │ ├── expr-170 │ ├── expr-171 │ ├── expr-172 │ ├── expr-173 │ ├── expr-174 │ ├── expr-175 │ ├── expr-178 │ ├── expr-179 │ ├── expr-18 │ ├── expr-180 │ ├── expr-181 │ ├── expr-182 │ ├── expr-183 │ ├── expr-184 │ ├── expr-185 │ ├── expr-186 │ ├── expr-187 │ ├── expr-188 │ ├── expr-189 │ ├── expr-19 │ ├── expr-190 │ ├── expr-191 │ ├── expr-192 │ ├── expr-193 │ ├── expr-194 │ ├── expr-195 │ ├── expr-196 │ ├── expr-198 │ ├── expr-199 │ ├── expr-2 │ ├── expr-20 │ ├── expr-200 │ ├── expr-201 │ ├── expr-202 │ ├── expr-203 │ ├── expr-204 │ ├── expr-205 │ ├── expr-206 │ ├── expr-207 │ ├── expr-208 │ ├── expr-209 │ ├── expr-21 │ ├── expr-210 │ ├── expr-211 │ ├── expr-212 │ ├── expr-213 │ ├── expr-214 │ ├── expr-215 │ ├── expr-216 │ ├── expr-217 │ ├── expr-218 │ ├── expr-219 │ ├── expr-22 │ ├── expr-220 │ ├── expr-221 │ ├── expr-222 │ ├── expr-223 │ ├── expr-224 │ ├── expr-225 │ ├── expr-226 │ ├── expr-227 │ ├── expr-228 │ ├── expr-229 │ ├── expr-23 │ ├── expr-230 │ ├── expr-231 │ ├── expr-232 │ ├── expr-233 │ ├── expr-234 │ ├── expr-235 │ ├── expr-236 │ ├── expr-237 │ ├── expr-238 │ ├── expr-239 │ ├── expr-24 │ ├── expr-240 │ ├── expr-241 │ ├── expr-242 │ ├── expr-243 │ ├── expr-244 │ ├── expr-245 │ ├── expr-246 │ ├── expr-247 │ ├── expr-248 │ ├── expr-249 │ ├── expr-25 │ ├── expr-250 │ ├── expr-251 │ ├── expr-252 │ ├── expr-253 │ ├── expr-254 │ ├── expr-255 │ ├── expr-256 │ ├── expr-257 │ ├── expr-258 │ ├── expr-259 │ ├── expr-26 │ ├── expr-260 │ ├── expr-261 │ ├── expr-262 │ ├── expr-263 │ ├── expr-264 │ ├── expr-265 │ ├── expr-266 │ ├── expr-267 │ ├── expr-268 │ ├── expr-269 │ ├── expr-27 │ ├── expr-270 │ ├── expr-271 │ ├── expr-272 │ ├── expr-273 │ ├── expr-274 │ ├── expr-275 │ ├── expr-276 │ ├── expr-277 │ ├── expr-278 │ ├── expr-279 │ ├── expr-28 │ ├── expr-280 │ ├── expr-281 │ ├── expr-282 │ ├── expr-283 │ ├── expr-284 │ ├── expr-285 │ ├── expr-286 │ ├── expr-287 │ ├── expr-288 │ ├── expr-289 │ ├── expr-29 │ ├── expr-290 │ ├── expr-291 │ ├── expr-292 │ ├── expr-293 │ ├── expr-294 │ ├── expr-295 │ ├── expr-296 │ ├── expr-297 │ ├── expr-298 │ ├── expr-299 │ ├── expr-3 │ ├── expr-30 │ ├── expr-300 │ ├── expr-301 │ ├── expr-302 │ ├── expr-303 │ ├── expr-304 │ ├── expr-305 │ ├── expr-306 │ ├── expr-307 │ ├── expr-308 │ ├── expr-309 │ ├── expr-31 │ ├── expr-310 │ ├── expr-311 │ ├── expr-312 │ ├── expr-313 │ ├── expr-314 │ ├── expr-315 │ ├── expr-316 │ ├── expr-317 │ ├── expr-318 │ ├── expr-319 │ ├── expr-32 │ ├── expr-320 │ ├── expr-321 │ ├── expr-322 │ ├── expr-323 │ ├── expr-324 │ ├── expr-325 │ ├── expr-326 │ ├── expr-327 │ ├── expr-328 │ ├── expr-329 │ ├── expr-33 │ ├── expr-330 │ ├── expr-331 │ ├── expr-332 │ ├── expr-333 │ ├── expr-334 │ ├── expr-335 │ ├── expr-336 │ ├── expr-337 │ ├── expr-338 │ ├── expr-339 │ ├── expr-34 │ ├── expr-340 │ ├── expr-341 │ ├── expr-342 │ ├── expr-343 │ ├── expr-344 │ ├── expr-345 │ ├── expr-346 │ ├── expr-347 │ ├── expr-348 │ ├── expr-349 │ ├── expr-35 │ ├── expr-350 │ ├── expr-351 │ ├── expr-352 │ ├── expr-353 │ ├── expr-354 │ ├── expr-355 │ ├── expr-356 │ ├── expr-357 │ ├── expr-358 │ ├── expr-359 │ ├── expr-36 │ ├── expr-360 │ ├── expr-361 │ ├── expr-362 │ ├── expr-363 │ ├── expr-364 │ ├── expr-365 │ ├── expr-366 │ ├── expr-367 │ ├── expr-368 │ ├── expr-369 │ ├── expr-37 │ ├── expr-370 │ ├── expr-371 │ ├── expr-372 │ ├── expr-373 │ ├── expr-374 │ ├── expr-375 │ ├── expr-376 │ ├── expr-377 │ ├── expr-378 │ ├── expr-379 │ ├── expr-38 │ ├── expr-380 │ ├── expr-381 │ ├── expr-382 │ ├── expr-383 │ ├── expr-384 │ ├── expr-385 │ ├── expr-386 │ ├── expr-387 │ ├── expr-388 │ ├── expr-389 │ ├── expr-39 │ ├── expr-390 │ ├── expr-391 │ ├── expr-392 │ ├── expr-393 │ ├── expr-394 │ ├── expr-395 │ ├── expr-396 │ ├── expr-397 │ ├── expr-398 │ ├── expr-399 │ ├── expr-4 │ ├── expr-40 │ ├── expr-400 │ ├── expr-401 │ ├── expr-402 │ ├── expr-403 │ ├── expr-404 │ ├── expr-405 │ ├── expr-406 │ ├── expr-407 │ ├── expr-408 │ ├── expr-409 │ ├── expr-41 │ ├── expr-410 │ ├── expr-411 │ ├── expr-412 │ ├── expr-413 │ ├── expr-414 │ ├── expr-415 │ ├── expr-416 │ ├── expr-417 │ ├── expr-418 │ ├── expr-419 │ ├── expr-42 │ ├── expr-420 │ ├── expr-421 │ ├── expr-422 │ ├── expr-423 │ ├── expr-424 │ ├── expr-425 │ ├── expr-426 │ ├── expr-427 │ ├── expr-428 │ ├── expr-429 │ ├── expr-43 │ ├── expr-430 │ ├── expr-431 │ ├── expr-432 │ ├── expr-433 │ ├── expr-434 │ ├── expr-435 │ ├── expr-436 │ ├── expr-437 │ ├── expr-438 │ ├── expr-439 │ ├── expr-44 │ ├── expr-440 │ ├── expr-441 │ ├── expr-442 │ ├── expr-443 │ ├── expr-444 │ ├── expr-445 │ ├── expr-446 │ ├── expr-447 │ ├── expr-448 │ ├── expr-449 │ ├── expr-45 │ ├── expr-450 │ ├── expr-451 │ ├── expr-452 │ ├── expr-453 │ ├── expr-454 │ ├── expr-455 │ ├── expr-456 │ ├── expr-457 │ ├── expr-458 │ ├── expr-459 │ ├── expr-46 │ ├── expr-460 │ ├── expr-461 │ ├── expr-462 │ ├── expr-463 │ ├── expr-464 │ ├── expr-465 │ ├── expr-466 │ ├── expr-467 │ ├── expr-468 │ ├── expr-469 │ ├── expr-47 │ ├── expr-470 │ ├── expr-471 │ ├── expr-472 │ ├── expr-473 │ ├── expr-474 │ ├── expr-475 │ ├── expr-476 │ ├── expr-477 │ ├── expr-478 │ ├── expr-479 │ ├── expr-48 │ ├── expr-480 │ ├── expr-481 │ ├── expr-482 │ ├── expr-483 │ ├── expr-484 │ ├── expr-485 │ ├── expr-486 │ ├── expr-487 │ ├── expr-488 │ ├── expr-489 │ ├── expr-49 │ ├── expr-490 │ ├── expr-491 │ ├── expr-492 │ ├── expr-493 │ ├── expr-494 │ ├── expr-495 │ ├── expr-496 │ ├── expr-497 │ ├── expr-498 │ ├── expr-499 │ ├── expr-5 │ ├── expr-50 │ ├── expr-500 │ ├── expr-501 │ ├── expr-502 │ ├── expr-503 │ ├── expr-504 │ ├── expr-505 │ ├── expr-506 │ ├── expr-507 │ ├── expr-508 │ ├── expr-509 │ ├── expr-51 │ ├── expr-510 │ ├── expr-511 │ ├── expr-512 │ ├── expr-513 │ ├── expr-514 │ ├── expr-515 │ ├── expr-516 │ ├── expr-517 │ ├── expr-518 │ ├── expr-519 │ ├── expr-52 │ ├── expr-520 │ ├── expr-521 │ ├── expr-522 │ ├── expr-523 │ ├── expr-524 │ ├── expr-525 │ ├── expr-526 │ ├── expr-527 │ ├── expr-528 │ ├── expr-529 │ ├── expr-53 │ ├── expr-530 │ ├── expr-531 │ ├── expr-532 │ ├── expr-533 │ ├── expr-534 │ ├── expr-535 │ ├── expr-536 │ ├── expr-537 │ ├── expr-538 │ ├── expr-539 │ ├── expr-54 │ ├── expr-540 │ ├── expr-541 │ ├── expr-542 │ ├── expr-543 │ ├── expr-544 │ ├── expr-545 │ ├── expr-546 │ ├── expr-547 │ ├── expr-548 │ ├── expr-549 │ ├── expr-55 │ ├── expr-550 │ ├── expr-551 │ ├── expr-552 │ ├── expr-553 │ ├── expr-554 │ ├── expr-555 │ ├── expr-556 │ ├── expr-557 │ ├── expr-558 │ ├── expr-559 │ ├── expr-56 │ ├── expr-560 │ ├── expr-561 │ ├── expr-562 │ ├── expr-563 │ ├── expr-564 │ ├── expr-565 │ ├── expr-566 │ ├── expr-567 │ ├── expr-568 │ ├── expr-569 │ ├── expr-57 │ ├── expr-570 │ ├── expr-571 │ ├── expr-572 │ ├── expr-573 │ ├── expr-574 │ ├── expr-575 │ ├── expr-576 │ ├── expr-577 │ ├── expr-578 │ ├── expr-579 │ ├── expr-58 │ ├── expr-580 │ ├── expr-581 │ ├── expr-582 │ ├── expr-583 │ ├── expr-584 │ ├── expr-585 │ ├── expr-586 │ ├── expr-587 │ ├── expr-588 │ ├── expr-589 │ ├── expr-59 │ ├── expr-590 │ ├── expr-591 │ ├── expr-592 │ ├── expr-593 │ ├── expr-594 │ ├── expr-595 │ ├── expr-596 │ ├── expr-597 │ ├── expr-598 │ ├── expr-599 │ ├── expr-6 │ ├── expr-60 │ ├── expr-600 │ ├── expr-601 │ ├── expr-602 │ ├── expr-603 │ ├── expr-604 │ ├── expr-605 │ ├── expr-606 │ ├── expr-607 │ ├── expr-608 │ ├── expr-609 │ ├── expr-61 │ ├── expr-610 │ ├── expr-611 │ ├── expr-612 │ ├── expr-613 │ ├── expr-614 │ ├── expr-615 │ ├── expr-616 │ ├── expr-617 │ ├── expr-618 │ ├── expr-619 │ ├── expr-62 │ ├── expr-620 │ ├── expr-621 │ ├── expr-622 │ ├── expr-623 │ ├── expr-624 │ ├── expr-625 │ ├── expr-626 │ ├── expr-627 │ ├── expr-628 │ ├── expr-629 │ ├── expr-63 │ ├── expr-630 │ ├── expr-631 │ ├── expr-632 │ ├── expr-633 │ ├── expr-634 │ ├── expr-635 │ ├── expr-636 │ ├── expr-637 │ ├── expr-638 │ ├── expr-639 │ ├── expr-64 │ ├── expr-640 │ ├── expr-641 │ ├── expr-642 │ ├── expr-643 │ ├── expr-644 │ ├── expr-645 │ ├── expr-646 │ ├── expr-647 │ ├── expr-648 │ ├── expr-649 │ ├── expr-65 │ ├── expr-650 │ ├── expr-651 │ ├── expr-652 │ ├── expr-653 │ ├── expr-654 │ ├── expr-655 │ ├── expr-656 │ ├── expr-66 │ ├── expr-67 │ ├── expr-68 │ ├── expr-69 │ ├── expr-7 │ ├── expr-70 │ ├── expr-71 │ ├── expr-72 │ ├── expr-73 │ ├── expr-74 │ ├── expr-75 │ ├── expr-76 │ ├── expr-77 │ ├── expr-78 │ ├── expr-79 │ ├── expr-8 │ ├── expr-80 │ ├── expr-81 │ ├── expr-82 │ ├── expr-83 │ ├── expr-84 │ ├── expr-85 │ ├── expr-86 │ ├── expr-87 │ ├── expr-88 │ ├── expr-89 │ ├── expr-9 │ ├── expr-90 │ ├── expr-91 │ ├── expr-92 │ ├── expr-93 │ ├── expr-94 │ ├── expr-95 │ ├── expr-96 │ ├── expr-97 │ └── expr-98 ├── go.mod ├── go.sum ├── internal └── testify │ ├── .gitignore │ ├── .travis.gofmt.sh │ ├── .travis.gogenerate.sh │ ├── .travis.govet.sh │ ├── .travis.yml │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── MAINTAINERS.md │ ├── README.md │ ├── _codegen │ ├── .gitignore │ ├── go.mod │ ├── go.sum │ └── main.go │ ├── assert │ ├── assertion_format.go │ ├── assertion_format.go.tmpl │ ├── assertion_forward.go │ ├── assertion_forward.go.tmpl │ ├── assertion_order.go │ ├── assertion_order_test.go │ ├── assertions.go │ ├── assertions_test.go │ ├── doc.go │ ├── errors.go │ ├── forward_assertions.go │ ├── forward_assertions_test.go │ ├── http_assertions.go │ └── http_assertions_test.go │ ├── doc.go │ ├── go.mod │ ├── go.sum │ ├── http │ ├── doc.go │ ├── test_response_writer.go │ └── test_round_tripper.go │ ├── mock │ ├── doc.go │ ├── mock.go │ └── mock_test.go │ ├── package_test.go │ ├── require │ ├── doc.go │ ├── forward_requirements.go │ ├── forward_requirements_test.go │ ├── require.go │ ├── require.go.tmpl │ ├── require_forward.go │ ├── require_forward.go.tmpl │ ├── requirements.go │ └── requirements_test.go │ └── suite │ ├── doc.go │ ├── interfaces.go │ ├── suite.go │ └── suite_test.go ├── interpreter.go ├── interpreter_test.go ├── lexer.go ├── lexer_test.go ├── parser.go ├── parser_test.go ├── toktype_string.go ├── util.go └── util_test.go /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | pull_request: 6 | jobs: 7 | run-tests: 8 | name: Run Tests 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | go-version: 13 | - 1.18 14 | - 1.17 15 | - 1.16 16 | - 1.15 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up Go 20 | uses: actions/setup-go@v2 21 | with: 22 | go-version: ${{ matrix.go-version }} 23 | - name: Install deps 24 | run: go mod download 25 | - name: Tests 26 | run: make test 27 | - name: Install golint 28 | if: ${{ matrix.go-version == '1.17' }} 29 | run: | 30 | make install-dev-cmds 31 | make check 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /jpgo 2 | jmespath-fuzz.zip 3 | cpu.out 4 | go-jmespath.test 5 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters: 2 | disable: 3 | - structcheck 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | CMD = jpgo 3 | 4 | SRC_PKGS=./ ./cmd/... ./fuzz/... 5 | 6 | help: 7 | @echo "Please use \`make ' where is one of" 8 | @echo " test to run all the tests" 9 | @echo " build to build the library and jp executable" 10 | @echo " generate to run codegen" 11 | 12 | 13 | generate: 14 | go generate ${SRC_PKGS} 15 | 16 | build: 17 | rm -f $(CMD) 18 | go build ${SRC_PKGS} 19 | rm -f cmd/$(CMD)/$(CMD) && cd cmd/$(CMD)/ && go build ./... 20 | mv cmd/$(CMD)/$(CMD) . 21 | 22 | test: build 23 | go test -v ${SRC_PKGS} 24 | 25 | check: 26 | go vet ${SRC_PKGS} 27 | golint ${SRC_PKGS} 28 | golangci-lint run 29 | 30 | htmlc: 31 | go test -coverprofile="/tmp/jpcov" && go tool cover -html="/tmp/jpcov" && unlink /tmp/jpcov 32 | 33 | buildfuzz: 34 | go-fuzz-build github.com/jmespath/go-jmespath/fuzz 35 | 36 | fuzz: buildfuzz 37 | go-fuzz -bin=./jmespath-fuzz.zip -workdir=fuzz/testdata 38 | 39 | bench: 40 | go test -bench . -cpuprofile cpu.out 41 | 42 | pprof-cpu: 43 | go tool pprof ./go-jmespath.test ./cpu.out 44 | 45 | install-dev-cmds: 46 | go install golang.org/x/lint/golint@latest 47 | go install golang.org/x/tools/cmd/stringer@latest 48 | command -v golangci-lint || { curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.46.2; } 49 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | go-jmespath 2 | Copyright 2015 James Saryerwinnie 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-jmespath - A JMESPath implementation in Go 2 | 3 | [![Build Status](https://img.shields.io/travis/jmespath/go-jmespath.svg)](https://travis-ci.org/jmespath/go-jmespath) 4 | 5 | 6 | 7 | go-jmespath is a GO implementation of JMESPath, 8 | which is a query language for JSON. It will take a JSON 9 | document and transform it into another JSON document 10 | through a JMESPath expression. 11 | 12 | Using go-jmespath is really easy. There's a single function 13 | you use, `jmespath.search`: 14 | 15 | 16 | ```go 17 | > import "github.com/jmespath/go-jmespath" 18 | > 19 | > var jsondata = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) // your data 20 | > var data interface{} 21 | > err := json.Unmarshal(jsondata, &data) 22 | > result, err := jmespath.Search("foo.bar.baz[2]", data) 23 | result = 2 24 | ``` 25 | 26 | In the example we gave the ``search`` function input data of 27 | `{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}` as well as the JMESPath 28 | expression `foo.bar.baz[2]`, and the `search` function evaluated 29 | the expression against the input data to produce the result ``2``. 30 | 31 | The JMESPath language can do a lot more than select an element 32 | from a list. Here are a few more examples: 33 | 34 | ```go 35 | > var jsondata = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) // your data 36 | > var data interface{} 37 | > err := json.Unmarshal(jsondata, &data) 38 | > result, err := jmespath.search("foo.bar", data) 39 | result = { "baz": [ 0, 1, 2, 3, 4 ] } 40 | 41 | 42 | > var jsondata = []byte(`{"foo": [{"first": "a", "last": "b"}, 43 | {"first": "c", "last": "d"}]}`) // your data 44 | > var data interface{} 45 | > err := json.Unmarshal(jsondata, &data) 46 | > result, err := jmespath.search({"foo[*].first", data) 47 | result [ 'a', 'c' ] 48 | 49 | 50 | > var jsondata = []byte(`{"foo": [{"age": 20}, {"age": 25}, 51 | {"age": 30}, {"age": 35}, 52 | {"age": 40}]}`) // your data 53 | > var data interface{} 54 | > err := json.Unmarshal(jsondata, &data) 55 | > result, err := jmespath.search("foo[?age > `30`]") 56 | result = [ { age: 35 }, { age: 40 } ] 57 | ``` 58 | 59 | You can also pre-compile your query. This is usefull if 60 | you are going to run multiple searches with it: 61 | 62 | ```go 63 | > var jsondata = []byte(`{"foo": "bar"}`) 64 | > var data interface{} 65 | > err := json.Unmarshal(jsondata, &data) 66 | > precompiled, err := Compile("foo") 67 | > if err != nil{ 68 | > // ... handle the error 69 | > } 70 | > result, err := precompiled.Search(data) 71 | result = "bar" 72 | ``` 73 | 74 | ## More Resources 75 | 76 | The example above only show a small amount of what 77 | a JMESPath expression can do. If you want to take a 78 | tour of the language, the *best* place to go is the 79 | [JMESPath Tutorial](http://jmespath.org/tutorial.html). 80 | 81 | One of the best things about JMESPath is that it is 82 | implemented in many different programming languages including 83 | python, ruby, php, lua, etc. To see a complete list of libraries, 84 | check out the [JMESPath libraries page](http://jmespath.org/libraries.html). 85 | 86 | And finally, the full JMESPath specification can be found 87 | on the [JMESPath site](http://jmespath.org/specification.html). 88 | -------------------------------------------------------------------------------- /api.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import "strconv" 4 | 5 | // JMESPath is the representation of a compiled JMES path query. A JMESPath is 6 | // safe for concurrent use by multiple goroutines. 7 | type JMESPath struct { 8 | ast ASTNode 9 | intr *treeInterpreter 10 | } 11 | 12 | // Compile parses a JMESPath expression and returns, if successful, a JMESPath 13 | // object that can be used to match against data. 14 | func Compile(expression string) (*JMESPath, error) { 15 | parser := NewParser() 16 | ast, err := parser.Parse(expression) 17 | if err != nil { 18 | return nil, err 19 | } 20 | jmespath := &JMESPath{ast: ast, intr: newInterpreter()} 21 | return jmespath, nil 22 | } 23 | 24 | // MustCompile is like Compile but panics if the expression cannot be parsed. 25 | // It simplifies safe initialization of global variables holding compiled 26 | // JMESPaths. 27 | func MustCompile(expression string) *JMESPath { 28 | jmespath, err := Compile(expression) 29 | if err != nil { 30 | panic(`jmespath: Compile(` + strconv.Quote(expression) + `): ` + err.Error()) 31 | } 32 | return jmespath 33 | } 34 | 35 | // Search evaluates a JMESPath expression against input data and returns the result. 36 | func (jp *JMESPath) Search(data interface{}) (interface{}, error) { 37 | return jp.intr.Execute(jp.ast, data) 38 | } 39 | 40 | // Search evaluates a JMESPath expression against input data and returns the result. 41 | func Search(expression string, data interface{}) (interface{}, error) { 42 | intr := newInterpreter() 43 | parser := NewParser() 44 | ast, err := parser.Parse(expression) 45 | if err != nil { 46 | return nil, err 47 | } 48 | return intr.Execute(ast, data) 49 | } 50 | -------------------------------------------------------------------------------- /api_test.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import ( 4 | "encoding/json" 5 | "testing" 6 | 7 | "github.com/jmespath/go-jmespath/internal/testify/assert" 8 | ) 9 | 10 | func TestValidUncompiledExpressionSearches(t *testing.T) { 11 | assert := assert.New(t) 12 | var j = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) 13 | var d interface{} 14 | err := json.Unmarshal(j, &d) 15 | assert.Nil(err) 16 | result, err := Search("foo.bar.baz[2]", d) 17 | assert.Nil(err) 18 | assert.Equal(2.0, result) 19 | } 20 | 21 | func TestValidPrecompiledExpressionSearches(t *testing.T) { 22 | assert := assert.New(t) 23 | data := make(map[string]interface{}) 24 | data["foo"] = "bar" 25 | precompiled, err := Compile("foo") 26 | assert.Nil(err) 27 | result, err := precompiled.Search(data) 28 | assert.Nil(err) 29 | assert.Equal("bar", result) 30 | } 31 | 32 | func TestInvalidPrecompileErrors(t *testing.T) { 33 | assert := assert.New(t) 34 | _, err := Compile("not a valid expression") 35 | assert.NotNil(err) 36 | } 37 | 38 | func TestInvalidMustCompilePanics(t *testing.T) { 39 | defer func() { 40 | r := recover() 41 | assert.NotNil(t, r) 42 | }() 43 | MustCompile("not a valid expression") 44 | } 45 | -------------------------------------------------------------------------------- /astnodetype_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type astNodeType"; DO NOT EDIT. 2 | 3 | package jmespath 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ASTEmpty-0] 12 | _ = x[ASTComparator-1] 13 | _ = x[ASTCurrentNode-2] 14 | _ = x[ASTExpRef-3] 15 | _ = x[ASTFunctionExpression-4] 16 | _ = x[ASTField-5] 17 | _ = x[ASTFilterProjection-6] 18 | _ = x[ASTFlatten-7] 19 | _ = x[ASTIdentity-8] 20 | _ = x[ASTIndex-9] 21 | _ = x[ASTIndexExpression-10] 22 | _ = x[ASTKeyValPair-11] 23 | _ = x[ASTLiteral-12] 24 | _ = x[ASTMultiSelectHash-13] 25 | _ = x[ASTMultiSelectList-14] 26 | _ = x[ASTOrExpression-15] 27 | _ = x[ASTAndExpression-16] 28 | _ = x[ASTNotExpression-17] 29 | _ = x[ASTPipe-18] 30 | _ = x[ASTProjection-19] 31 | _ = x[ASTSubexpression-20] 32 | _ = x[ASTSlice-21] 33 | _ = x[ASTValueProjection-22] 34 | } 35 | 36 | const _astNodeType_name = "ASTEmptyASTComparatorASTCurrentNodeASTExpRefASTFunctionExpressionASTFieldASTFilterProjectionASTFlattenASTIdentityASTIndexASTIndexExpressionASTKeyValPairASTLiteralASTMultiSelectHashASTMultiSelectListASTOrExpressionASTAndExpressionASTNotExpressionASTPipeASTProjectionASTSubexpressionASTSliceASTValueProjection" 37 | 38 | var _astNodeType_index = [...]uint16{0, 8, 21, 35, 44, 65, 73, 92, 102, 113, 121, 139, 152, 162, 180, 198, 213, 229, 245, 252, 265, 281, 289, 307} 39 | 40 | func (i astNodeType) String() string { 41 | if i < 0 || i >= astNodeType(len(_astNodeType_index)-1) { 42 | return "astNodeType(" + strconv.FormatInt(int64(i), 10) + ")" 43 | } 44 | return _astNodeType_name[_astNodeType_index[i]:_astNodeType_index[i+1]] 45 | } 46 | -------------------------------------------------------------------------------- /cmd/jpgo/main.go: -------------------------------------------------------------------------------- 1 | /*Basic command line interface for debug and testing purposes. 2 | 3 | Examples: 4 | 5 | Only print the AST for the expression: 6 | 7 | jp.go -ast "foo.bar.baz" 8 | 9 | Evaluate the JMESPath expression against JSON data from a file: 10 | 11 | jp.go -input /tmp/data.json "foo.bar.baz" 12 | 13 | This program can also be used as an executable to the jp-compliance 14 | runner (github.com/jmespath/jmespath.test). 15 | 16 | */ 17 | package main 18 | 19 | import ( 20 | "flag" 21 | "fmt" 22 | "io/ioutil" 23 | "os" 24 | ) 25 | 26 | import ( 27 | "encoding/json" 28 | 29 | "github.com/jmespath/go-jmespath" 30 | ) 31 | 32 | func errMsg(msg string, a ...interface{}) int { 33 | fmt.Fprintf(os.Stderr, msg, a...) 34 | fmt.Fprintln(os.Stderr) 35 | return 1 36 | } 37 | 38 | func run() int { 39 | 40 | astOnly := flag.Bool("ast", false, "Print the AST for the input expression and exit.") 41 | inputFile := flag.String("input", "", "Filename containing JSON data to search. If not provided, data is read from stdin.") 42 | 43 | flag.Parse() 44 | args := flag.Args() 45 | if len(args) != 1 { 46 | fmt.Fprintf(os.Stderr, "Usage:\n\n") 47 | flag.PrintDefaults() 48 | return errMsg("\nError: expected a single argument (the JMESPath expression).") 49 | } 50 | 51 | expression := args[0] 52 | parser := jmespath.NewParser() 53 | parsed, err := parser.Parse(expression) 54 | if err != nil { 55 | if syntaxError, ok := err.(jmespath.SyntaxError); ok { 56 | return errMsg("%s\n%s\n", syntaxError, syntaxError.HighlightLocation()) 57 | } 58 | return errMsg("%s", err) 59 | } 60 | if *astOnly { 61 | fmt.Println("") 62 | fmt.Printf("%s\n", parsed) 63 | return 0 64 | } 65 | 66 | var inputData []byte 67 | if *inputFile != "" { 68 | inputData, err = ioutil.ReadFile(*inputFile) 69 | if err != nil { 70 | return errMsg("Error loading file %s: %s", *inputFile, err) 71 | } 72 | } else { 73 | // If an input data file is not provided then we read the 74 | // data from stdin. 75 | inputData, err = ioutil.ReadAll(os.Stdin) 76 | if err != nil { 77 | return errMsg("Error reading from stdin: %s", err) 78 | } 79 | } 80 | var data interface{} 81 | if err := json.Unmarshal(inputData, &data); err != nil { 82 | return errMsg("Invalid input JSON: %s", err) 83 | } 84 | result, err := jmespath.Search(expression, data) 85 | if err != nil { 86 | return errMsg("Error executing expression: %s", err) 87 | } 88 | toJSON, err := json.MarshalIndent(result, "", " ") 89 | if err != nil { 90 | return errMsg("Error serializing result to JSON: %s", err) 91 | } 92 | fmt.Println(string(toJSON)) 93 | return 0 94 | } 95 | 96 | func main() { 97 | os.Exit(run()) 98 | } 99 | -------------------------------------------------------------------------------- /compliance/basic.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "given": 3 | {"foo": {"bar": {"baz": "correct"}}}, 4 | "cases": [ 5 | { 6 | "expression": "foo", 7 | "result": {"bar": {"baz": "correct"}} 8 | }, 9 | { 10 | "expression": "foo.bar", 11 | "result": {"baz": "correct"} 12 | }, 13 | { 14 | "expression": "foo.bar.baz", 15 | "result": "correct" 16 | }, 17 | { 18 | "expression": "foo\n.\nbar\n.baz", 19 | "result": "correct" 20 | }, 21 | { 22 | "expression": "foo.bar.baz.bad", 23 | "result": null 24 | }, 25 | { 26 | "expression": "foo.bar.bad", 27 | "result": null 28 | }, 29 | { 30 | "expression": "foo.bad", 31 | "result": null 32 | }, 33 | { 34 | "expression": "bad", 35 | "result": null 36 | }, 37 | { 38 | "expression": "bad.morebad.morebad", 39 | "result": null 40 | } 41 | ] 42 | }, 43 | { 44 | "given": 45 | {"foo": {"bar": ["one", "two", "three"]}}, 46 | "cases": [ 47 | { 48 | "expression": "foo", 49 | "result": {"bar": ["one", "two", "three"]} 50 | }, 51 | { 52 | "expression": "foo.bar", 53 | "result": ["one", "two", "three"] 54 | } 55 | ] 56 | }, 57 | { 58 | "given": ["one", "two", "three"], 59 | "cases": [ 60 | { 61 | "expression": "one", 62 | "result": null 63 | }, 64 | { 65 | "expression": "two", 66 | "result": null 67 | }, 68 | { 69 | "expression": "three", 70 | "result": null 71 | }, 72 | { 73 | "expression": "one.two", 74 | "result": null 75 | } 76 | ] 77 | }, 78 | { 79 | "given": 80 | {"foo": {"1": ["one", "two", "three"], "-1": "bar"}}, 81 | "cases": [ 82 | { 83 | "expression": "foo.\"1\"", 84 | "result": ["one", "two", "three"] 85 | }, 86 | { 87 | "expression": "foo.\"1\"[0]", 88 | "result": "one" 89 | }, 90 | { 91 | "expression": "foo.\"-1\"", 92 | "result": "bar" 93 | } 94 | ] 95 | } 96 | ] 97 | -------------------------------------------------------------------------------- /compliance/current.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "given": { 4 | "foo": [{"name": "a"}, {"name": "b"}], 5 | "bar": {"baz": "qux"} 6 | }, 7 | "cases": [ 8 | { 9 | "expression": "@", 10 | "result": { 11 | "foo": [{"name": "a"}, {"name": "b"}], 12 | "bar": {"baz": "qux"} 13 | } 14 | }, 15 | { 16 | "expression": "@.bar", 17 | "result": {"baz": "qux"} 18 | }, 19 | { 20 | "expression": "@.foo[0]", 21 | "result": {"name": "a"} 22 | } 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /compliance/escape.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "given": { 3 | "foo.bar": "dot", 4 | "foo bar": "space", 5 | "foo\nbar": "newline", 6 | "foo\"bar": "doublequote", 7 | "c:\\\\windows\\path": "windows", 8 | "/unix/path": "unix", 9 | "\"\"\"": "threequotes", 10 | "bar": {"baz": "qux"} 11 | }, 12 | "cases": [ 13 | { 14 | "expression": "\"foo.bar\"", 15 | "result": "dot" 16 | }, 17 | { 18 | "expression": "\"foo bar\"", 19 | "result": "space" 20 | }, 21 | { 22 | "expression": "\"foo\\nbar\"", 23 | "result": "newline" 24 | }, 25 | { 26 | "expression": "\"foo\\\"bar\"", 27 | "result": "doublequote" 28 | }, 29 | { 30 | "expression": "\"c:\\\\\\\\windows\\\\path\"", 31 | "result": "windows" 32 | }, 33 | { 34 | "expression": "\"/unix/path\"", 35 | "result": "unix" 36 | }, 37 | { 38 | "expression": "\"\\\"\\\"\\\"\"", 39 | "result": "threequotes" 40 | }, 41 | { 42 | "expression": "\"bar\".\"baz\"", 43 | "result": "qux" 44 | } 45 | ] 46 | }] 47 | -------------------------------------------------------------------------------- /compliance/literal.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "given": { 4 | "foo": [{"name": "a"}, {"name": "b"}], 5 | "bar": {"baz": "qux"} 6 | }, 7 | "cases": [ 8 | { 9 | "expression": "`\"foo\"`", 10 | "result": "foo" 11 | }, 12 | { 13 | "comment": "Interpret escaped unicode.", 14 | "expression": "`\"\\u03a6\"`", 15 | "result": "Φ" 16 | }, 17 | { 18 | "expression": "`\"✓\"`", 19 | "result": "✓" 20 | }, 21 | { 22 | "expression": "`[1, 2, 3]`", 23 | "result": [1, 2, 3] 24 | }, 25 | { 26 | "expression": "`{\"a\": \"b\"}`", 27 | "result": {"a": "b"} 28 | }, 29 | { 30 | "expression": "`true`", 31 | "result": true 32 | }, 33 | { 34 | "expression": "`false`", 35 | "result": false 36 | }, 37 | { 38 | "expression": "`null`", 39 | "result": null 40 | }, 41 | { 42 | "expression": "`0`", 43 | "result": 0 44 | }, 45 | { 46 | "expression": "`1`", 47 | "result": 1 48 | }, 49 | { 50 | "expression": "`2`", 51 | "result": 2 52 | }, 53 | { 54 | "expression": "`3`", 55 | "result": 3 56 | }, 57 | { 58 | "expression": "`4`", 59 | "result": 4 60 | }, 61 | { 62 | "expression": "`5`", 63 | "result": 5 64 | }, 65 | { 66 | "expression": "`6`", 67 | "result": 6 68 | }, 69 | { 70 | "expression": "`7`", 71 | "result": 7 72 | }, 73 | { 74 | "expression": "`8`", 75 | "result": 8 76 | }, 77 | { 78 | "expression": "`9`", 79 | "result": 9 80 | }, 81 | { 82 | "comment": "Escaping a backtick in quotes", 83 | "expression": "`\"foo\\`bar\"`", 84 | "result": "foo`bar" 85 | }, 86 | { 87 | "comment": "Double quote in literal", 88 | "expression": "`\"foo\\\"bar\"`", 89 | "result": "foo\"bar" 90 | }, 91 | { 92 | "expression": "`\"1\\`\"`", 93 | "result": "1`" 94 | }, 95 | { 96 | "comment": "Multiple literal expressions with escapes", 97 | "expression": "`\"\\\\\"`.{a:`\"b\"`}", 98 | "result": {"a": "b"} 99 | }, 100 | { 101 | "comment": "literal . identifier", 102 | "expression": "`{\"a\": \"b\"}`.a", 103 | "result": "b" 104 | }, 105 | { 106 | "comment": "literal . identifier . identifier", 107 | "expression": "`{\"a\": {\"b\": \"c\"}}`.a.b", 108 | "result": "c" 109 | }, 110 | { 111 | "comment": "literal . identifier bracket-expr", 112 | "expression": "`[0, 1, 2]`[1]", 113 | "result": 1 114 | } 115 | ] 116 | }, 117 | { 118 | "comment": "Literals", 119 | "given": {"type": "object"}, 120 | "cases": [ 121 | { 122 | "comment": "Literal with leading whitespace", 123 | "expression": "` {\"foo\": true}`", 124 | "result": {"foo": true} 125 | }, 126 | { 127 | "comment": "Literal with trailing whitespace", 128 | "expression": "`{\"foo\": true} `", 129 | "result": {"foo": true} 130 | }, 131 | { 132 | "comment": "Literal on RHS of subexpr not allowed", 133 | "expression": "foo.`\"bar\"`", 134 | "error": "syntax" 135 | } 136 | ] 137 | }, 138 | { 139 | "comment": "Raw String Literals", 140 | "given": {}, 141 | "cases": [ 142 | { 143 | "expression": "'foo'", 144 | "result": "foo" 145 | }, 146 | { 147 | "expression": "' foo '", 148 | "result": " foo " 149 | }, 150 | { 151 | "expression": "'0'", 152 | "result": "0" 153 | }, 154 | { 155 | "expression": "'newline\n'", 156 | "result": "newline\n" 157 | }, 158 | { 159 | "expression": "'\n'", 160 | "result": "\n" 161 | }, 162 | { 163 | "expression": "'✓'", 164 | "result": "✓" 165 | }, 166 | { 167 | "expression": "'𝄞'", 168 | "result": "𝄞" 169 | }, 170 | { 171 | "expression": "' [foo] '", 172 | "result": " [foo] " 173 | }, 174 | { 175 | "expression": "'[foo]'", 176 | "result": "[foo]" 177 | }, 178 | { 179 | "comment": "Do not interpret escaped unicode.", 180 | "expression": "'\\u03a6'", 181 | "result": "\\u03a6" 182 | } 183 | ] 184 | } 185 | ] 186 | -------------------------------------------------------------------------------- /compliance/ormatch.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "given": 3 | {"outer": {"foo": "foo", "bar": "bar", "baz": "baz"}}, 4 | "cases": [ 5 | { 6 | "expression": "outer.foo || outer.bar", 7 | "result": "foo" 8 | }, 9 | { 10 | "expression": "outer.foo||outer.bar", 11 | "result": "foo" 12 | }, 13 | { 14 | "expression": "outer.bar || outer.baz", 15 | "result": "bar" 16 | }, 17 | { 18 | "expression": "outer.bar||outer.baz", 19 | "result": "bar" 20 | }, 21 | { 22 | "expression": "outer.bad || outer.foo", 23 | "result": "foo" 24 | }, 25 | { 26 | "expression": "outer.bad||outer.foo", 27 | "result": "foo" 28 | }, 29 | { 30 | "expression": "outer.foo || outer.bad", 31 | "result": "foo" 32 | }, 33 | { 34 | "expression": "outer.foo||outer.bad", 35 | "result": "foo" 36 | }, 37 | { 38 | "expression": "outer.bad || outer.alsobad", 39 | "result": null 40 | }, 41 | { 42 | "expression": "outer.bad||outer.alsobad", 43 | "result": null 44 | } 45 | ] 46 | }, { 47 | "given": 48 | {"outer": {"foo": "foo", "bool": false, "empty_list": [], "empty_string": ""}}, 49 | "cases": [ 50 | { 51 | "expression": "outer.empty_string || outer.foo", 52 | "result": "foo" 53 | }, 54 | { 55 | "expression": "outer.nokey || outer.bool || outer.empty_list || outer.empty_string || outer.foo", 56 | "result": "foo" 57 | } 58 | ] 59 | }] 60 | -------------------------------------------------------------------------------- /compliance/pipe.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "given": { 3 | "foo": { 4 | "bar": { 5 | "baz": "subkey" 6 | }, 7 | "other": { 8 | "baz": "subkey" 9 | }, 10 | "other2": { 11 | "baz": "subkey" 12 | }, 13 | "other3": { 14 | "notbaz": ["a", "b", "c"] 15 | }, 16 | "other4": { 17 | "notbaz": ["a", "b", "c"] 18 | } 19 | } 20 | }, 21 | "cases": [ 22 | { 23 | "expression": "foo.*.baz | [0]", 24 | "result": "subkey" 25 | }, 26 | { 27 | "expression": "foo.*.baz | [1]", 28 | "result": "subkey" 29 | }, 30 | { 31 | "expression": "foo.*.baz | [2]", 32 | "result": "subkey" 33 | }, 34 | { 35 | "expression": "foo.bar.* | [0]", 36 | "result": "subkey" 37 | }, 38 | { 39 | "expression": "foo.*.notbaz | [*]", 40 | "result": [["a", "b", "c"], ["a", "b", "c"]] 41 | }, 42 | { 43 | "expression": "{\"a\": foo.bar, \"b\": foo.other} | *.baz", 44 | "result": ["subkey", "subkey"] 45 | } 46 | ] 47 | }, { 48 | "given": { 49 | "foo": { 50 | "bar": { 51 | "baz": "one" 52 | }, 53 | "other": { 54 | "baz": "two" 55 | }, 56 | "other2": { 57 | "baz": "three" 58 | }, 59 | "other3": { 60 | "notbaz": ["a", "b", "c"] 61 | }, 62 | "other4": { 63 | "notbaz": ["d", "e", "f"] 64 | } 65 | } 66 | }, 67 | "cases": [ 68 | { 69 | "expression": "foo | bar", 70 | "result": {"baz": "one"} 71 | }, 72 | { 73 | "expression": "foo | bar | baz", 74 | "result": "one" 75 | }, 76 | { 77 | "expression": "foo|bar| baz", 78 | "result": "one" 79 | }, 80 | { 81 | "expression": "not_there | [0]", 82 | "result": null 83 | }, 84 | { 85 | "expression": "not_there | [0]", 86 | "result": null 87 | }, 88 | { 89 | "expression": "[foo.bar, foo.other] | [0]", 90 | "result": {"baz": "one"} 91 | }, 92 | { 93 | "expression": "{\"a\": foo.bar, \"b\": foo.other} | a", 94 | "result": {"baz": "one"} 95 | }, 96 | { 97 | "expression": "{\"a\": foo.bar, \"b\": foo.other} | b", 98 | "result": {"baz": "two"} 99 | }, 100 | { 101 | "expression": "foo.bam || foo.bar | baz", 102 | "result": "one" 103 | }, 104 | { 105 | "expression": "foo | not_there || bar", 106 | "result": {"baz": "one"} 107 | } 108 | ] 109 | }, { 110 | "given": { 111 | "foo": [{ 112 | "bar": [{ 113 | "baz": "one" 114 | }, { 115 | "baz": "two" 116 | }] 117 | }, { 118 | "bar": [{ 119 | "baz": "three" 120 | }, { 121 | "baz": "four" 122 | }] 123 | }] 124 | }, 125 | "cases": [ 126 | { 127 | "expression": "foo[*].bar[*] | [0][0]", 128 | "result": {"baz": "one"} 129 | } 130 | ] 131 | }] 132 | -------------------------------------------------------------------------------- /compliance/slice.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "given": { 3 | "foo": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4 | "bar": { 5 | "baz": 1 6 | } 7 | }, 8 | "cases": [ 9 | { 10 | "expression": "bar[0:10]", 11 | "result": null 12 | }, 13 | { 14 | "expression": "foo[0:10:1]", 15 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 16 | }, 17 | { 18 | "expression": "foo[0:10]", 19 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 20 | }, 21 | { 22 | "expression": "foo[0:10:]", 23 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 24 | }, 25 | { 26 | "expression": "foo[0::1]", 27 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 28 | }, 29 | { 30 | "expression": "foo[0::]", 31 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 32 | }, 33 | { 34 | "expression": "foo[0:]", 35 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 36 | }, 37 | { 38 | "expression": "foo[:10:1]", 39 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 40 | }, 41 | { 42 | "expression": "foo[::1]", 43 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 44 | }, 45 | { 46 | "expression": "foo[:10:]", 47 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 48 | }, 49 | { 50 | "expression": "foo[::]", 51 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 52 | }, 53 | { 54 | "expression": "foo[:]", 55 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 56 | }, 57 | { 58 | "expression": "foo[1:9]", 59 | "result": [1, 2, 3, 4, 5, 6, 7, 8] 60 | }, 61 | { 62 | "expression": "foo[0:10:2]", 63 | "result": [0, 2, 4, 6, 8] 64 | }, 65 | { 66 | "expression": "foo[5:]", 67 | "result": [5, 6, 7, 8, 9] 68 | }, 69 | { 70 | "expression": "foo[5::2]", 71 | "result": [5, 7, 9] 72 | }, 73 | { 74 | "expression": "foo[::2]", 75 | "result": [0, 2, 4, 6, 8] 76 | }, 77 | { 78 | "expression": "foo[::-1]", 79 | "result": [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] 80 | }, 81 | { 82 | "expression": "foo[1::2]", 83 | "result": [1, 3, 5, 7, 9] 84 | }, 85 | { 86 | "expression": "foo[10:0:-1]", 87 | "result": [9, 8, 7, 6, 5, 4, 3, 2, 1] 88 | }, 89 | { 90 | "expression": "foo[10:5:-1]", 91 | "result": [9, 8, 7, 6] 92 | }, 93 | { 94 | "expression": "foo[8:2:-2]", 95 | "result": [8, 6, 4] 96 | }, 97 | { 98 | "expression": "foo[0:20]", 99 | "result": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 100 | }, 101 | { 102 | "expression": "foo[10:-20:-1]", 103 | "result": [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] 104 | }, 105 | { 106 | "expression": "foo[10:-20]", 107 | "result": [] 108 | }, 109 | { 110 | "expression": "foo[-4:-1]", 111 | "result": [6, 7, 8] 112 | }, 113 | { 114 | "expression": "foo[:-5:-1]", 115 | "result": [9, 8, 7, 6] 116 | }, 117 | { 118 | "expression": "foo[8:2:0]", 119 | "error": "invalid-value" 120 | }, 121 | { 122 | "expression": "foo[8:2:0:1]", 123 | "error": "syntax" 124 | }, 125 | { 126 | "expression": "foo[8:2&]", 127 | "error": "syntax" 128 | }, 129 | { 130 | "expression": "foo[2:a:3]", 131 | "error": "syntax" 132 | } 133 | ] 134 | }, { 135 | "given": { 136 | "foo": [{"a": 1}, {"a": 2}, {"a": 3}], 137 | "bar": [{"a": {"b": 1}}, {"a": {"b": 2}}, 138 | {"a": {"b": 3}}], 139 | "baz": 50 140 | }, 141 | "cases": [ 142 | { 143 | "expression": "foo[:2].a", 144 | "result": [1, 2] 145 | }, 146 | { 147 | "expression": "foo[:2].b", 148 | "result": [] 149 | }, 150 | { 151 | "expression": "foo[:2].a.b", 152 | "result": [] 153 | }, 154 | { 155 | "expression": "bar[::-1].a.b", 156 | "result": [3, 2, 1] 157 | }, 158 | { 159 | "expression": "bar[:2].a.b", 160 | "result": [1, 2] 161 | }, 162 | { 163 | "expression": "baz[:2].a", 164 | "result": null 165 | } 166 | ] 167 | }, { 168 | "given": [{"a": 1}, {"a": 2}, {"a": 3}], 169 | "cases": [ 170 | { 171 | "expression": "[:]", 172 | "result": [{"a": 1}, {"a": 2}, {"a": 3}] 173 | }, 174 | { 175 | "expression": "[:2].a", 176 | "result": [1, 2] 177 | }, 178 | { 179 | "expression": "[::-1].a", 180 | "result": [3, 2, 1] 181 | }, 182 | { 183 | "expression": "[:2].b", 184 | "result": [] 185 | } 186 | ] 187 | }] 188 | -------------------------------------------------------------------------------- /compliance/unicode.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "given": {"foo": [{"✓": "✓"}, {"✓": "✗"}]}, 4 | "cases": [ 5 | { 6 | "expression": "foo[].\"✓\"", 7 | "result": ["✓", "✗"] 8 | } 9 | ] 10 | }, 11 | { 12 | "given": {"☯": true}, 13 | "cases": [ 14 | { 15 | "expression": "\"☯\"", 16 | "result": true 17 | } 18 | ] 19 | }, 20 | { 21 | "given": {"♪♫•*¨*•.¸¸❤¸¸.•*¨*•♫♪": true}, 22 | "cases": [ 23 | { 24 | "expression": "\"♪♫•*¨*•.¸¸❤¸¸.•*¨*•♫♪\"", 25 | "result": true 26 | } 27 | ] 28 | }, 29 | { 30 | "given": {"☃": true}, 31 | "cases": [ 32 | { 33 | "expression": "\"☃\"", 34 | "result": true 35 | } 36 | ] 37 | } 38 | ] 39 | -------------------------------------------------------------------------------- /compliance_test.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | "path/filepath" 9 | "testing" 10 | 11 | "github.com/jmespath/go-jmespath/internal/testify/assert" 12 | ) 13 | 14 | type TestSuite struct { 15 | Given interface{} 16 | TestCases []TestCase `json:"cases"` 17 | Comment string 18 | } 19 | type TestCase struct { 20 | Comment string 21 | Expression string 22 | Result interface{} 23 | Error string 24 | } 25 | 26 | var whiteListed = []string{ 27 | "compliance/basic.json", 28 | "compliance/current.json", 29 | "compliance/escape.json", 30 | "compliance/filters.json", 31 | "compliance/functions.json", 32 | "compliance/identifiers.json", 33 | "compliance/indices.json", 34 | "compliance/literal.json", 35 | "compliance/multiselect.json", 36 | "compliance/ormatch.json", 37 | "compliance/pipe.json", 38 | "compliance/slice.json", 39 | "compliance/syntax.json", 40 | "compliance/unicode.json", 41 | "compliance/wildcard.json", 42 | "compliance/boolean.json", 43 | } 44 | 45 | func allowed(path string) bool { 46 | for _, el := range whiteListed { 47 | if el == path { 48 | return true 49 | } 50 | } 51 | return false 52 | } 53 | 54 | func TestCompliance(t *testing.T) { 55 | assert := assert.New(t) 56 | 57 | var complianceFiles []string 58 | err := filepath.Walk("compliance", func(path string, _ os.FileInfo, _ error) error { 59 | //if strings.HasSuffix(path, ".json") { 60 | if allowed(path) { 61 | complianceFiles = append(complianceFiles, path) 62 | } 63 | return nil 64 | }) 65 | if assert.Nil(err) { 66 | for _, filename := range complianceFiles { 67 | runComplianceTest(assert, filename) 68 | } 69 | } 70 | } 71 | 72 | func runComplianceTest(assert *assert.Assertions, filename string) { 73 | var testSuites []TestSuite 74 | data, err := ioutil.ReadFile(filename) 75 | if assert.Nil(err) { 76 | err := json.Unmarshal(data, &testSuites) 77 | if assert.Nil(err) { 78 | for _, testsuite := range testSuites { 79 | runTestSuite(assert, testsuite, filename) 80 | } 81 | } 82 | } 83 | } 84 | 85 | func runTestSuite(assert *assert.Assertions, testsuite TestSuite, filename string) { 86 | for _, testcase := range testsuite.TestCases { 87 | if testcase.Error != "" { 88 | // This is a test case that verifies we error out properly. 89 | runSyntaxTestCase(assert, testsuite.Given, testcase, filename) 90 | } else { 91 | runTestCase(assert, testsuite.Given, testcase, filename) 92 | } 93 | } 94 | } 95 | 96 | func runSyntaxTestCase(assert *assert.Assertions, given interface{}, testcase TestCase, filename string) { 97 | // Anything with an .Error means that we expect that JMESPath should return 98 | // an error when we try to evaluate the expression. 99 | _, err := Search(testcase.Expression, given) 100 | assert.NotNil(err, fmt.Sprintf("Expression: %s", testcase.Expression)) 101 | } 102 | 103 | func runTestCase(assert *assert.Assertions, given interface{}, testcase TestCase, filename string) { 104 | lexer := NewLexer() 105 | var err error 106 | _, err = lexer.tokenize(testcase.Expression) 107 | if err != nil { 108 | errMsg := fmt.Sprintf("(%s) Could not lex expression: %s -- %s", filename, testcase.Expression, err.Error()) 109 | assert.Fail(errMsg) 110 | return 111 | } 112 | parser := NewParser() 113 | _, err = parser.Parse(testcase.Expression) 114 | if err != nil { 115 | errMsg := fmt.Sprintf("(%s) Could not parse expression: %s -- %s", filename, testcase.Expression, err.Error()) 116 | assert.Fail(errMsg) 117 | return 118 | } 119 | actual, err := Search(testcase.Expression, given) 120 | if assert.Nil(err, fmt.Sprintf("Expression: %s", testcase.Expression)) { 121 | assert.Equal(testcase.Result, actual, fmt.Sprintf("Expression: %s", testcase.Expression)) 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /fuzz/jmespath.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import "github.com/jmespath/go-jmespath" 4 | 5 | // Fuzz will fuzz test the JMESPath parser. 6 | func Fuzz(data []byte) int { 7 | p := jmespath.NewParser() 8 | _, err := p.Parse(string(data)) 9 | if err != nil { 10 | return 1 11 | } 12 | return 0 13 | } 14 | -------------------------------------------------------------------------------- /fuzz/testdata/expr-1: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-10: -------------------------------------------------------------------------------- 1 | foo.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-100: -------------------------------------------------------------------------------- 1 | ends_with(str, 'SStr') -------------------------------------------------------------------------------- /fuzz/testdata/expr-101: -------------------------------------------------------------------------------- 1 | ends_with(str, 'foo') -------------------------------------------------------------------------------- /fuzz/testdata/expr-102: -------------------------------------------------------------------------------- 1 | floor(`1.2`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-103: -------------------------------------------------------------------------------- 1 | floor(decimals[0]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-104: -------------------------------------------------------------------------------- 1 | floor(foo) -------------------------------------------------------------------------------- /fuzz/testdata/expr-105: -------------------------------------------------------------------------------- 1 | length('abc') -------------------------------------------------------------------------------- /fuzz/testdata/expr-106: -------------------------------------------------------------------------------- 1 | length('') -------------------------------------------------------------------------------- /fuzz/testdata/expr-107: -------------------------------------------------------------------------------- 1 | length(@) -------------------------------------------------------------------------------- /fuzz/testdata/expr-108: -------------------------------------------------------------------------------- 1 | length(strings[0]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-109: -------------------------------------------------------------------------------- 1 | length(str) -------------------------------------------------------------------------------- /fuzz/testdata/expr-110: -------------------------------------------------------------------------------- 1 | length(array) -------------------------------------------------------------------------------- /fuzz/testdata/expr-112: -------------------------------------------------------------------------------- 1 | length(strings[0]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-115: -------------------------------------------------------------------------------- 1 | max(strings) -------------------------------------------------------------------------------- /fuzz/testdata/expr-118: -------------------------------------------------------------------------------- 1 | merge(`{}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-119: -------------------------------------------------------------------------------- 1 | merge(`{}`, `{}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-12: -------------------------------------------------------------------------------- 1 | two -------------------------------------------------------------------------------- /fuzz/testdata/expr-120: -------------------------------------------------------------------------------- 1 | merge(`{"a": 1}`, `{"b": 2}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-121: -------------------------------------------------------------------------------- 1 | merge(`{"a": 1}`, `{"a": 2}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-122: -------------------------------------------------------------------------------- 1 | merge(`{"a": 1, "b": 2}`, `{"a": 2, "c": 3}`, `{"d": 4}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-123: -------------------------------------------------------------------------------- 1 | min(numbers) -------------------------------------------------------------------------------- /fuzz/testdata/expr-126: -------------------------------------------------------------------------------- 1 | min(decimals) -------------------------------------------------------------------------------- /fuzz/testdata/expr-128: -------------------------------------------------------------------------------- 1 | type('abc') -------------------------------------------------------------------------------- /fuzz/testdata/expr-129: -------------------------------------------------------------------------------- 1 | type(`1.0`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-13: -------------------------------------------------------------------------------- 1 | three -------------------------------------------------------------------------------- /fuzz/testdata/expr-130: -------------------------------------------------------------------------------- 1 | type(`2`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-131: -------------------------------------------------------------------------------- 1 | type(`true`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-132: -------------------------------------------------------------------------------- 1 | type(`false`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-133: -------------------------------------------------------------------------------- 1 | type(`null`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-134: -------------------------------------------------------------------------------- 1 | type(`[0]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-135: -------------------------------------------------------------------------------- 1 | type(`{"a": "b"}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-136: -------------------------------------------------------------------------------- 1 | type(@) -------------------------------------------------------------------------------- /fuzz/testdata/expr-137: -------------------------------------------------------------------------------- 1 | keys(objects) -------------------------------------------------------------------------------- /fuzz/testdata/expr-138: -------------------------------------------------------------------------------- 1 | values(objects) -------------------------------------------------------------------------------- /fuzz/testdata/expr-139: -------------------------------------------------------------------------------- 1 | keys(empty_hash) -------------------------------------------------------------------------------- /fuzz/testdata/expr-14: -------------------------------------------------------------------------------- 1 | one.two -------------------------------------------------------------------------------- /fuzz/testdata/expr-140: -------------------------------------------------------------------------------- 1 | join(', ', strings) -------------------------------------------------------------------------------- /fuzz/testdata/expr-141: -------------------------------------------------------------------------------- 1 | join(', ', strings) -------------------------------------------------------------------------------- /fuzz/testdata/expr-142: -------------------------------------------------------------------------------- 1 | join(',', `["a", "b"]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-143: -------------------------------------------------------------------------------- 1 | join('|', strings) -------------------------------------------------------------------------------- /fuzz/testdata/expr-144: -------------------------------------------------------------------------------- 1 | join('|', decimals[].to_string(@)) -------------------------------------------------------------------------------- /fuzz/testdata/expr-145: -------------------------------------------------------------------------------- 1 | join('|', empty_list) -------------------------------------------------------------------------------- /fuzz/testdata/expr-146: -------------------------------------------------------------------------------- 1 | reverse(numbers) -------------------------------------------------------------------------------- /fuzz/testdata/expr-147: -------------------------------------------------------------------------------- 1 | reverse(array) -------------------------------------------------------------------------------- /fuzz/testdata/expr-148: -------------------------------------------------------------------------------- 1 | reverse(`[]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-149: -------------------------------------------------------------------------------- 1 | reverse('') -------------------------------------------------------------------------------- /fuzz/testdata/expr-15: -------------------------------------------------------------------------------- 1 | foo."1" -------------------------------------------------------------------------------- /fuzz/testdata/expr-150: -------------------------------------------------------------------------------- 1 | reverse('hello world') -------------------------------------------------------------------------------- /fuzz/testdata/expr-151: -------------------------------------------------------------------------------- 1 | starts_with(str, 'S') -------------------------------------------------------------------------------- /fuzz/testdata/expr-152: -------------------------------------------------------------------------------- 1 | starts_with(str, 'St') -------------------------------------------------------------------------------- /fuzz/testdata/expr-153: -------------------------------------------------------------------------------- 1 | starts_with(str, 'Str') -------------------------------------------------------------------------------- /fuzz/testdata/expr-155: -------------------------------------------------------------------------------- 1 | sum(numbers) -------------------------------------------------------------------------------- /fuzz/testdata/expr-156: -------------------------------------------------------------------------------- 1 | sum(decimals) -------------------------------------------------------------------------------- /fuzz/testdata/expr-157: -------------------------------------------------------------------------------- 1 | sum(array[].to_number(@)) -------------------------------------------------------------------------------- /fuzz/testdata/expr-158: -------------------------------------------------------------------------------- 1 | sum(`[]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-159: -------------------------------------------------------------------------------- 1 | to_array('foo') -------------------------------------------------------------------------------- /fuzz/testdata/expr-16: -------------------------------------------------------------------------------- 1 | foo."1"[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-160: -------------------------------------------------------------------------------- 1 | to_array(`0`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-161: -------------------------------------------------------------------------------- 1 | to_array(objects) -------------------------------------------------------------------------------- /fuzz/testdata/expr-162: -------------------------------------------------------------------------------- 1 | to_array(`[1, 2, 3]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-163: -------------------------------------------------------------------------------- 1 | to_array(false) -------------------------------------------------------------------------------- /fuzz/testdata/expr-164: -------------------------------------------------------------------------------- 1 | to_string('foo') -------------------------------------------------------------------------------- /fuzz/testdata/expr-165: -------------------------------------------------------------------------------- 1 | to_string(`1.2`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-166: -------------------------------------------------------------------------------- 1 | to_string(`[0, 1]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-167: -------------------------------------------------------------------------------- 1 | to_number('1.0') -------------------------------------------------------------------------------- /fuzz/testdata/expr-168: -------------------------------------------------------------------------------- 1 | to_number('1.1') -------------------------------------------------------------------------------- /fuzz/testdata/expr-169: -------------------------------------------------------------------------------- 1 | to_number('4') -------------------------------------------------------------------------------- /fuzz/testdata/expr-17: -------------------------------------------------------------------------------- 1 | foo."-1" -------------------------------------------------------------------------------- /fuzz/testdata/expr-170: -------------------------------------------------------------------------------- 1 | to_number('notanumber') -------------------------------------------------------------------------------- /fuzz/testdata/expr-171: -------------------------------------------------------------------------------- 1 | to_number(`false`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-172: -------------------------------------------------------------------------------- 1 | to_number(`null`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-173: -------------------------------------------------------------------------------- 1 | to_number(`[0]`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-174: -------------------------------------------------------------------------------- 1 | to_number(`{"foo": 0}`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-175: -------------------------------------------------------------------------------- 1 | sort(numbers) -------------------------------------------------------------------------------- /fuzz/testdata/expr-178: -------------------------------------------------------------------------------- 1 | sort(empty_list) -------------------------------------------------------------------------------- /fuzz/testdata/expr-179: -------------------------------------------------------------------------------- 1 | not_null(unknown_key, str) -------------------------------------------------------------------------------- /fuzz/testdata/expr-18: -------------------------------------------------------------------------------- 1 | @ -------------------------------------------------------------------------------- /fuzz/testdata/expr-180: -------------------------------------------------------------------------------- 1 | not_null(unknown_key, foo.bar, empty_list, str) -------------------------------------------------------------------------------- /fuzz/testdata/expr-181: -------------------------------------------------------------------------------- 1 | not_null(unknown_key, null_key, empty_list, str) -------------------------------------------------------------------------------- /fuzz/testdata/expr-182: -------------------------------------------------------------------------------- 1 | not_null(all, expressions, are_null) -------------------------------------------------------------------------------- /fuzz/testdata/expr-183: -------------------------------------------------------------------------------- 1 | numbers[].to_string(@) -------------------------------------------------------------------------------- /fuzz/testdata/expr-184: -------------------------------------------------------------------------------- 1 | array[].to_number(@) -------------------------------------------------------------------------------- /fuzz/testdata/expr-185: -------------------------------------------------------------------------------- 1 | foo[].not_null(f, e, d, c, b, a) -------------------------------------------------------------------------------- /fuzz/testdata/expr-186: -------------------------------------------------------------------------------- 1 | sort_by(people, &age) -------------------------------------------------------------------------------- /fuzz/testdata/expr-187: -------------------------------------------------------------------------------- 1 | sort_by(people, &to_number(age_str)) -------------------------------------------------------------------------------- /fuzz/testdata/expr-188: -------------------------------------------------------------------------------- 1 | sort_by(people, &age)[].name -------------------------------------------------------------------------------- /fuzz/testdata/expr-189: -------------------------------------------------------------------------------- 1 | sort_by(people, &age)[].extra -------------------------------------------------------------------------------- /fuzz/testdata/expr-19: -------------------------------------------------------------------------------- 1 | @.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-190: -------------------------------------------------------------------------------- 1 | sort_by(`[]`, &age) -------------------------------------------------------------------------------- /fuzz/testdata/expr-191: -------------------------------------------------------------------------------- 1 | max_by(people, &age) -------------------------------------------------------------------------------- /fuzz/testdata/expr-192: -------------------------------------------------------------------------------- 1 | max_by(people, &age_str) -------------------------------------------------------------------------------- /fuzz/testdata/expr-193: -------------------------------------------------------------------------------- 1 | max_by(people, &to_number(age_str)) -------------------------------------------------------------------------------- /fuzz/testdata/expr-194: -------------------------------------------------------------------------------- 1 | min_by(people, &age) -------------------------------------------------------------------------------- /fuzz/testdata/expr-195: -------------------------------------------------------------------------------- 1 | min_by(people, &age_str) -------------------------------------------------------------------------------- /fuzz/testdata/expr-196: -------------------------------------------------------------------------------- 1 | min_by(people, &to_number(age_str)) -------------------------------------------------------------------------------- /fuzz/testdata/expr-198: -------------------------------------------------------------------------------- 1 | __L -------------------------------------------------------------------------------- /fuzz/testdata/expr-199: -------------------------------------------------------------------------------- 1 | "!\r" -------------------------------------------------------------------------------- /fuzz/testdata/expr-2: -------------------------------------------------------------------------------- 1 | foo.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-20: -------------------------------------------------------------------------------- 1 | @.foo[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-200: -------------------------------------------------------------------------------- 1 | Y_1623 -------------------------------------------------------------------------------- /fuzz/testdata/expr-201: -------------------------------------------------------------------------------- 1 | x -------------------------------------------------------------------------------- /fuzz/testdata/expr-202: -------------------------------------------------------------------------------- 1 | "\tF\uCebb" -------------------------------------------------------------------------------- /fuzz/testdata/expr-203: -------------------------------------------------------------------------------- 1 | " \t" -------------------------------------------------------------------------------- /fuzz/testdata/expr-204: -------------------------------------------------------------------------------- 1 | " " -------------------------------------------------------------------------------- /fuzz/testdata/expr-205: -------------------------------------------------------------------------------- 1 | v2 -------------------------------------------------------------------------------- /fuzz/testdata/expr-206: -------------------------------------------------------------------------------- 1 | "\t" -------------------------------------------------------------------------------- /fuzz/testdata/expr-207: -------------------------------------------------------------------------------- 1 | _X -------------------------------------------------------------------------------- /fuzz/testdata/expr-208: -------------------------------------------------------------------------------- 1 | "\t4\ud9da\udd15" -------------------------------------------------------------------------------- /fuzz/testdata/expr-209: -------------------------------------------------------------------------------- 1 | v24_W -------------------------------------------------------------------------------- /fuzz/testdata/expr-21: -------------------------------------------------------------------------------- 1 | "foo.bar" -------------------------------------------------------------------------------- /fuzz/testdata/expr-210: -------------------------------------------------------------------------------- 1 | "H" -------------------------------------------------------------------------------- /fuzz/testdata/expr-211: -------------------------------------------------------------------------------- 1 | "\f" -------------------------------------------------------------------------------- /fuzz/testdata/expr-212: -------------------------------------------------------------------------------- 1 | "E4" -------------------------------------------------------------------------------- /fuzz/testdata/expr-213: -------------------------------------------------------------------------------- 1 | "!" -------------------------------------------------------------------------------- /fuzz/testdata/expr-214: -------------------------------------------------------------------------------- 1 | tM -------------------------------------------------------------------------------- /fuzz/testdata/expr-215: -------------------------------------------------------------------------------- 1 | " [" -------------------------------------------------------------------------------- /fuzz/testdata/expr-216: -------------------------------------------------------------------------------- 1 | "R!" -------------------------------------------------------------------------------- /fuzz/testdata/expr-217: -------------------------------------------------------------------------------- 1 | _6W -------------------------------------------------------------------------------- /fuzz/testdata/expr-218: -------------------------------------------------------------------------------- 1 | "\uaBA1\r" -------------------------------------------------------------------------------- /fuzz/testdata/expr-219: -------------------------------------------------------------------------------- 1 | tL7 -------------------------------------------------------------------------------- /fuzz/testdata/expr-22: -------------------------------------------------------------------------------- 1 | "foo bar" -------------------------------------------------------------------------------- /fuzz/testdata/expr-220: -------------------------------------------------------------------------------- 1 | "<" -------------------------------------------------------------------------------- /fuzz/testdata/expr-257: -------------------------------------------------------------------------------- 1 | hvu -------------------------------------------------------------------------------- /fuzz/testdata/expr-258: -------------------------------------------------------------------------------- 1 | "; !" -------------------------------------------------------------------------------- /fuzz/testdata/expr-259: -------------------------------------------------------------------------------- 1 | hU -------------------------------------------------------------------------------- /fuzz/testdata/expr-26: -------------------------------------------------------------------------------- 1 | "/unix/path" -------------------------------------------------------------------------------- /fuzz/testdata/expr-260: -------------------------------------------------------------------------------- 1 | "!I\n\/" -------------------------------------------------------------------------------- /fuzz/testdata/expr-261: -------------------------------------------------------------------------------- 1 | "\uEEbF" -------------------------------------------------------------------------------- /fuzz/testdata/expr-262: -------------------------------------------------------------------------------- 1 | "U)\t" -------------------------------------------------------------------------------- /fuzz/testdata/expr-263: -------------------------------------------------------------------------------- 1 | fa0_9 -------------------------------------------------------------------------------- /fuzz/testdata/expr-264: -------------------------------------------------------------------------------- 1 | "/" -------------------------------------------------------------------------------- /fuzz/testdata/expr-265: -------------------------------------------------------------------------------- 1 | Gy -------------------------------------------------------------------------------- /fuzz/testdata/expr-266: -------------------------------------------------------------------------------- 1 | "\b" -------------------------------------------------------------------------------- /fuzz/testdata/expr-267: -------------------------------------------------------------------------------- 1 | "<" -------------------------------------------------------------------------------- /fuzz/testdata/expr-268: -------------------------------------------------------------------------------- 1 | "\t" -------------------------------------------------------------------------------- /fuzz/testdata/expr-269: -------------------------------------------------------------------------------- 1 | "\t&\\\r" -------------------------------------------------------------------------------- /fuzz/testdata/expr-27: -------------------------------------------------------------------------------- 1 | "\"\"\"" -------------------------------------------------------------------------------- /fuzz/testdata/expr-270: -------------------------------------------------------------------------------- 1 | "#" -------------------------------------------------------------------------------- /fuzz/testdata/expr-271: -------------------------------------------------------------------------------- 1 | B__ -------------------------------------------------------------------------------- /fuzz/testdata/expr-272: -------------------------------------------------------------------------------- 1 | "\nS \n" -------------------------------------------------------------------------------- /fuzz/testdata/expr-273: -------------------------------------------------------------------------------- 1 | Bp -------------------------------------------------------------------------------- /fuzz/testdata/expr-274: -------------------------------------------------------------------------------- 1 | ",\t;" -------------------------------------------------------------------------------- /fuzz/testdata/expr-275: -------------------------------------------------------------------------------- 1 | B_q -------------------------------------------------------------------------------- /fuzz/testdata/expr-276: -------------------------------------------------------------------------------- 1 | "\/+\t\n\b!Z" -------------------------------------------------------------------------------- /fuzz/testdata/expr-277: -------------------------------------------------------------------------------- 1 | "󇟇\\ueFAc" -------------------------------------------------------------------------------- /fuzz/testdata/expr-278: -------------------------------------------------------------------------------- 1 | ":\f" -------------------------------------------------------------------------------- /fuzz/testdata/expr-279: -------------------------------------------------------------------------------- 1 | "\/" -------------------------------------------------------------------------------- /fuzz/testdata/expr-28: -------------------------------------------------------------------------------- 1 | "bar"."baz" -------------------------------------------------------------------------------- /fuzz/testdata/expr-280: -------------------------------------------------------------------------------- 1 | _BW_6Hg_Gl -------------------------------------------------------------------------------- /fuzz/testdata/expr-281: -------------------------------------------------------------------------------- 1 | "􃰂" -------------------------------------------------------------------------------- /fuzz/testdata/expr-282: -------------------------------------------------------------------------------- 1 | zs1DC -------------------------------------------------------------------------------- /fuzz/testdata/expr-283: -------------------------------------------------------------------------------- 1 | __434 -------------------------------------------------------------------------------- /fuzz/testdata/expr-284: -------------------------------------------------------------------------------- 1 | "󵅁" -------------------------------------------------------------------------------- /fuzz/testdata/expr-285: -------------------------------------------------------------------------------- 1 | Z_5 -------------------------------------------------------------------------------- /fuzz/testdata/expr-286: -------------------------------------------------------------------------------- 1 | z_M_ -------------------------------------------------------------------------------- /fuzz/testdata/expr-287: -------------------------------------------------------------------------------- 1 | YU_2 -------------------------------------------------------------------------------- /fuzz/testdata/expr-288: -------------------------------------------------------------------------------- 1 | _0 -------------------------------------------------------------------------------- /fuzz/testdata/expr-289: -------------------------------------------------------------------------------- 1 | "\b+" -------------------------------------------------------------------------------- /fuzz/testdata/expr-29: -------------------------------------------------------------------------------- 1 | foo[?name == 'a'] -------------------------------------------------------------------------------- /fuzz/testdata/expr-290: -------------------------------------------------------------------------------- 1 | "\"" -------------------------------------------------------------------------------- /fuzz/testdata/expr-291: -------------------------------------------------------------------------------- 1 | D7 -------------------------------------------------------------------------------- /fuzz/testdata/expr-292: -------------------------------------------------------------------------------- 1 | _62L -------------------------------------------------------------------------------- /fuzz/testdata/expr-293: -------------------------------------------------------------------------------- 1 | "\tK\t" -------------------------------------------------------------------------------- /fuzz/testdata/expr-294: -------------------------------------------------------------------------------- 1 | "\n\\\f" -------------------------------------------------------------------------------- /fuzz/testdata/expr-295: -------------------------------------------------------------------------------- 1 | I_ -------------------------------------------------------------------------------- /fuzz/testdata/expr-296: -------------------------------------------------------------------------------- 1 | W_a0_ -------------------------------------------------------------------------------- /fuzz/testdata/expr-297: -------------------------------------------------------------------------------- 1 | BQ -------------------------------------------------------------------------------- /fuzz/testdata/expr-298: -------------------------------------------------------------------------------- 1 | "\tX$\uABBb" -------------------------------------------------------------------------------- /fuzz/testdata/expr-299: -------------------------------------------------------------------------------- 1 | Z9 -------------------------------------------------------------------------------- /fuzz/testdata/expr-3: -------------------------------------------------------------------------------- 1 | foo.bar.baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-30: -------------------------------------------------------------------------------- 1 | *[?[0] == `0`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-300: -------------------------------------------------------------------------------- 1 | "\b%\"򞄏" -------------------------------------------------------------------------------- /fuzz/testdata/expr-301: -------------------------------------------------------------------------------- 1 | _F -------------------------------------------------------------------------------- /fuzz/testdata/expr-302: -------------------------------------------------------------------------------- 1 | "!," -------------------------------------------------------------------------------- /fuzz/testdata/expr-303: -------------------------------------------------------------------------------- 1 | "\"!" -------------------------------------------------------------------------------- /fuzz/testdata/expr-304: -------------------------------------------------------------------------------- 1 | Hh -------------------------------------------------------------------------------- /fuzz/testdata/expr-305: -------------------------------------------------------------------------------- 1 | "&" -------------------------------------------------------------------------------- /fuzz/testdata/expr-306: -------------------------------------------------------------------------------- 1 | "9\r\\R" -------------------------------------------------------------------------------- /fuzz/testdata/expr-307: -------------------------------------------------------------------------------- 1 | M_k -------------------------------------------------------------------------------- /fuzz/testdata/expr-308: -------------------------------------------------------------------------------- 1 | "!\b\n󑩒\"\"" -------------------------------------------------------------------------------- /fuzz/testdata/expr-309: -------------------------------------------------------------------------------- 1 | "6" -------------------------------------------------------------------------------- /fuzz/testdata/expr-31: -------------------------------------------------------------------------------- 1 | foo[?first == last] -------------------------------------------------------------------------------- /fuzz/testdata/expr-310: -------------------------------------------------------------------------------- 1 | _7 -------------------------------------------------------------------------------- /fuzz/testdata/expr-311: -------------------------------------------------------------------------------- 1 | "0" -------------------------------------------------------------------------------- /fuzz/testdata/expr-312: -------------------------------------------------------------------------------- 1 | "\\8\\" -------------------------------------------------------------------------------- /fuzz/testdata/expr-313: -------------------------------------------------------------------------------- 1 | b7eo -------------------------------------------------------------------------------- /fuzz/testdata/expr-314: -------------------------------------------------------------------------------- 1 | xIUo9 -------------------------------------------------------------------------------- /fuzz/testdata/expr-315: -------------------------------------------------------------------------------- 1 | "5" -------------------------------------------------------------------------------- /fuzz/testdata/expr-316: -------------------------------------------------------------------------------- 1 | "?" -------------------------------------------------------------------------------- /fuzz/testdata/expr-317: -------------------------------------------------------------------------------- 1 | sU -------------------------------------------------------------------------------- /fuzz/testdata/expr-318: -------------------------------------------------------------------------------- 1 | "VH2&H\\\/" -------------------------------------------------------------------------------- /fuzz/testdata/expr-319: -------------------------------------------------------------------------------- 1 | _C -------------------------------------------------------------------------------- /fuzz/testdata/expr-32: -------------------------------------------------------------------------------- 1 | foo[?first == last].first -------------------------------------------------------------------------------- /fuzz/testdata/expr-320: -------------------------------------------------------------------------------- 1 | _ -------------------------------------------------------------------------------- /fuzz/testdata/expr-321: -------------------------------------------------------------------------------- 1 | "<\t" -------------------------------------------------------------------------------- /fuzz/testdata/expr-322: -------------------------------------------------------------------------------- 1 | "\uD834\uDD1E" -------------------------------------------------------------------------------- /fuzz/testdata/expr-323: -------------------------------------------------------------------------------- 1 | foo.bar[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-324: -------------------------------------------------------------------------------- 1 | foo.bar[1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-325: -------------------------------------------------------------------------------- 1 | foo.bar[2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-326: -------------------------------------------------------------------------------- 1 | foo.bar[3] -------------------------------------------------------------------------------- /fuzz/testdata/expr-327: -------------------------------------------------------------------------------- 1 | foo.bar[-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-328: -------------------------------------------------------------------------------- 1 | foo.bar[-2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-329: -------------------------------------------------------------------------------- 1 | foo.bar[-3] -------------------------------------------------------------------------------- /fuzz/testdata/expr-33: -------------------------------------------------------------------------------- 1 | foo[?age > `25`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-330: -------------------------------------------------------------------------------- 1 | foo.bar[-4] -------------------------------------------------------------------------------- /fuzz/testdata/expr-331: -------------------------------------------------------------------------------- 1 | foo.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-332: -------------------------------------------------------------------------------- 1 | foo[0].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-333: -------------------------------------------------------------------------------- 1 | foo[1].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-334: -------------------------------------------------------------------------------- 1 | foo[2].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-335: -------------------------------------------------------------------------------- 1 | foo[3].notbar -------------------------------------------------------------------------------- /fuzz/testdata/expr-336: -------------------------------------------------------------------------------- 1 | foo[3].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-337: -------------------------------------------------------------------------------- 1 | foo[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-338: -------------------------------------------------------------------------------- 1 | foo[1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-339: -------------------------------------------------------------------------------- 1 | foo[2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-34: -------------------------------------------------------------------------------- 1 | foo[?age >= `25`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-340: -------------------------------------------------------------------------------- 1 | foo[3] -------------------------------------------------------------------------------- /fuzz/testdata/expr-341: -------------------------------------------------------------------------------- 1 | foo[4] -------------------------------------------------------------------------------- /fuzz/testdata/expr-342: -------------------------------------------------------------------------------- 1 | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-343: -------------------------------------------------------------------------------- 1 | [1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-344: -------------------------------------------------------------------------------- 1 | [2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-345: -------------------------------------------------------------------------------- 1 | [-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-346: -------------------------------------------------------------------------------- 1 | [-2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-347: -------------------------------------------------------------------------------- 1 | [-3] -------------------------------------------------------------------------------- /fuzz/testdata/expr-348: -------------------------------------------------------------------------------- 1 | reservations[].instances[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-349: -------------------------------------------------------------------------------- 1 | reservations[].instances[].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-35: -------------------------------------------------------------------------------- 1 | foo[?age > `30`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-350: -------------------------------------------------------------------------------- 1 | reservations[].notinstances[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-351: -------------------------------------------------------------------------------- 1 | reservations[].notinstances[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-352: -------------------------------------------------------------------------------- 1 | reservations[].instances[].foo[].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-353: -------------------------------------------------------------------------------- 1 | reservations[].instances[].foo[].baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-354: -------------------------------------------------------------------------------- 1 | reservations[].instances[].notfoo[].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-355: -------------------------------------------------------------------------------- 1 | reservations[].instances[].notfoo[].notbar -------------------------------------------------------------------------------- /fuzz/testdata/expr-356: -------------------------------------------------------------------------------- 1 | reservations[].notinstances[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-357: -------------------------------------------------------------------------------- 1 | reservations[].instances[].foo[].notbar -------------------------------------------------------------------------------- /fuzz/testdata/expr-358: -------------------------------------------------------------------------------- 1 | reservations[].instances[].bar[].baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-359: -------------------------------------------------------------------------------- 1 | reservations[].instances[].baz[].baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-36: -------------------------------------------------------------------------------- 1 | foo[?age < `25`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-360: -------------------------------------------------------------------------------- 1 | reservations[].instances[].qux[].baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-361: -------------------------------------------------------------------------------- 1 | reservations[].instances[].qux[].baz[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-362: -------------------------------------------------------------------------------- 1 | foo[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-363: -------------------------------------------------------------------------------- 1 | foo[][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-364: -------------------------------------------------------------------------------- 1 | foo[][1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-365: -------------------------------------------------------------------------------- 1 | foo[][0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-366: -------------------------------------------------------------------------------- 1 | foo[][2][2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-367: -------------------------------------------------------------------------------- 1 | foo[][0][0][100] -------------------------------------------------------------------------------- /fuzz/testdata/expr-368: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-369: -------------------------------------------------------------------------------- 1 | foo[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-37: -------------------------------------------------------------------------------- 1 | foo[?age <= `25`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-370: -------------------------------------------------------------------------------- 1 | foo[].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-371: -------------------------------------------------------------------------------- 1 | foo[].bar[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-372: -------------------------------------------------------------------------------- 1 | foo[].bar[].baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-373: -------------------------------------------------------------------------------- 1 | string[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-374: -------------------------------------------------------------------------------- 1 | hash[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-375: -------------------------------------------------------------------------------- 1 | number[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-376: -------------------------------------------------------------------------------- 1 | nullvalue[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-377: -------------------------------------------------------------------------------- 1 | string[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-378: -------------------------------------------------------------------------------- 1 | hash[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-379: -------------------------------------------------------------------------------- 1 | number[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-38: -------------------------------------------------------------------------------- 1 | foo[?age < `20`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-380: -------------------------------------------------------------------------------- 1 | nullvalue[].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-381: -------------------------------------------------------------------------------- 1 | nullvalue[].foo[].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-382: -------------------------------------------------------------------------------- 1 | `"foo"` -------------------------------------------------------------------------------- /fuzz/testdata/expr-383: -------------------------------------------------------------------------------- 1 | `"\u03a6"` -------------------------------------------------------------------------------- /fuzz/testdata/expr-384: -------------------------------------------------------------------------------- 1 | `"✓"` -------------------------------------------------------------------------------- /fuzz/testdata/expr-385: -------------------------------------------------------------------------------- 1 | `[1, 2, 3]` -------------------------------------------------------------------------------- /fuzz/testdata/expr-386: -------------------------------------------------------------------------------- 1 | `{"a": "b"}` -------------------------------------------------------------------------------- /fuzz/testdata/expr-387: -------------------------------------------------------------------------------- 1 | `true` -------------------------------------------------------------------------------- /fuzz/testdata/expr-388: -------------------------------------------------------------------------------- 1 | `false` -------------------------------------------------------------------------------- /fuzz/testdata/expr-389: -------------------------------------------------------------------------------- 1 | `null` -------------------------------------------------------------------------------- /fuzz/testdata/expr-39: -------------------------------------------------------------------------------- 1 | foo[?age == `20`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-390: -------------------------------------------------------------------------------- 1 | `0` -------------------------------------------------------------------------------- /fuzz/testdata/expr-391: -------------------------------------------------------------------------------- 1 | `1` -------------------------------------------------------------------------------- /fuzz/testdata/expr-392: -------------------------------------------------------------------------------- 1 | `2` -------------------------------------------------------------------------------- /fuzz/testdata/expr-393: -------------------------------------------------------------------------------- 1 | `3` -------------------------------------------------------------------------------- /fuzz/testdata/expr-394: -------------------------------------------------------------------------------- 1 | `4` -------------------------------------------------------------------------------- /fuzz/testdata/expr-395: -------------------------------------------------------------------------------- 1 | `5` -------------------------------------------------------------------------------- /fuzz/testdata/expr-396: -------------------------------------------------------------------------------- 1 | `6` -------------------------------------------------------------------------------- /fuzz/testdata/expr-397: -------------------------------------------------------------------------------- 1 | `7` -------------------------------------------------------------------------------- /fuzz/testdata/expr-398: -------------------------------------------------------------------------------- 1 | `8` -------------------------------------------------------------------------------- /fuzz/testdata/expr-399: -------------------------------------------------------------------------------- 1 | `9` -------------------------------------------------------------------------------- /fuzz/testdata/expr-4: -------------------------------------------------------------------------------- 1 | foo.bar.baz.bad -------------------------------------------------------------------------------- /fuzz/testdata/expr-40: -------------------------------------------------------------------------------- 1 | foo[?age != `20`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-400: -------------------------------------------------------------------------------- 1 | `"foo\`bar"` -------------------------------------------------------------------------------- /fuzz/testdata/expr-401: -------------------------------------------------------------------------------- 1 | `"foo\"bar"` -------------------------------------------------------------------------------- /fuzz/testdata/expr-402: -------------------------------------------------------------------------------- 1 | `"1\`"` -------------------------------------------------------------------------------- /fuzz/testdata/expr-403: -------------------------------------------------------------------------------- 1 | `"\\"`.{a:`"b"`} -------------------------------------------------------------------------------- /fuzz/testdata/expr-404: -------------------------------------------------------------------------------- 1 | `{"a": "b"}`.a -------------------------------------------------------------------------------- /fuzz/testdata/expr-405: -------------------------------------------------------------------------------- 1 | `{"a": {"b": "c"}}`.a.b -------------------------------------------------------------------------------- /fuzz/testdata/expr-406: -------------------------------------------------------------------------------- 1 | `[0, 1, 2]`[1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-407: -------------------------------------------------------------------------------- 1 | ` {"foo": true}` -------------------------------------------------------------------------------- /fuzz/testdata/expr-408: -------------------------------------------------------------------------------- 1 | `{"foo": true} ` -------------------------------------------------------------------------------- /fuzz/testdata/expr-409: -------------------------------------------------------------------------------- 1 | 'foo' -------------------------------------------------------------------------------- /fuzz/testdata/expr-41: -------------------------------------------------------------------------------- 1 | foo[?top.name == 'a'] -------------------------------------------------------------------------------- /fuzz/testdata/expr-410: -------------------------------------------------------------------------------- 1 | ' foo ' -------------------------------------------------------------------------------- /fuzz/testdata/expr-411: -------------------------------------------------------------------------------- 1 | '0' -------------------------------------------------------------------------------- /fuzz/testdata/expr-412: -------------------------------------------------------------------------------- 1 | 'newline 2 | ' -------------------------------------------------------------------------------- /fuzz/testdata/expr-413: -------------------------------------------------------------------------------- 1 | ' 2 | ' -------------------------------------------------------------------------------- /fuzz/testdata/expr-414: -------------------------------------------------------------------------------- 1 | '✓' -------------------------------------------------------------------------------- /fuzz/testdata/expr-415: -------------------------------------------------------------------------------- 1 | '𝄞' -------------------------------------------------------------------------------- /fuzz/testdata/expr-416: -------------------------------------------------------------------------------- 1 | ' [foo] ' -------------------------------------------------------------------------------- /fuzz/testdata/expr-417: -------------------------------------------------------------------------------- 1 | '[foo]' -------------------------------------------------------------------------------- /fuzz/testdata/expr-418: -------------------------------------------------------------------------------- 1 | '\u03a6' -------------------------------------------------------------------------------- /fuzz/testdata/expr-419: -------------------------------------------------------------------------------- 1 | foo.{bar: bar} -------------------------------------------------------------------------------- /fuzz/testdata/expr-42: -------------------------------------------------------------------------------- 1 | foo[?top.first == top.last] -------------------------------------------------------------------------------- /fuzz/testdata/expr-420: -------------------------------------------------------------------------------- 1 | foo.{"bar": bar} -------------------------------------------------------------------------------- /fuzz/testdata/expr-421: -------------------------------------------------------------------------------- 1 | foo.{"foo.bar": bar} -------------------------------------------------------------------------------- /fuzz/testdata/expr-422: -------------------------------------------------------------------------------- 1 | foo.{bar: bar, baz: baz} -------------------------------------------------------------------------------- /fuzz/testdata/expr-423: -------------------------------------------------------------------------------- 1 | foo.{"bar": bar, "baz": baz} -------------------------------------------------------------------------------- /fuzz/testdata/expr-424: -------------------------------------------------------------------------------- 1 | {"baz": baz, "qux\"": "qux\""} -------------------------------------------------------------------------------- /fuzz/testdata/expr-425: -------------------------------------------------------------------------------- 1 | foo.{bar:bar,baz:baz} -------------------------------------------------------------------------------- /fuzz/testdata/expr-426: -------------------------------------------------------------------------------- 1 | foo.{bar: bar,qux: qux} -------------------------------------------------------------------------------- /fuzz/testdata/expr-427: -------------------------------------------------------------------------------- 1 | foo.{bar: bar, noexist: noexist} -------------------------------------------------------------------------------- /fuzz/testdata/expr-428: -------------------------------------------------------------------------------- 1 | foo.{noexist: noexist, alsonoexist: alsonoexist} -------------------------------------------------------------------------------- /fuzz/testdata/expr-429: -------------------------------------------------------------------------------- 1 | foo.badkey.{nokey: nokey, alsonokey: alsonokey} -------------------------------------------------------------------------------- /fuzz/testdata/expr-43: -------------------------------------------------------------------------------- 1 | foo[?top == `{"first": "foo", "last": "bar"}`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-430: -------------------------------------------------------------------------------- 1 | foo.nested.*.{a: a,b: b} -------------------------------------------------------------------------------- /fuzz/testdata/expr-431: -------------------------------------------------------------------------------- 1 | foo.nested.three.{a: a, cinner: c.inner} -------------------------------------------------------------------------------- /fuzz/testdata/expr-432: -------------------------------------------------------------------------------- 1 | foo.nested.three.{a: a, c: c.inner.bad.key} -------------------------------------------------------------------------------- /fuzz/testdata/expr-433: -------------------------------------------------------------------------------- 1 | foo.{a: nested.one.a, b: nested.two.b} -------------------------------------------------------------------------------- /fuzz/testdata/expr-434: -------------------------------------------------------------------------------- 1 | {bar: bar, baz: baz} -------------------------------------------------------------------------------- /fuzz/testdata/expr-435: -------------------------------------------------------------------------------- 1 | {bar: bar} -------------------------------------------------------------------------------- /fuzz/testdata/expr-436: -------------------------------------------------------------------------------- 1 | {otherkey: bar} -------------------------------------------------------------------------------- /fuzz/testdata/expr-437: -------------------------------------------------------------------------------- 1 | {no: no, exist: exist} -------------------------------------------------------------------------------- /fuzz/testdata/expr-438: -------------------------------------------------------------------------------- 1 | foo.[bar] -------------------------------------------------------------------------------- /fuzz/testdata/expr-439: -------------------------------------------------------------------------------- 1 | foo.[bar,baz] -------------------------------------------------------------------------------- /fuzz/testdata/expr-44: -------------------------------------------------------------------------------- 1 | foo[?key == `true`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-440: -------------------------------------------------------------------------------- 1 | foo.[bar,qux] -------------------------------------------------------------------------------- /fuzz/testdata/expr-441: -------------------------------------------------------------------------------- 1 | foo.[bar,noexist] -------------------------------------------------------------------------------- /fuzz/testdata/expr-442: -------------------------------------------------------------------------------- 1 | foo.[noexist,alsonoexist] -------------------------------------------------------------------------------- /fuzz/testdata/expr-443: -------------------------------------------------------------------------------- 1 | foo.{bar:bar,baz:baz} -------------------------------------------------------------------------------- /fuzz/testdata/expr-444: -------------------------------------------------------------------------------- 1 | foo.[bar,baz[0]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-445: -------------------------------------------------------------------------------- 1 | foo.[bar,baz[1]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-446: -------------------------------------------------------------------------------- 1 | foo.[bar,baz[2]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-447: -------------------------------------------------------------------------------- 1 | foo.[bar,baz[3]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-448: -------------------------------------------------------------------------------- 1 | foo.[bar[0],baz[3]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-449: -------------------------------------------------------------------------------- 1 | foo.{bar: bar, baz: baz} -------------------------------------------------------------------------------- /fuzz/testdata/expr-45: -------------------------------------------------------------------------------- 1 | foo[?key == `false`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-450: -------------------------------------------------------------------------------- 1 | foo.[bar,baz] -------------------------------------------------------------------------------- /fuzz/testdata/expr-451: -------------------------------------------------------------------------------- 1 | foo.{bar: bar.baz[1],includeme: includeme} -------------------------------------------------------------------------------- /fuzz/testdata/expr-452: -------------------------------------------------------------------------------- 1 | foo.{"bar.baz.two": bar.baz[1].two, includeme: includeme} -------------------------------------------------------------------------------- /fuzz/testdata/expr-453: -------------------------------------------------------------------------------- 1 | foo.[includeme, bar.baz[*].common] -------------------------------------------------------------------------------- /fuzz/testdata/expr-454: -------------------------------------------------------------------------------- 1 | foo.[includeme, bar.baz[*].none] -------------------------------------------------------------------------------- /fuzz/testdata/expr-455: -------------------------------------------------------------------------------- 1 | foo.[includeme, bar.baz[].common] -------------------------------------------------------------------------------- /fuzz/testdata/expr-456: -------------------------------------------------------------------------------- 1 | reservations[*].instances[*].{id: id, name: name} -------------------------------------------------------------------------------- /fuzz/testdata/expr-457: -------------------------------------------------------------------------------- 1 | reservations[].instances[].{id: id, name: name} -------------------------------------------------------------------------------- /fuzz/testdata/expr-458: -------------------------------------------------------------------------------- 1 | reservations[].instances[].[id, name] -------------------------------------------------------------------------------- /fuzz/testdata/expr-459: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-46: -------------------------------------------------------------------------------- 1 | foo[?key == `0`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-460: -------------------------------------------------------------------------------- 1 | foo[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-461: -------------------------------------------------------------------------------- 1 | foo[].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-462: -------------------------------------------------------------------------------- 1 | foo[].bar[] -------------------------------------------------------------------------------- /fuzz/testdata/expr-463: -------------------------------------------------------------------------------- 1 | foo[].bar[].[baz, qux] -------------------------------------------------------------------------------- /fuzz/testdata/expr-464: -------------------------------------------------------------------------------- 1 | foo[].bar[].[baz] -------------------------------------------------------------------------------- /fuzz/testdata/expr-465: -------------------------------------------------------------------------------- 1 | foo[].bar[].[baz, qux][] -------------------------------------------------------------------------------- /fuzz/testdata/expr-466: -------------------------------------------------------------------------------- 1 | foo.[baz[*].bar, qux[0]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-467: -------------------------------------------------------------------------------- 1 | foo.[baz[*].[bar, boo], qux[0]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-468: -------------------------------------------------------------------------------- 1 | foo.[baz[*].not_there || baz[*].bar, qux[0]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-469: -------------------------------------------------------------------------------- 1 | [[*],*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-47: -------------------------------------------------------------------------------- 1 | foo[?key == `1`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-470: -------------------------------------------------------------------------------- 1 | [[*]] -------------------------------------------------------------------------------- /fuzz/testdata/expr-471: -------------------------------------------------------------------------------- 1 | outer.foo || outer.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-472: -------------------------------------------------------------------------------- 1 | outer.foo||outer.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-473: -------------------------------------------------------------------------------- 1 | outer.bar || outer.baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-474: -------------------------------------------------------------------------------- 1 | outer.bar||outer.baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-475: -------------------------------------------------------------------------------- 1 | outer.bad || outer.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-476: -------------------------------------------------------------------------------- 1 | outer.bad||outer.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-477: -------------------------------------------------------------------------------- 1 | outer.foo || outer.bad -------------------------------------------------------------------------------- /fuzz/testdata/expr-478: -------------------------------------------------------------------------------- 1 | outer.foo||outer.bad -------------------------------------------------------------------------------- /fuzz/testdata/expr-479: -------------------------------------------------------------------------------- 1 | outer.bad || outer.alsobad -------------------------------------------------------------------------------- /fuzz/testdata/expr-48: -------------------------------------------------------------------------------- 1 | foo[?key == `[0]`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-480: -------------------------------------------------------------------------------- 1 | outer.bad||outer.alsobad -------------------------------------------------------------------------------- /fuzz/testdata/expr-481: -------------------------------------------------------------------------------- 1 | outer.empty_string || outer.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-482: -------------------------------------------------------------------------------- 1 | outer.nokey || outer.bool || outer.empty_list || outer.empty_string || outer.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-483: -------------------------------------------------------------------------------- 1 | foo.*.baz | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-484: -------------------------------------------------------------------------------- 1 | foo.*.baz | [1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-485: -------------------------------------------------------------------------------- 1 | foo.*.baz | [2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-486: -------------------------------------------------------------------------------- 1 | foo.bar.* | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-487: -------------------------------------------------------------------------------- 1 | foo.*.notbaz | [*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-488: -------------------------------------------------------------------------------- 1 | foo | bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-489: -------------------------------------------------------------------------------- 1 | foo | bar | baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-49: -------------------------------------------------------------------------------- 1 | foo[?key == `{"bar": [0]}`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-490: -------------------------------------------------------------------------------- 1 | foo|bar| baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-491: -------------------------------------------------------------------------------- 1 | not_there | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-492: -------------------------------------------------------------------------------- 1 | not_there | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-493: -------------------------------------------------------------------------------- 1 | [foo.bar, foo.other] | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-494: -------------------------------------------------------------------------------- 1 | {"a": foo.bar, "b": foo.other} | a -------------------------------------------------------------------------------- /fuzz/testdata/expr-495: -------------------------------------------------------------------------------- 1 | {"a": foo.bar, "b": foo.other} | b -------------------------------------------------------------------------------- /fuzz/testdata/expr-496: -------------------------------------------------------------------------------- 1 | {"a": foo.bar, "b": foo.other} | *.baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-497: -------------------------------------------------------------------------------- 1 | foo.bam || foo.bar | baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-498: -------------------------------------------------------------------------------- 1 | foo | not_there || bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-499: -------------------------------------------------------------------------------- 1 | foo[*].bar[*] | [0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-5: -------------------------------------------------------------------------------- 1 | foo.bar.bad -------------------------------------------------------------------------------- /fuzz/testdata/expr-50: -------------------------------------------------------------------------------- 1 | foo[?key == `null`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-500: -------------------------------------------------------------------------------- 1 | bar[0:10] -------------------------------------------------------------------------------- /fuzz/testdata/expr-501: -------------------------------------------------------------------------------- 1 | foo[0:10:1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-502: -------------------------------------------------------------------------------- 1 | foo[0:10] -------------------------------------------------------------------------------- /fuzz/testdata/expr-503: -------------------------------------------------------------------------------- 1 | foo[0:10:] -------------------------------------------------------------------------------- /fuzz/testdata/expr-504: -------------------------------------------------------------------------------- 1 | foo[0::1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-505: -------------------------------------------------------------------------------- 1 | foo[0::] -------------------------------------------------------------------------------- /fuzz/testdata/expr-506: -------------------------------------------------------------------------------- 1 | foo[0:] -------------------------------------------------------------------------------- /fuzz/testdata/expr-507: -------------------------------------------------------------------------------- 1 | foo[:10:1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-508: -------------------------------------------------------------------------------- 1 | foo[::1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-509: -------------------------------------------------------------------------------- 1 | foo[:10:] -------------------------------------------------------------------------------- /fuzz/testdata/expr-51: -------------------------------------------------------------------------------- 1 | foo[?key == `[1]`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-510: -------------------------------------------------------------------------------- 1 | foo[::] -------------------------------------------------------------------------------- /fuzz/testdata/expr-511: -------------------------------------------------------------------------------- 1 | foo[:] -------------------------------------------------------------------------------- /fuzz/testdata/expr-512: -------------------------------------------------------------------------------- 1 | foo[1:9] -------------------------------------------------------------------------------- /fuzz/testdata/expr-513: -------------------------------------------------------------------------------- 1 | foo[0:10:2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-514: -------------------------------------------------------------------------------- 1 | foo[5:] -------------------------------------------------------------------------------- /fuzz/testdata/expr-515: -------------------------------------------------------------------------------- 1 | foo[5::2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-516: -------------------------------------------------------------------------------- 1 | foo[::2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-517: -------------------------------------------------------------------------------- 1 | foo[::-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-518: -------------------------------------------------------------------------------- 1 | foo[1::2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-519: -------------------------------------------------------------------------------- 1 | foo[10:0:-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-52: -------------------------------------------------------------------------------- 1 | foo[?key == `{"a":2}`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-520: -------------------------------------------------------------------------------- 1 | foo[10:5:-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-521: -------------------------------------------------------------------------------- 1 | foo[8:2:-2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-522: -------------------------------------------------------------------------------- 1 | foo[0:20] -------------------------------------------------------------------------------- /fuzz/testdata/expr-523: -------------------------------------------------------------------------------- 1 | foo[10:-20:-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-524: -------------------------------------------------------------------------------- 1 | foo[10:-20] -------------------------------------------------------------------------------- /fuzz/testdata/expr-525: -------------------------------------------------------------------------------- 1 | foo[-4:-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-526: -------------------------------------------------------------------------------- 1 | foo[:-5:-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-527: -------------------------------------------------------------------------------- 1 | foo[:2].a -------------------------------------------------------------------------------- /fuzz/testdata/expr-528: -------------------------------------------------------------------------------- 1 | foo[:2].b -------------------------------------------------------------------------------- /fuzz/testdata/expr-529: -------------------------------------------------------------------------------- 1 | foo[:2].a.b -------------------------------------------------------------------------------- /fuzz/testdata/expr-53: -------------------------------------------------------------------------------- 1 | foo[?`true` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-530: -------------------------------------------------------------------------------- 1 | bar[::-1].a.b -------------------------------------------------------------------------------- /fuzz/testdata/expr-531: -------------------------------------------------------------------------------- 1 | bar[:2].a.b -------------------------------------------------------------------------------- /fuzz/testdata/expr-532: -------------------------------------------------------------------------------- 1 | baz[:2].a -------------------------------------------------------------------------------- /fuzz/testdata/expr-533: -------------------------------------------------------------------------------- 1 | [:] -------------------------------------------------------------------------------- /fuzz/testdata/expr-534: -------------------------------------------------------------------------------- 1 | [:2].a -------------------------------------------------------------------------------- /fuzz/testdata/expr-535: -------------------------------------------------------------------------------- 1 | [::-1].a -------------------------------------------------------------------------------- /fuzz/testdata/expr-536: -------------------------------------------------------------------------------- 1 | [:2].b -------------------------------------------------------------------------------- /fuzz/testdata/expr-537: -------------------------------------------------------------------------------- 1 | foo.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-538: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-539: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /fuzz/testdata/expr-54: -------------------------------------------------------------------------------- 1 | foo[?`false` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-540: -------------------------------------------------------------------------------- 1 | *.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-541: -------------------------------------------------------------------------------- 1 | *.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-542: -------------------------------------------------------------------------------- 1 | *[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-543: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /fuzz/testdata/expr-544: -------------------------------------------------------------------------------- 1 | [0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-545: -------------------------------------------------------------------------------- 1 | [*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-546: -------------------------------------------------------------------------------- 1 | *.["0"] -------------------------------------------------------------------------------- /fuzz/testdata/expr-547: -------------------------------------------------------------------------------- 1 | [*].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-548: -------------------------------------------------------------------------------- 1 | [*][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-549: -------------------------------------------------------------------------------- 1 | foo[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-55: -------------------------------------------------------------------------------- 1 | foo[?`0` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-550: -------------------------------------------------------------------------------- 1 | foo.[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-551: -------------------------------------------------------------------------------- 1 | foo.[abc] -------------------------------------------------------------------------------- /fuzz/testdata/expr-552: -------------------------------------------------------------------------------- 1 | foo.[abc, def] -------------------------------------------------------------------------------- /fuzz/testdata/expr-553: -------------------------------------------------------------------------------- 1 | a.{foo: bar} -------------------------------------------------------------------------------- /fuzz/testdata/expr-554: -------------------------------------------------------------------------------- 1 | a.{foo: bar, baz: bam} -------------------------------------------------------------------------------- /fuzz/testdata/expr-555: -------------------------------------------------------------------------------- 1 | {"\\":{" ":*}} -------------------------------------------------------------------------------- /fuzz/testdata/expr-556: -------------------------------------------------------------------------------- 1 | foo || bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-557: -------------------------------------------------------------------------------- 1 | foo.[a || b] -------------------------------------------------------------------------------- /fuzz/testdata/expr-558: -------------------------------------------------------------------------------- 1 | foo[?bar==`"baz"`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-559: -------------------------------------------------------------------------------- 1 | foo[? bar == `"baz"` ] -------------------------------------------------------------------------------- /fuzz/testdata/expr-56: -------------------------------------------------------------------------------- 1 | foo[?`1` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-560: -------------------------------------------------------------------------------- 1 | foo[?a.b.c==d.e.f] -------------------------------------------------------------------------------- /fuzz/testdata/expr-561: -------------------------------------------------------------------------------- 1 | foo[?bar==`[0, 1, 2]`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-562: -------------------------------------------------------------------------------- 1 | foo[?bar==`["a", "b", "c"]`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-563: -------------------------------------------------------------------------------- 1 | foo[?bar==`["foo\`bar"]`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-564: -------------------------------------------------------------------------------- 1 | [?"\\">`"foo"`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-565: -------------------------------------------------------------------------------- 1 | [?"\\" > `"foo"`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-566: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-567: -------------------------------------------------------------------------------- 1 | "foo" -------------------------------------------------------------------------------- /fuzz/testdata/expr-568: -------------------------------------------------------------------------------- 1 | "\\" -------------------------------------------------------------------------------- /fuzz/testdata/expr-569: -------------------------------------------------------------------------------- 1 | *||*|*|* -------------------------------------------------------------------------------- /fuzz/testdata/expr-57: -------------------------------------------------------------------------------- 1 | foo[?`[0]` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-570: -------------------------------------------------------------------------------- 1 | *[]||[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-571: -------------------------------------------------------------------------------- 1 | [*.*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-572: -------------------------------------------------------------------------------- 1 | foo[]."✓" -------------------------------------------------------------------------------- /fuzz/testdata/expr-573: -------------------------------------------------------------------------------- 1 | "☯" -------------------------------------------------------------------------------- /fuzz/testdata/expr-574: -------------------------------------------------------------------------------- 1 | "♪♫•*¨*•.¸¸❤¸¸.•*¨*•♫♪" -------------------------------------------------------------------------------- /fuzz/testdata/expr-575: -------------------------------------------------------------------------------- 1 | "☃" -------------------------------------------------------------------------------- /fuzz/testdata/expr-576: -------------------------------------------------------------------------------- 1 | foo.*.baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-577: -------------------------------------------------------------------------------- 1 | foo.bar.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-578: -------------------------------------------------------------------------------- 1 | foo.*.notbaz -------------------------------------------------------------------------------- /fuzz/testdata/expr-579: -------------------------------------------------------------------------------- 1 | foo.*.notbaz[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-58: -------------------------------------------------------------------------------- 1 | foo[?`{"bar": [0]}` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-580: -------------------------------------------------------------------------------- 1 | foo.*.notbaz[-1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-581: -------------------------------------------------------------------------------- 1 | foo.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-582: -------------------------------------------------------------------------------- 1 | foo.*.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-583: -------------------------------------------------------------------------------- 1 | foo.*.*.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-584: -------------------------------------------------------------------------------- 1 | foo.*.*.*.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-585: -------------------------------------------------------------------------------- 1 | *.bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-586: -------------------------------------------------------------------------------- 1 | * -------------------------------------------------------------------------------- /fuzz/testdata/expr-587: -------------------------------------------------------------------------------- 1 | *.sub1 -------------------------------------------------------------------------------- /fuzz/testdata/expr-588: -------------------------------------------------------------------------------- 1 | *.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-589: -------------------------------------------------------------------------------- 1 | *.*.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-59: -------------------------------------------------------------------------------- 1 | foo[?`null` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-590: -------------------------------------------------------------------------------- 1 | *.sub1.foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-591: -------------------------------------------------------------------------------- 1 | foo[*].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-592: -------------------------------------------------------------------------------- 1 | foo[*].notbar -------------------------------------------------------------------------------- /fuzz/testdata/expr-593: -------------------------------------------------------------------------------- 1 | [*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-594: -------------------------------------------------------------------------------- 1 | [*].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-595: -------------------------------------------------------------------------------- 1 | [*].notbar -------------------------------------------------------------------------------- /fuzz/testdata/expr-596: -------------------------------------------------------------------------------- 1 | foo.bar[*].baz -------------------------------------------------------------------------------- /fuzz/testdata/expr-597: -------------------------------------------------------------------------------- 1 | foo.bar[*].baz[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-598: -------------------------------------------------------------------------------- 1 | foo.bar[*].baz[1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-599: -------------------------------------------------------------------------------- 1 | foo.bar[*].baz[2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-6: -------------------------------------------------------------------------------- 1 | foo.bad -------------------------------------------------------------------------------- /fuzz/testdata/expr-60: -------------------------------------------------------------------------------- 1 | foo[?`[1]` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-600: -------------------------------------------------------------------------------- 1 | foo.bar[*].baz[3] -------------------------------------------------------------------------------- /fuzz/testdata/expr-601: -------------------------------------------------------------------------------- 1 | foo.bar[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-602: -------------------------------------------------------------------------------- 1 | foo.bar[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-603: -------------------------------------------------------------------------------- 1 | foo.bar[0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-604: -------------------------------------------------------------------------------- 1 | foo.bar[0][0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-605: -------------------------------------------------------------------------------- 1 | foo.bar[0][0][0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-606: -------------------------------------------------------------------------------- 1 | foo[0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-607: -------------------------------------------------------------------------------- 1 | foo[*].bar[*].kind -------------------------------------------------------------------------------- /fuzz/testdata/expr-608: -------------------------------------------------------------------------------- 1 | foo[*].bar[0].kind -------------------------------------------------------------------------------- /fuzz/testdata/expr-609: -------------------------------------------------------------------------------- 1 | foo[*].bar.kind -------------------------------------------------------------------------------- /fuzz/testdata/expr-61: -------------------------------------------------------------------------------- 1 | foo[?`{"a":2}` == key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-610: -------------------------------------------------------------------------------- 1 | foo[*].bar[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-611: -------------------------------------------------------------------------------- 1 | foo[*].bar[1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-612: -------------------------------------------------------------------------------- 1 | foo[*].bar[2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-613: -------------------------------------------------------------------------------- 1 | foo[*].bar[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-614: -------------------------------------------------------------------------------- 1 | foo[*][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-615: -------------------------------------------------------------------------------- 1 | foo[*][1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-616: -------------------------------------------------------------------------------- 1 | foo[*][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-617: -------------------------------------------------------------------------------- 1 | foo[*][1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-618: -------------------------------------------------------------------------------- 1 | foo[*][0][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-619: -------------------------------------------------------------------------------- 1 | foo[*][1][0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-62: -------------------------------------------------------------------------------- 1 | foo[?key != `true`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-620: -------------------------------------------------------------------------------- 1 | foo[*][0][1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-621: -------------------------------------------------------------------------------- 1 | foo[*][1][1] -------------------------------------------------------------------------------- /fuzz/testdata/expr-622: -------------------------------------------------------------------------------- 1 | foo[*][2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-623: -------------------------------------------------------------------------------- 1 | foo[*][2][2] -------------------------------------------------------------------------------- /fuzz/testdata/expr-624: -------------------------------------------------------------------------------- 1 | bar[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-625: -------------------------------------------------------------------------------- 1 | bar[*].baz[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-626: -------------------------------------------------------------------------------- 1 | string[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-627: -------------------------------------------------------------------------------- 1 | hash[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-628: -------------------------------------------------------------------------------- 1 | number[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-629: -------------------------------------------------------------------------------- 1 | nullvalue[*] -------------------------------------------------------------------------------- /fuzz/testdata/expr-63: -------------------------------------------------------------------------------- 1 | foo[?key != `false`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-630: -------------------------------------------------------------------------------- 1 | string[*].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-631: -------------------------------------------------------------------------------- 1 | hash[*].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-632: -------------------------------------------------------------------------------- 1 | number[*].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-633: -------------------------------------------------------------------------------- 1 | nullvalue[*].foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-634: -------------------------------------------------------------------------------- 1 | nullvalue[*].foo[*].bar -------------------------------------------------------------------------------- /fuzz/testdata/expr-635: -------------------------------------------------------------------------------- 1 | string.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-636: -------------------------------------------------------------------------------- 1 | hash.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-637: -------------------------------------------------------------------------------- 1 | number.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-638: -------------------------------------------------------------------------------- 1 | array.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-639: -------------------------------------------------------------------------------- 1 | nullvalue.* -------------------------------------------------------------------------------- /fuzz/testdata/expr-64: -------------------------------------------------------------------------------- 1 | foo[?key != `0`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-640: -------------------------------------------------------------------------------- 1 | *[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-641: -------------------------------------------------------------------------------- 1 | `foo` -------------------------------------------------------------------------------- /fuzz/testdata/expr-642: -------------------------------------------------------------------------------- 1 | `foo\"quote` -------------------------------------------------------------------------------- /fuzz/testdata/expr-643: -------------------------------------------------------------------------------- 1 | `✓` -------------------------------------------------------------------------------- /fuzz/testdata/expr-644: -------------------------------------------------------------------------------- 1 | `foo\"bar` -------------------------------------------------------------------------------- /fuzz/testdata/expr-645: -------------------------------------------------------------------------------- 1 | `1\`` -------------------------------------------------------------------------------- /fuzz/testdata/expr-646: -------------------------------------------------------------------------------- 1 | `\\`.{a:`b`} -------------------------------------------------------------------------------- /fuzz/testdata/expr-647: -------------------------------------------------------------------------------- 1 | `foo` -------------------------------------------------------------------------------- /fuzz/testdata/expr-648: -------------------------------------------------------------------------------- 1 | ` foo` -------------------------------------------------------------------------------- /fuzz/testdata/expr-649: -------------------------------------------------------------------------------- 1 | `foo` -------------------------------------------------------------------------------- /fuzz/testdata/expr-65: -------------------------------------------------------------------------------- 1 | foo[?key != `1`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-650: -------------------------------------------------------------------------------- 1 | `foo\"quote` -------------------------------------------------------------------------------- /fuzz/testdata/expr-651: -------------------------------------------------------------------------------- 1 | `✓` -------------------------------------------------------------------------------- /fuzz/testdata/expr-652: -------------------------------------------------------------------------------- 1 | `foo\"bar` -------------------------------------------------------------------------------- /fuzz/testdata/expr-653: -------------------------------------------------------------------------------- 1 | `1\`` -------------------------------------------------------------------------------- /fuzz/testdata/expr-654: -------------------------------------------------------------------------------- 1 | `\\`.{a:`b`} -------------------------------------------------------------------------------- /fuzz/testdata/expr-655: -------------------------------------------------------------------------------- 1 | `foo` -------------------------------------------------------------------------------- /fuzz/testdata/expr-656: -------------------------------------------------------------------------------- 1 | ` foo` -------------------------------------------------------------------------------- /fuzz/testdata/expr-66: -------------------------------------------------------------------------------- 1 | foo[?key != `null`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-67: -------------------------------------------------------------------------------- 1 | foo[?key != `[1]`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-68: -------------------------------------------------------------------------------- 1 | foo[?key != `{"a":2}`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-69: -------------------------------------------------------------------------------- 1 | foo[?`true` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-7: -------------------------------------------------------------------------------- 1 | bad -------------------------------------------------------------------------------- /fuzz/testdata/expr-70: -------------------------------------------------------------------------------- 1 | foo[?`false` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-71: -------------------------------------------------------------------------------- 1 | foo[?`0` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-72: -------------------------------------------------------------------------------- 1 | foo[?`1` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-73: -------------------------------------------------------------------------------- 1 | foo[?`null` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-74: -------------------------------------------------------------------------------- 1 | foo[?`[1]` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-75: -------------------------------------------------------------------------------- 1 | foo[?`{"a":2}` != key] -------------------------------------------------------------------------------- /fuzz/testdata/expr-76: -------------------------------------------------------------------------------- 1 | reservations[].instances[?bar==`1`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-77: -------------------------------------------------------------------------------- 1 | reservations[*].instances[?bar==`1`] -------------------------------------------------------------------------------- /fuzz/testdata/expr-78: -------------------------------------------------------------------------------- 1 | reservations[].instances[?bar==`1`][] -------------------------------------------------------------------------------- /fuzz/testdata/expr-79: -------------------------------------------------------------------------------- 1 | foo[?bar==`1`].bar[0] -------------------------------------------------------------------------------- /fuzz/testdata/expr-8: -------------------------------------------------------------------------------- 1 | bad.morebad.morebad -------------------------------------------------------------------------------- /fuzz/testdata/expr-80: -------------------------------------------------------------------------------- 1 | foo[?a==`1`].b.c -------------------------------------------------------------------------------- /fuzz/testdata/expr-81: -------------------------------------------------------------------------------- 1 | abs(foo) -------------------------------------------------------------------------------- /fuzz/testdata/expr-82: -------------------------------------------------------------------------------- 1 | abs(foo) -------------------------------------------------------------------------------- /fuzz/testdata/expr-83: -------------------------------------------------------------------------------- 1 | abs(array[1]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-84: -------------------------------------------------------------------------------- 1 | abs(array[1]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-85: -------------------------------------------------------------------------------- 1 | abs(`-24`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-86: -------------------------------------------------------------------------------- 1 | abs(`-24`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-87: -------------------------------------------------------------------------------- 1 | avg(numbers) -------------------------------------------------------------------------------- /fuzz/testdata/expr-88: -------------------------------------------------------------------------------- 1 | ceil(`1.2`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-89: -------------------------------------------------------------------------------- 1 | ceil(decimals[0]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-9: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /fuzz/testdata/expr-90: -------------------------------------------------------------------------------- 1 | ceil(decimals[1]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-91: -------------------------------------------------------------------------------- 1 | ceil(decimals[2]) -------------------------------------------------------------------------------- /fuzz/testdata/expr-92: -------------------------------------------------------------------------------- 1 | contains('abc', 'a') -------------------------------------------------------------------------------- /fuzz/testdata/expr-93: -------------------------------------------------------------------------------- 1 | contains('abc', 'd') -------------------------------------------------------------------------------- /fuzz/testdata/expr-94: -------------------------------------------------------------------------------- 1 | contains(strings, 'a') -------------------------------------------------------------------------------- /fuzz/testdata/expr-95: -------------------------------------------------------------------------------- 1 | contains(decimals, `1.2`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-96: -------------------------------------------------------------------------------- 1 | contains(decimals, `false`) -------------------------------------------------------------------------------- /fuzz/testdata/expr-97: -------------------------------------------------------------------------------- 1 | ends_with(str, 'r') -------------------------------------------------------------------------------- /fuzz/testdata/expr-98: -------------------------------------------------------------------------------- 1 | ends_with(str, 'tr') -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jmespath/go-jmespath 2 | 3 | go 1.14 4 | 5 | require github.com/jmespath/go-jmespath/internal/testify v1.5.1 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= 4 | github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= 5 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 6 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 7 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 8 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 9 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 10 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 11 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 12 | -------------------------------------------------------------------------------- /internal/testify/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | .DS_Store 25 | -------------------------------------------------------------------------------- /internal/testify/.travis.gofmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -n "$(gofmt -l .)" ]; then 4 | echo "Go code is not formatted:" 5 | gofmt -d . 6 | exit 1 7 | fi 8 | 9 | go generate ./... 10 | if [ -n "$(git status -s -uno)" ]; then 11 | echo "Go generate output does not match commit." 12 | echo "Did you forget to run go generate ./... ?" 13 | exit 1 14 | fi 15 | -------------------------------------------------------------------------------- /internal/testify/.travis.gogenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # If GOMOD is defined we are running with Go Modules enabled, either 4 | # automatically or via the GO111MODULE=on environment variable. Codegen only 5 | # works with modules, so skip generation if modules is not in use. 6 | if [[ -z "$(go env GOMOD)" ]]; then 7 | echo "Skipping go generate because modules not enabled and required" 8 | exit 0 9 | fi 10 | 11 | go generate ./... 12 | if [ -n "$(git diff)" ]; then 13 | echo "Go generate had not been run" 14 | git diff 15 | exit 1 16 | fi 17 | -------------------------------------------------------------------------------- /internal/testify/.travis.govet.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | go vet ./... 6 | -------------------------------------------------------------------------------- /internal/testify/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | sudo: false 4 | 5 | matrix: 6 | include: 7 | - go: "1.8.x" 8 | - go: "1.9.x" 9 | - go: "1.10.x" 10 | - go: "1.11.x" 11 | env: GO111MODULE=off 12 | - go: "1.11.x" 13 | env: GO111MODULE=on 14 | - go: "1.12.x" 15 | env: GO111MODULE=off 16 | - go: "1.12.x" 17 | env: GO111MODULE=on 18 | - go: "1.13.x" 19 | env: GO111MODULE=off 20 | - go: "1.13.x" 21 | env: GO111MODULE=on 22 | - go: master 23 | script: 24 | - ./.travis.gogenerate.sh 25 | - ./.travis.gofmt.sh 26 | - ./.travis.govet.sh 27 | - go test -v -race ./... 28 | -------------------------------------------------------------------------------- /internal/testify/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Testify 2 | 3 | So you'd like to contribute to Testify? First of all, thank you! Testify is widely used, so each 4 | contribution has a significant impact within the Golang community! Below you'll find everything you 5 | need to know to get up to speed on the project. 6 | 7 | ## Philosophy 8 | 9 | The Testify maintainers generally attempt to follow widely accepted practices within the Golang 10 | community. That being said, the first priority is always to make sure that the package is useful to 11 | the community. A few general guidelines are listed here: 12 | 13 | *Keep it simple (whenever practical)* - Try not to expand the API unless the new surface area 14 | provides meaningful benefits. For example, don't add functions because they might be useful to 15 | someone, someday. Add what is useful to specific users, today. 16 | 17 | *Ease of use is paramount* - This means good documentation and package organization. It also means 18 | that we should try hard to use meaningful, descriptive function names, avoid breaking the API 19 | unnecessarily, and try not to surprise the user. 20 | 21 | *Quality isn't an afterthought* - Testify is a testing library, so it seems reasonable that we 22 | should have a decent test suite. This is doubly important because a bug in Testify doesn't just mean 23 | a bug in our users' code, it means a bug in our users' tests, which means a potentially unnoticed 24 | and hard-to-find bug in our users' code. 25 | 26 | ## Pull Requests 27 | 28 | We welcome pull requests! Please include the following in the description: 29 | 30 | * Motivation, why your change is important or helpful 31 | * Example usage (if applicable) 32 | * Whether you intend to add / change behavior or fix a bug 33 | 34 | Please be aware that the maintainers may ask for changes. This isn't a commentary on the quality of 35 | your idea or your code. Testify is the result of many contributions from many individuals, so we 36 | need to enforce certain practices and patterns to keep the package easy for others to understand. 37 | Essentially, we recognize that there are often many good ways to do a given thing, but we have to 38 | pick one and stick with it. 39 | 40 | See `MAINTAINERS.md` for a list of users who can approve / merge your changes. 41 | 42 | ## Issues 43 | 44 | If you find a bug or think of a useful feature you'd like to see added to Testify, the best thing 45 | you can do is make the necessary changes and open a pull request (see above). If that isn't an 46 | option, or if you'd like to discuss your change before you write the code, open an issue! 47 | 48 | Please provide enough context in the issue description that other members of the community can 49 | easily understand what it is that you'd like to see. 50 | 51 | -------------------------------------------------------------------------------- /internal/testify/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /internal/testify/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # Testify Maintainers 2 | 3 | The individuals listed below are active in the project and have the ability to approve and merge 4 | pull requests. 5 | 6 | * @glesica 7 | * @boyan-soubachov 8 | 9 | -------------------------------------------------------------------------------- /internal/testify/_codegen/.gitignore: -------------------------------------------------------------------------------- 1 | _codegen 2 | -------------------------------------------------------------------------------- /internal/testify/_codegen/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jmespath/go-jmespath/internal/testify/_codegen 2 | 3 | go 1.11 4 | 5 | require github.com/ernesto-jimenez/gogen v0.0.0-20180125220232-d7d4131e6607 6 | -------------------------------------------------------------------------------- /internal/testify/_codegen/go.sum: -------------------------------------------------------------------------------- 1 | github.com/ernesto-jimenez/gogen v0.0.0-20180125220232-d7d4131e6607 h1:cTavhURetDkezJCvxFggiyLeP40Mrk/TtVg2+ycw1Es= 2 | github.com/ernesto-jimenez/gogen v0.0.0-20180125220232-d7d4131e6607/go.mod h1:Cg4fM0vhYWOZdgM7RIOSTRNIc8/VT7CXClC3Ni86lu4= 3 | -------------------------------------------------------------------------------- /internal/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 5 | } 6 | -------------------------------------------------------------------------------- /internal/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /internal/testify/assert/assertion_order_test.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestCompare(t *testing.T) { 9 | for _, currCase := range []struct { 10 | less interface{} 11 | greater interface{} 12 | cType string 13 | }{ 14 | {less: "a", greater: "b", cType: "string"}, 15 | {less: int(1), greater: int(2), cType: "int"}, 16 | {less: int8(1), greater: int8(2), cType: "int8"}, 17 | {less: int16(1), greater: int16(2), cType: "int16"}, 18 | {less: int32(1), greater: int32(2), cType: "int32"}, 19 | {less: int64(1), greater: int64(2), cType: "int64"}, 20 | {less: uint8(1), greater: uint8(2), cType: "uint8"}, 21 | {less: uint16(1), greater: uint16(2), cType: "uint16"}, 22 | {less: uint32(1), greater: uint32(2), cType: "uint32"}, 23 | {less: uint64(1), greater: uint64(2), cType: "uint64"}, 24 | {less: float32(1), greater: float32(2), cType: "float32"}, 25 | {less: float64(1), greater: float64(2), cType: "float64"}, 26 | } { 27 | resLess, isComparable := compare(currCase.less, currCase.greater, reflect.ValueOf(currCase.less).Kind()) 28 | if !isComparable { 29 | t.Error("object should be comparable for type " + currCase.cType) 30 | } 31 | 32 | if resLess != 1 { 33 | t.Errorf("object less should be less than greater for type " + currCase.cType) 34 | } 35 | 36 | resGreater, isComparable := compare(currCase.greater, currCase.less, reflect.ValueOf(currCase.less).Kind()) 37 | if !isComparable { 38 | t.Error("object are comparable for type " + currCase.cType) 39 | } 40 | 41 | if resGreater != -1 { 42 | t.Errorf("object greater should be greater than less for type " + currCase.cType) 43 | } 44 | 45 | resEqual, isComparable := compare(currCase.less, currCase.less, reflect.ValueOf(currCase.less).Kind()) 46 | if !isComparable { 47 | t.Error("object are comparable for type " + currCase.cType) 48 | } 49 | 50 | if resEqual != 0 { 51 | t.Errorf("objects should be equal for type " + currCase.cType) 52 | } 53 | } 54 | } 55 | 56 | func TestGreater(t *testing.T) { 57 | mockT := new(testing.T) 58 | 59 | if !Greater(mockT, 2, 1) { 60 | t.Error("Greater should return true") 61 | } 62 | 63 | if Greater(mockT, 1, 1) { 64 | t.Error("Greater should return false") 65 | } 66 | 67 | if Greater(mockT, 1, 2) { 68 | t.Error("Greater should return false") 69 | } 70 | } 71 | 72 | func TestGreaterOrEqual(t *testing.T) { 73 | mockT := new(testing.T) 74 | 75 | if !GreaterOrEqual(mockT, 2, 1) { 76 | t.Error("Greater should return true") 77 | } 78 | 79 | if !GreaterOrEqual(mockT, 1, 1) { 80 | t.Error("Greater should return true") 81 | } 82 | 83 | if GreaterOrEqual(mockT, 1, 2) { 84 | t.Error("Greater should return false") 85 | } 86 | } 87 | 88 | func TestLess(t *testing.T) { 89 | mockT := new(testing.T) 90 | 91 | if !Less(mockT, 1, 2) { 92 | t.Error("Less should return true") 93 | } 94 | 95 | if Less(mockT, 1, 1) { 96 | t.Error("Less should return false") 97 | } 98 | 99 | if Less(mockT, 2, 1) { 100 | t.Error("Less should return false") 101 | } 102 | } 103 | 104 | func TestLessOrEqual(t *testing.T) { 105 | mockT := new(testing.T) 106 | 107 | if !LessOrEqual(mockT, 1, 2) { 108 | t.Error("Greater should return true") 109 | } 110 | 111 | if !LessOrEqual(mockT, 1, 1) { 112 | t.Error("Greater should return true") 113 | } 114 | 115 | if LessOrEqual(mockT, 2, 1) { 116 | t.Error("Greater should return false") 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /internal/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/jmespath/go-jmespath/internal/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/jmespath/go-jmespath/internal/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /internal/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /internal/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs" 17 | -------------------------------------------------------------------------------- /internal/testify/assert/http_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/http/httptest" 7 | "net/url" 8 | "strings" 9 | ) 10 | 11 | // httpCode is a helper that returns HTTP code of the response. It returns -1 and 12 | // an error if building a new request fails. 13 | func httpCode(handler http.HandlerFunc, method, url string, values url.Values) (int, error) { 14 | w := httptest.NewRecorder() 15 | req, err := http.NewRequest(method, url, nil) 16 | if err != nil { 17 | return -1, err 18 | } 19 | req.URL.RawQuery = values.Encode() 20 | handler(w, req) 21 | return w.Code, nil 22 | } 23 | 24 | // HTTPSuccess asserts that a specified handler returns a success status code. 25 | // 26 | // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) 27 | // 28 | // Returns whether the assertion was successful (true) or not (false). 29 | func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { 30 | if h, ok := t.(tHelper); ok { 31 | h.Helper() 32 | } 33 | code, err := httpCode(handler, method, url, values) 34 | if err != nil { 35 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) 36 | return false 37 | } 38 | 39 | isSuccessCode := code >= http.StatusOK && code <= http.StatusPartialContent 40 | if !isSuccessCode { 41 | Fail(t, fmt.Sprintf("Expected HTTP success status code for %q but received %d", url+"?"+values.Encode(), code)) 42 | } 43 | 44 | return isSuccessCode 45 | } 46 | 47 | // HTTPRedirect asserts that a specified handler returns a redirect status code. 48 | // 49 | // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 50 | // 51 | // Returns whether the assertion was successful (true) or not (false). 52 | func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { 53 | if h, ok := t.(tHelper); ok { 54 | h.Helper() 55 | } 56 | code, err := httpCode(handler, method, url, values) 57 | if err != nil { 58 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) 59 | return false 60 | } 61 | 62 | isRedirectCode := code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect 63 | if !isRedirectCode { 64 | Fail(t, fmt.Sprintf("Expected HTTP redirect status code for %q but received %d", url+"?"+values.Encode(), code)) 65 | } 66 | 67 | return isRedirectCode 68 | } 69 | 70 | // HTTPError asserts that a specified handler returns an error status code. 71 | // 72 | // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 73 | // 74 | // Returns whether the assertion was successful (true) or not (false). 75 | func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool { 76 | if h, ok := t.(tHelper); ok { 77 | h.Helper() 78 | } 79 | code, err := httpCode(handler, method, url, values) 80 | if err != nil { 81 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err)) 82 | return false 83 | } 84 | 85 | isErrorCode := code >= http.StatusBadRequest 86 | if !isErrorCode { 87 | Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code)) 88 | } 89 | 90 | return isErrorCode 91 | } 92 | 93 | // HTTPBody is a helper that returns HTTP body of the response. It returns 94 | // empty string if building a new request fails. 95 | func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string { 96 | w := httptest.NewRecorder() 97 | req, err := http.NewRequest(method, url+"?"+values.Encode(), nil) 98 | if err != nil { 99 | return "" 100 | } 101 | handler(w, req) 102 | return w.Body.String() 103 | } 104 | 105 | // HTTPBodyContains asserts that a specified handler returns a 106 | // body that contains a string. 107 | // 108 | // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 109 | // 110 | // Returns whether the assertion was successful (true) or not (false). 111 | func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { 112 | if h, ok := t.(tHelper); ok { 113 | h.Helper() 114 | } 115 | body := HTTPBody(handler, method, url, values) 116 | 117 | contains := strings.Contains(body, fmt.Sprint(str)) 118 | if !contains { 119 | Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) 120 | } 121 | 122 | return contains 123 | } 124 | 125 | // HTTPBodyNotContains asserts that a specified handler returns a 126 | // body that does not contain a string. 127 | // 128 | // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 129 | // 130 | // Returns whether the assertion was successful (true) or not (false). 131 | func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { 132 | if h, ok := t.(tHelper); ok { 133 | h.Helper() 134 | } 135 | body := HTTPBody(handler, method, url, values) 136 | 137 | contains := strings.Contains(body, fmt.Sprint(str)) 138 | if contains { 139 | Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) 140 | } 141 | 142 | return !contains 143 | } 144 | -------------------------------------------------------------------------------- /internal/testify/assert/http_assertions_test.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "net/url" 7 | "testing" 8 | ) 9 | 10 | func httpOK(w http.ResponseWriter, r *http.Request) { 11 | w.WriteHeader(http.StatusOK) 12 | } 13 | 14 | func httpRedirect(w http.ResponseWriter, r *http.Request) { 15 | w.WriteHeader(http.StatusTemporaryRedirect) 16 | } 17 | 18 | func httpError(w http.ResponseWriter, r *http.Request) { 19 | w.WriteHeader(http.StatusInternalServerError) 20 | } 21 | 22 | func TestHTTPSuccess(t *testing.T) { 23 | assert := New(t) 24 | 25 | mockT1 := new(testing.T) 26 | assert.Equal(HTTPSuccess(mockT1, httpOK, "GET", "/", nil), true) 27 | assert.False(mockT1.Failed()) 28 | 29 | mockT2 := new(testing.T) 30 | assert.Equal(HTTPSuccess(mockT2, httpRedirect, "GET", "/", nil), false) 31 | assert.True(mockT2.Failed()) 32 | 33 | mockT3 := new(testing.T) 34 | assert.Equal(HTTPSuccess(mockT3, httpError, "GET", "/", nil), false) 35 | assert.True(mockT3.Failed()) 36 | } 37 | 38 | func TestHTTPRedirect(t *testing.T) { 39 | assert := New(t) 40 | 41 | mockT1 := new(testing.T) 42 | assert.Equal(HTTPRedirect(mockT1, httpOK, "GET", "/", nil), false) 43 | assert.True(mockT1.Failed()) 44 | 45 | mockT2 := new(testing.T) 46 | assert.Equal(HTTPRedirect(mockT2, httpRedirect, "GET", "/", nil), true) 47 | assert.False(mockT2.Failed()) 48 | 49 | mockT3 := new(testing.T) 50 | assert.Equal(HTTPRedirect(mockT3, httpError, "GET", "/", nil), false) 51 | assert.True(mockT3.Failed()) 52 | } 53 | 54 | func TestHTTPError(t *testing.T) { 55 | assert := New(t) 56 | 57 | mockT1 := new(testing.T) 58 | assert.Equal(HTTPError(mockT1, httpOK, "GET", "/", nil), false) 59 | assert.True(mockT1.Failed()) 60 | 61 | mockT2 := new(testing.T) 62 | assert.Equal(HTTPError(mockT2, httpRedirect, "GET", "/", nil), false) 63 | assert.True(mockT2.Failed()) 64 | 65 | mockT3 := new(testing.T) 66 | assert.Equal(HTTPError(mockT3, httpError, "GET", "/", nil), true) 67 | assert.False(mockT3.Failed()) 68 | } 69 | 70 | func TestHTTPStatusesWrapper(t *testing.T) { 71 | assert := New(t) 72 | mockAssert := New(new(testing.T)) 73 | 74 | assert.Equal(mockAssert.HTTPSuccess(httpOK, "GET", "/", nil), true) 75 | assert.Equal(mockAssert.HTTPSuccess(httpRedirect, "GET", "/", nil), false) 76 | assert.Equal(mockAssert.HTTPSuccess(httpError, "GET", "/", nil), false) 77 | 78 | assert.Equal(mockAssert.HTTPRedirect(httpOK, "GET", "/", nil), false) 79 | assert.Equal(mockAssert.HTTPRedirect(httpRedirect, "GET", "/", nil), true) 80 | assert.Equal(mockAssert.HTTPRedirect(httpError, "GET", "/", nil), false) 81 | 82 | assert.Equal(mockAssert.HTTPError(httpOK, "GET", "/", nil), false) 83 | assert.Equal(mockAssert.HTTPError(httpRedirect, "GET", "/", nil), false) 84 | assert.Equal(mockAssert.HTTPError(httpError, "GET", "/", nil), true) 85 | } 86 | 87 | func httpHelloName(w http.ResponseWriter, r *http.Request) { 88 | name := r.FormValue("name") 89 | w.Write([]byte(fmt.Sprintf("Hello, %s!", name))) 90 | } 91 | 92 | func TestHTTPRequestWithNoParams(t *testing.T) { 93 | var got *http.Request 94 | handler := func(w http.ResponseWriter, r *http.Request) { 95 | got = r 96 | w.WriteHeader(http.StatusOK) 97 | } 98 | 99 | True(t, HTTPSuccess(t, handler, "GET", "/url", nil)) 100 | 101 | Empty(t, got.URL.Query()) 102 | Equal(t, "/url", got.URL.RequestURI()) 103 | } 104 | 105 | func TestHTTPRequestWithParams(t *testing.T) { 106 | var got *http.Request 107 | handler := func(w http.ResponseWriter, r *http.Request) { 108 | got = r 109 | w.WriteHeader(http.StatusOK) 110 | } 111 | params := url.Values{} 112 | params.Add("id", "12345") 113 | 114 | True(t, HTTPSuccess(t, handler, "GET", "/url", params)) 115 | 116 | Equal(t, url.Values{"id": []string{"12345"}}, got.URL.Query()) 117 | Equal(t, "/url?id=12345", got.URL.String()) 118 | Equal(t, "/url?id=12345", got.URL.RequestURI()) 119 | } 120 | 121 | func TestHttpBody(t *testing.T) { 122 | assert := New(t) 123 | mockT := new(testing.T) 124 | 125 | assert.True(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) 126 | assert.True(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) 127 | assert.False(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) 128 | 129 | assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) 130 | assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) 131 | assert.True(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) 132 | } 133 | 134 | func TestHttpBodyWrappers(t *testing.T) { 135 | assert := New(t) 136 | mockAssert := New(new(testing.T)) 137 | 138 | assert.True(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) 139 | assert.True(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) 140 | assert.False(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) 141 | 142 | assert.False(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!")) 143 | assert.False(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World")) 144 | assert.True(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world")) 145 | 146 | } 147 | -------------------------------------------------------------------------------- /internal/testify/doc.go: -------------------------------------------------------------------------------- 1 | // Package testify is a set of packages that provide many tools for testifying that your code will behave as you intend. 2 | // 3 | // testify contains the following packages: 4 | // 5 | // The assert package provides a comprehensive set of assertion functions that tie in to the Go testing system. 6 | // 7 | // The http package contains tools to make it easier to test http activity using the Go testing system. 8 | // 9 | // The mock package provides a system by which it is possible to mock your objects and verify calls are happening as expected. 10 | // 11 | // The suite package provides a basic structure for using structs as testing suites, and methods on those structs as tests. It includes setup/teardown functionality in the way of interfaces. 12 | package testify 13 | 14 | // blank imports help docs. 15 | import ( 16 | // assert package 17 | _ "github.com/jmespath/go-jmespath/internal/testify/assert" 18 | // http package 19 | _ "github.com/jmespath/go-jmespath/internal/testify/http" 20 | // mock package 21 | _ "github.com/jmespath/go-jmespath/internal/testify/mock" 22 | ) 23 | -------------------------------------------------------------------------------- /internal/testify/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jmespath/go-jmespath/internal/testify 2 | 3 | require ( 4 | github.com/davecgh/go-spew v1.1.0 5 | github.com/pmezard/go-difflib v1.0.0 6 | github.com/stretchr/objx v0.1.0 7 | gopkg.in/yaml.v2 v2.2.8 8 | ) 9 | 10 | go 1.13 11 | -------------------------------------------------------------------------------- /internal/testify/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 4 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 5 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 6 | github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= 7 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 8 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 9 | gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= 10 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 11 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 12 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 13 | -------------------------------------------------------------------------------- /internal/testify/http/doc.go: -------------------------------------------------------------------------------- 1 | // Package http DEPRECATED USE net/http/httptest 2 | package http 3 | -------------------------------------------------------------------------------- /internal/testify/http/test_response_writer.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | // TestResponseWriter DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead. 8 | type TestResponseWriter struct { 9 | 10 | // StatusCode is the last int written by the call to WriteHeader(int) 11 | StatusCode int 12 | 13 | // Output is a string containing the written bytes using the Write([]byte) func. 14 | Output string 15 | 16 | // header is the internal storage of the http.Header object 17 | header http.Header 18 | } 19 | 20 | // Header DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead. 21 | func (rw *TestResponseWriter) Header() http.Header { 22 | 23 | if rw.header == nil { 24 | rw.header = make(http.Header) 25 | } 26 | 27 | return rw.header 28 | } 29 | 30 | // Write DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead. 31 | func (rw *TestResponseWriter) Write(bytes []byte) (int, error) { 32 | 33 | // assume 200 success if no header has been set 34 | if rw.StatusCode == 0 { 35 | rw.WriteHeader(200) 36 | } 37 | 38 | // add these bytes to the output string 39 | rw.Output = rw.Output + string(bytes) 40 | 41 | // return normal values 42 | return 0, nil 43 | 44 | } 45 | 46 | // WriteHeader DEPRECATED: We recommend you use http://golang.org/pkg/net/http/httptest instead. 47 | func (rw *TestResponseWriter) WriteHeader(i int) { 48 | rw.StatusCode = i 49 | } 50 | -------------------------------------------------------------------------------- /internal/testify/http/test_round_tripper.go: -------------------------------------------------------------------------------- 1 | package http 2 | 3 | import ( 4 | "github.com/jmespath/go-jmespath/internal/testify/mock" 5 | "net/http" 6 | ) 7 | 8 | // TestRoundTripper DEPRECATED USE net/http/httptest 9 | type TestRoundTripper struct { 10 | mock.Mock 11 | } 12 | 13 | // RoundTrip DEPRECATED USE net/http/httptest 14 | func (t *TestRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { 15 | args := t.Called(req) 16 | return args.Get(0).(*http.Response), args.Error(1) 17 | } 18 | -------------------------------------------------------------------------------- /internal/testify/mock/doc.go: -------------------------------------------------------------------------------- 1 | // Package mock provides a system by which it is possible to mock your objects 2 | // and verify calls are happening as expected. 3 | // 4 | // Example Usage 5 | // 6 | // The mock package provides an object, Mock, that tracks activity on another object. It is usually 7 | // embedded into a test object as shown below: 8 | // 9 | // type MyTestObject struct { 10 | // // add a Mock object instance 11 | // mock.Mock 12 | // 13 | // // other fields go here as normal 14 | // } 15 | // 16 | // When implementing the methods of an interface, you wire your functions up 17 | // to call the Mock.Called(args...) method, and return the appropriate values. 18 | // 19 | // For example, to mock a method that saves the name and age of a person and returns 20 | // the year of their birth or an error, you might write this: 21 | // 22 | // func (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) { 23 | // args := o.Called(firstname, lastname, age) 24 | // return args.Int(0), args.Error(1) 25 | // } 26 | // 27 | // The Int, Error and Bool methods are examples of strongly typed getters that take the argument 28 | // index position. Given this argument list: 29 | // 30 | // (12, true, "Something") 31 | // 32 | // You could read them out strongly typed like this: 33 | // 34 | // args.Int(0) 35 | // args.Bool(1) 36 | // args.String(2) 37 | // 38 | // For objects of your own type, use the generic Arguments.Get(index) method and make a type assertion: 39 | // 40 | // return args.Get(0).(*MyObject), args.Get(1).(*AnotherObjectOfMine) 41 | // 42 | // This may cause a panic if the object you are getting is nil (the type assertion will fail), in those 43 | // cases you should check for nil first. 44 | package mock 45 | -------------------------------------------------------------------------------- /internal/testify/package_test.go: -------------------------------------------------------------------------------- 1 | package testify 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/jmespath/go-jmespath/internal/testify/assert" 7 | ) 8 | 9 | func TestImports(t *testing.T) { 10 | if assert.Equal(t, 1, 1) != true { 11 | t.Error("Something is wrong.") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /internal/testify/require/doc.go: -------------------------------------------------------------------------------- 1 | // Package require implements the same assertions as the `assert` package but 2 | // stops test execution when a test fails. 3 | // 4 | // Example Usage 5 | // 6 | // The following is a complete example using require in a standard test function: 7 | // import ( 8 | // "testing" 9 | // "github.com/jmespath/go-jmespath/internal/testify/require" 10 | // ) 11 | // 12 | // func TestSomething(t *testing.T) { 13 | // 14 | // var a string = "Hello" 15 | // var b string = "Hello" 16 | // 17 | // require.Equal(t, a, b, "The two words should be the same.") 18 | // 19 | // } 20 | // 21 | // Assertions 22 | // 23 | // The `require` package have same global functions as in the `assert` package, 24 | // but instead of returning a boolean result they call `t.FailNow()`. 25 | // 26 | // Every assertion function also takes an optional string message as the final argument, 27 | // allowing custom error messages to be appended to the message the assertion method outputs. 28 | package require 29 | -------------------------------------------------------------------------------- /internal/testify/require/forward_requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=require -template=require_forward.go.tmpl -include-format-funcs" 17 | -------------------------------------------------------------------------------- /internal/testify/require/require.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.Comment}} 2 | func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } 5 | t.FailNow() 6 | } 7 | -------------------------------------------------------------------------------- /internal/testify/require/require_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /internal/testify/require/requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // TestingT is an interface wrapper around *testing.T 4 | type TestingT interface { 5 | Errorf(format string, args ...interface{}) 6 | FailNow() 7 | } 8 | 9 | type tHelper interface { 10 | Helper() 11 | } 12 | 13 | // ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful 14 | // for table driven tests. 15 | type ComparisonAssertionFunc func(TestingT, interface{}, interface{}, ...interface{}) 16 | 17 | // ValueAssertionFunc is a common function prototype when validating a single value. Can be useful 18 | // for table driven tests. 19 | type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) 20 | 21 | // BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful 22 | // for table driven tests. 23 | type BoolAssertionFunc func(TestingT, bool, ...interface{}) 24 | 25 | // ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful 26 | // for table driven tests. 27 | type ErrorAssertionFunc func(TestingT, error, ...interface{}) 28 | 29 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=require -template=require.go.tmpl -include-format-funcs" 30 | -------------------------------------------------------------------------------- /internal/testify/suite/doc.go: -------------------------------------------------------------------------------- 1 | // Package suite contains logic for creating testing suite structs 2 | // and running the methods on those structs as tests. The most useful 3 | // piece of this package is that you can create setup/teardown methods 4 | // on your testing suites, which will run before/after the whole suite 5 | // or individual tests (depending on which interface(s) you 6 | // implement). 7 | // 8 | // A testing suite is usually built by first extending the built-in 9 | // suite functionality from suite.Suite in testify. Alternatively, 10 | // you could reproduce that logic on your own if you wanted (you 11 | // just need to implement the TestingSuite interface from 12 | // suite/interfaces.go). 13 | // 14 | // After that, you can implement any of the interfaces in 15 | // suite/interfaces.go to add setup/teardown functionality to your 16 | // suite, and add any methods that start with "Test" to add tests. 17 | // Methods that do not match any suite interfaces and do not begin 18 | // with "Test" will not be run by testify, and can safely be used as 19 | // helper methods. 20 | // 21 | // Once you've built your testing suite, you need to run the suite 22 | // (using suite.Run from testify) inside any function that matches the 23 | // identity that "go test" is already looking for (i.e. 24 | // func(*testing.T)). 25 | // 26 | // Regular expression to select test suites specified command-line 27 | // argument "-run". Regular expression to select the methods 28 | // of test suites specified command-line argument "-m". 29 | // Suite object has assertion methods. 30 | // 31 | // A crude example: 32 | // // Basic imports 33 | // import ( 34 | // "testing" 35 | // "github.com/jmespath/go-jmespath/internal/testify/assert" 36 | // "github.com/jmespath/go-jmespath/internal/testify/suite" 37 | // ) 38 | // 39 | // // Define the suite, and absorb the built-in basic suite 40 | // // functionality from testify - including a T() method which 41 | // // returns the current testing context 42 | // type ExampleTestSuite struct { 43 | // suite.Suite 44 | // VariableThatShouldStartAtFive int 45 | // } 46 | // 47 | // // Make sure that VariableThatShouldStartAtFive is set to five 48 | // // before each test 49 | // func (suite *ExampleTestSuite) SetupTest() { 50 | // suite.VariableThatShouldStartAtFive = 5 51 | // } 52 | // 53 | // // All methods that begin with "Test" are run as tests within a 54 | // // suite. 55 | // func (suite *ExampleTestSuite) TestExample() { 56 | // assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) 57 | // suite.Equal(5, suite.VariableThatShouldStartAtFive) 58 | // } 59 | // 60 | // // In order for 'go test' to run this suite, we need to create 61 | // // a normal test function and pass our suite to suite.Run 62 | // func TestExampleTestSuite(t *testing.T) { 63 | // suite.Run(t, new(ExampleTestSuite)) 64 | // } 65 | package suite 66 | -------------------------------------------------------------------------------- /internal/testify/suite/interfaces.go: -------------------------------------------------------------------------------- 1 | package suite 2 | 3 | import "testing" 4 | 5 | // TestingSuite can store and return the current *testing.T context 6 | // generated by 'go test'. 7 | type TestingSuite interface { 8 | T() *testing.T 9 | SetT(*testing.T) 10 | } 11 | 12 | // SetupAllSuite has a SetupSuite method, which will run before the 13 | // tests in the suite are run. 14 | type SetupAllSuite interface { 15 | SetupSuite() 16 | } 17 | 18 | // SetupTestSuite has a SetupTest method, which will run before each 19 | // test in the suite. 20 | type SetupTestSuite interface { 21 | SetupTest() 22 | } 23 | 24 | // TearDownAllSuite has a TearDownSuite method, which will run after 25 | // all the tests in the suite have been run. 26 | type TearDownAllSuite interface { 27 | TearDownSuite() 28 | } 29 | 30 | // TearDownTestSuite has a TearDownTest method, which will run after 31 | // each test in the suite. 32 | type TearDownTestSuite interface { 33 | TearDownTest() 34 | } 35 | 36 | // BeforeTest has a function to be executed right before the test 37 | // starts and receives the suite and test names as input 38 | type BeforeTest interface { 39 | BeforeTest(suiteName, testName string) 40 | } 41 | 42 | // AfterTest has a function to be executed right after the test 43 | // finishes and receives the suite and test names as input 44 | type AfterTest interface { 45 | AfterTest(suiteName, testName string) 46 | } 47 | -------------------------------------------------------------------------------- /internal/testify/suite/suite.go: -------------------------------------------------------------------------------- 1 | package suite 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "reflect" 8 | "regexp" 9 | "runtime/debug" 10 | "sync" 11 | "testing" 12 | 13 | "github.com/jmespath/go-jmespath/internal/testify/assert" 14 | "github.com/jmespath/go-jmespath/internal/testify/require" 15 | ) 16 | 17 | var allTestsFilter = func(_, _ string) (bool, error) { return true, nil } 18 | var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run") 19 | 20 | // Suite is a basic testing suite with methods for storing and 21 | // retrieving the current *testing.T context. 22 | type Suite struct { 23 | *assert.Assertions 24 | require *require.Assertions 25 | t *testing.T 26 | } 27 | 28 | // T retrieves the current *testing.T context. 29 | func (suite *Suite) T() *testing.T { 30 | return suite.t 31 | } 32 | 33 | // SetT sets the current *testing.T context. 34 | func (suite *Suite) SetT(t *testing.T) { 35 | suite.t = t 36 | suite.Assertions = assert.New(t) 37 | suite.require = require.New(t) 38 | } 39 | 40 | // Require returns a require context for suite. 41 | func (suite *Suite) Require() *require.Assertions { 42 | if suite.require == nil { 43 | suite.require = require.New(suite.T()) 44 | } 45 | return suite.require 46 | } 47 | 48 | // Assert returns an assert context for suite. Normally, you can call 49 | // `suite.NoError(expected, actual)`, but for situations where the embedded 50 | // methods are overridden (for example, you might want to override 51 | // assert.Assertions with require.Assertions), this method is provided so you 52 | // can call `suite.Assert().NoError()`. 53 | func (suite *Suite) Assert() *assert.Assertions { 54 | if suite.Assertions == nil { 55 | suite.Assertions = assert.New(suite.T()) 56 | } 57 | return suite.Assertions 58 | } 59 | 60 | func failOnPanic(t *testing.T) { 61 | r := recover() 62 | if r != nil { 63 | t.Errorf("test panicked: %v\n%s", r, debug.Stack()) 64 | t.FailNow() 65 | } 66 | } 67 | 68 | // Run provides suite functionality around golang subtests. It should be 69 | // called in place of t.Run(name, func(t *testing.T)) in test suite code. 70 | // The passed-in func will be executed as a subtest with a fresh instance of t. 71 | // Provides compatibility with go test pkg -run TestSuite/TestName/SubTestName. 72 | func (suite *Suite) Run(name string, subtest func()) bool { 73 | oldT := suite.T() 74 | defer suite.SetT(oldT) 75 | return oldT.Run(name, func(t *testing.T) { 76 | suite.SetT(t) 77 | subtest() 78 | }) 79 | } 80 | 81 | // Run takes a testing suite and runs all of the tests attached 82 | // to it. 83 | func Run(t *testing.T, suite TestingSuite) { 84 | testsSync := &sync.WaitGroup{} 85 | suite.SetT(t) 86 | defer failOnPanic(t) 87 | 88 | suiteSetupDone := false 89 | 90 | methodFinder := reflect.TypeOf(suite) 91 | tests := []testing.InternalTest{} 92 | for index := 0; index < methodFinder.NumMethod(); index++ { 93 | method := methodFinder.Method(index) 94 | ok, err := methodFilter(method.Name) 95 | if err != nil { 96 | fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err) 97 | os.Exit(1) 98 | } 99 | if !ok { 100 | continue 101 | } 102 | if !suiteSetupDone { 103 | if setupAllSuite, ok := suite.(SetupAllSuite); ok { 104 | setupAllSuite.SetupSuite() 105 | } 106 | defer func() { 107 | if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { 108 | testsSync.Wait() 109 | tearDownAllSuite.TearDownSuite() 110 | } 111 | }() 112 | suiteSetupDone = true 113 | } 114 | test := testing.InternalTest{ 115 | Name: method.Name, 116 | F: func(t *testing.T) { 117 | defer testsSync.Done() 118 | parentT := suite.T() 119 | suite.SetT(t) 120 | defer failOnPanic(t) 121 | 122 | if setupTestSuite, ok := suite.(SetupTestSuite); ok { 123 | setupTestSuite.SetupTest() 124 | } 125 | if beforeTestSuite, ok := suite.(BeforeTest); ok { 126 | beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name) 127 | } 128 | defer func() { 129 | if afterTestSuite, ok := suite.(AfterTest); ok { 130 | afterTestSuite.AfterTest(methodFinder.Elem().Name(), method.Name) 131 | } 132 | if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok { 133 | tearDownTestSuite.TearDownTest() 134 | } 135 | suite.SetT(parentT) 136 | }() 137 | method.Func.Call([]reflect.Value{reflect.ValueOf(suite)}) 138 | }, 139 | } 140 | tests = append(tests, test) 141 | testsSync.Add(1) 142 | } 143 | runTests(t, tests) 144 | } 145 | 146 | func runTests(t testing.TB, tests []testing.InternalTest) { 147 | r, ok := t.(runner) 148 | if !ok { // backwards compatibility with Go 1.6 and below 149 | if !testing.RunTests(allTestsFilter, tests) { 150 | t.Fail() 151 | } 152 | return 153 | } 154 | 155 | for _, test := range tests { 156 | r.Run(test.Name, test.F) 157 | } 158 | } 159 | 160 | // Filtering method according to set regular expression 161 | // specified command-line argument -m 162 | func methodFilter(name string) (bool, error) { 163 | if ok, _ := regexp.MatchString("^Test", name); !ok { 164 | return false, nil 165 | } 166 | return regexp.MatchString(*matchMethod, name) 167 | } 168 | 169 | type runner interface { 170 | Run(name string, f func(t *testing.T)) bool 171 | } 172 | -------------------------------------------------------------------------------- /parser_test.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/jmespath/go-jmespath/internal/testify/assert" 8 | ) 9 | 10 | var parsingErrorTests = []struct { 11 | expression string 12 | msg string 13 | }{ 14 | {"foo.", "Incopmlete expression"}, 15 | {"[foo", "Incopmlete expression"}, 16 | {"]", "Invalid"}, 17 | {")", "Invalid"}, 18 | {"}", "Invalid"}, 19 | {"foo..bar", "Invalid"}, 20 | {`foo."bar`, "Forwards lexer errors"}, 21 | {`{foo: bar`, "Incomplete expression"}, 22 | {`{foo bar}`, "Invalid"}, 23 | {`[foo bar]`, "Invalid"}, 24 | {`foo@`, "Invalid"}, 25 | {`&&&&&&&&&&&&t(`, "Invalid"}, 26 | {`[*][`, "Invalid"}, 27 | } 28 | 29 | func TestParsingErrors(t *testing.T) { 30 | assert := assert.New(t) 31 | parser := NewParser() 32 | for _, tt := range parsingErrorTests { 33 | _, err := parser.Parse(tt.expression) 34 | assert.NotNil(err, fmt.Sprintf("Expected parsing error: %s, for expression: %s", tt.msg, tt.expression)) 35 | } 36 | } 37 | 38 | var prettyPrinted = `ASTProjection { 39 | children: { 40 | ASTField { 41 | value: "foo" 42 | } 43 | ASTSubexpression { 44 | children: { 45 | ASTSubexpression { 46 | children: { 47 | ASTField { 48 | value: "bar" 49 | } 50 | ASTField { 51 | value: "baz" 52 | } 53 | } 54 | ASTField { 55 | value: "qux" 56 | } 57 | } 58 | } 59 | ` 60 | 61 | var prettyPrintedCompNode = `ASTFilterProjection { 62 | children: { 63 | ASTField { 64 | value: "a" 65 | } 66 | ASTIdentity { 67 | } 68 | ASTComparator { 69 | value: tLTE 70 | children: { 71 | ASTField { 72 | value: "b" 73 | } 74 | ASTField { 75 | value: "c" 76 | } 77 | } 78 | } 79 | ` 80 | 81 | func TestPrettyPrintedAST(t *testing.T) { 82 | assert := assert.New(t) 83 | parser := NewParser() 84 | parsed, _ := parser.Parse("foo[*].bar.baz.qux") 85 | assert.Equal(parsed.PrettyPrint(0), prettyPrinted) 86 | } 87 | 88 | func TestPrettyPrintedCompNode(t *testing.T) { 89 | assert := assert.New(t) 90 | parser := NewParser() 91 | parsed, _ := parser.Parse("a[?b<=c]") 92 | assert.Equal(parsed.PrettyPrint(0), prettyPrintedCompNode) 93 | } 94 | 95 | func BenchmarkParseIdentifier(b *testing.B) { 96 | runParseBenchmark(b, exprIdentifier) 97 | } 98 | 99 | func BenchmarkParseSubexpression(b *testing.B) { 100 | runParseBenchmark(b, exprSubexpr) 101 | } 102 | 103 | func BenchmarkParseDeeplyNested50(b *testing.B) { 104 | runParseBenchmark(b, deeplyNested50) 105 | } 106 | 107 | func BenchmarkParseDeepNested50Pipe(b *testing.B) { 108 | runParseBenchmark(b, deeplyNested50Pipe) 109 | } 110 | 111 | func BenchmarkParseDeepNested50Index(b *testing.B) { 112 | runParseBenchmark(b, deeplyNested50Index) 113 | } 114 | 115 | func BenchmarkParseQuotedIdentifier(b *testing.B) { 116 | runParseBenchmark(b, exprQuotedIdentifier) 117 | } 118 | 119 | func BenchmarkParseQuotedIdentifierEscapes(b *testing.B) { 120 | runParseBenchmark(b, quotedIdentifierEscapes) 121 | } 122 | 123 | func BenchmarkParseRawStringLiteral(b *testing.B) { 124 | runParseBenchmark(b, rawStringLiteral) 125 | } 126 | 127 | func BenchmarkParseDeepProjection104(b *testing.B) { 128 | runParseBenchmark(b, deepProjection104) 129 | } 130 | 131 | func runParseBenchmark(b *testing.B, expression string) { 132 | assert := assert.New(b) 133 | parser := NewParser() 134 | for i := 0; i < b.N; i++ { 135 | _, err := parser.Parse(expression) 136 | if err != nil { 137 | assert.Fail("Failed to parse expression") 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /toktype_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=tokType"; DO NOT EDIT. 2 | 3 | package jmespath 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[tUnknown-0] 12 | _ = x[tStar-1] 13 | _ = x[tDot-2] 14 | _ = x[tFilter-3] 15 | _ = x[tFlatten-4] 16 | _ = x[tLparen-5] 17 | _ = x[tRparen-6] 18 | _ = x[tLbracket-7] 19 | _ = x[tRbracket-8] 20 | _ = x[tLbrace-9] 21 | _ = x[tRbrace-10] 22 | _ = x[tOr-11] 23 | _ = x[tPipe-12] 24 | _ = x[tNumber-13] 25 | _ = x[tUnquotedIdentifier-14] 26 | _ = x[tQuotedIdentifier-15] 27 | _ = x[tComma-16] 28 | _ = x[tColon-17] 29 | _ = x[tLT-18] 30 | _ = x[tLTE-19] 31 | _ = x[tGT-20] 32 | _ = x[tGTE-21] 33 | _ = x[tEQ-22] 34 | _ = x[tNE-23] 35 | _ = x[tJSONLiteral-24] 36 | _ = x[tStringLiteral-25] 37 | _ = x[tCurrent-26] 38 | _ = x[tExpref-27] 39 | _ = x[tAnd-28] 40 | _ = x[tNot-29] 41 | _ = x[tEOF-30] 42 | } 43 | 44 | const _tokType_name = "tUnknowntStartDottFiltertFlattentLparentRparentLbrackettRbrackettLbracetRbracetOrtPipetNumbertUnquotedIdentifiertQuotedIdentifiertCommatColontLTtLTEtGTtGTEtEQtNEtJSONLiteraltStringLiteraltCurrenttExpreftAndtNottEOF" 45 | 46 | var _tokType_index = [...]uint8{0, 8, 13, 17, 24, 32, 39, 46, 55, 64, 71, 78, 81, 86, 93, 112, 129, 135, 141, 144, 148, 151, 155, 158, 161, 173, 187, 195, 202, 206, 210, 214} 47 | 48 | func (i tokType) String() string { 49 | if i < 0 || i >= tokType(len(_tokType_index)-1) { 50 | return "tokType(" + strconv.FormatInt(int64(i), 10) + ")" 51 | } 52 | return _tokType_name[_tokType_index[i]:_tokType_index[i+1]] 53 | } 54 | -------------------------------------------------------------------------------- /util.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import ( 4 | "errors" 5 | "reflect" 6 | ) 7 | 8 | // IsFalse determines if an object is false based on the JMESPath spec. 9 | // JMESPath defines false values to be any of: 10 | // - An empty string array, or hash. 11 | // - The boolean value false. 12 | // - nil 13 | func isFalse(value interface{}) bool { 14 | switch v := value.(type) { 15 | case bool: 16 | return !v 17 | case []interface{}: 18 | return len(v) == 0 19 | case map[string]interface{}: 20 | return len(v) == 0 21 | case string: 22 | return len(v) == 0 23 | case nil: 24 | return true 25 | } 26 | // Try the reflection cases before returning false. 27 | rv := reflect.ValueOf(value) 28 | switch rv.Kind() { 29 | case reflect.Struct: 30 | // A struct type will never be false, even if 31 | // all of its values are the zero type. 32 | return false 33 | case reflect.Slice, reflect.Map: 34 | return rv.Len() == 0 35 | case reflect.Ptr: 36 | if rv.IsNil() { 37 | return true 38 | } 39 | // If it's a pointer type, we'll try to deref the pointer 40 | // and evaluate the pointer value for isFalse. 41 | element := rv.Elem() 42 | return isFalse(element.Interface()) 43 | } 44 | return false 45 | } 46 | 47 | // ObjsEqual is a generic object equality check. 48 | // It will take two arbitrary objects and recursively determine 49 | // if they are equal. 50 | func objsEqual(left interface{}, right interface{}) bool { 51 | return reflect.DeepEqual(left, right) 52 | } 53 | 54 | // SliceParam refers to a single part of a slice. 55 | // A slice consists of a start, a stop, and a step, similar to 56 | // python slices. 57 | type sliceParam struct { 58 | N int 59 | Specified bool 60 | } 61 | 62 | // Slice supports [start:stop:step] style slicing that's supported in JMESPath. 63 | func slice(slice []interface{}, parts []sliceParam) ([]interface{}, error) { 64 | computed, err := computeSliceParams(len(slice), parts) 65 | if err != nil { 66 | return nil, err 67 | } 68 | start, stop, step := computed[0], computed[1], computed[2] 69 | result := []interface{}{} 70 | if step > 0 { 71 | for i := start; i < stop; i += step { 72 | result = append(result, slice[i]) 73 | } 74 | } else { 75 | for i := start; i > stop; i += step { 76 | result = append(result, slice[i]) 77 | } 78 | } 79 | return result, nil 80 | } 81 | 82 | func computeSliceParams(length int, parts []sliceParam) ([]int, error) { 83 | var start, stop, step int 84 | if !parts[2].Specified { 85 | step = 1 86 | } else if parts[2].N == 0 { 87 | return nil, errors.New("Invalid slice, step cannot be 0") 88 | } else { 89 | step = parts[2].N 90 | } 91 | var stepValueNegative bool 92 | if step < 0 { 93 | stepValueNegative = true 94 | } else { 95 | stepValueNegative = false 96 | } 97 | 98 | if !parts[0].Specified { 99 | if stepValueNegative { 100 | start = length - 1 101 | } else { 102 | start = 0 103 | } 104 | } else { 105 | start = capSlice(length, parts[0].N, step) 106 | } 107 | 108 | if !parts[1].Specified { 109 | if stepValueNegative { 110 | stop = -1 111 | } else { 112 | stop = length 113 | } 114 | } else { 115 | stop = capSlice(length, parts[1].N, step) 116 | } 117 | return []int{start, stop, step}, nil 118 | } 119 | 120 | func capSlice(length int, actual int, step int) int { 121 | if actual < 0 { 122 | actual += length 123 | if actual < 0 { 124 | if step < 0 { 125 | actual = -1 126 | } else { 127 | actual = 0 128 | } 129 | } 130 | } else if actual >= length { 131 | if step < 0 { 132 | actual = length - 1 133 | } else { 134 | actual = length 135 | } 136 | } 137 | return actual 138 | } 139 | 140 | // ToArrayNum converts an empty interface type to a slice of float64. 141 | // If any element in the array cannot be converted, then nil is returned 142 | // along with a second value of false. 143 | func toArrayNum(data interface{}) ([]float64, bool) { 144 | // Is there a better way to do this with reflect? 145 | if d, ok := data.([]interface{}); ok { 146 | result := make([]float64, len(d)) 147 | for i, el := range d { 148 | item, ok := el.(float64) 149 | if !ok { 150 | return nil, false 151 | } 152 | result[i] = item 153 | } 154 | return result, true 155 | } 156 | return nil, false 157 | } 158 | 159 | // ToArrayStr converts an empty interface type to a slice of strings. 160 | // If any element in the array cannot be converted, then nil is returned 161 | // along with a second value of false. If the input data could be entirely 162 | // converted, then the converted data, along with a second value of true, 163 | // will be returned. 164 | func toArrayStr(data interface{}) ([]string, bool) { 165 | // Is there a better way to do this with reflect? 166 | if d, ok := data.([]interface{}); ok { 167 | result := make([]string, len(d)) 168 | for i, el := range d { 169 | item, ok := el.(string) 170 | if !ok { 171 | return nil, false 172 | } 173 | result[i] = item 174 | } 175 | return result, true 176 | } 177 | return nil, false 178 | } 179 | 180 | func isSliceType(v interface{}) bool { 181 | if v == nil { 182 | return false 183 | } 184 | return reflect.TypeOf(v).Kind() == reflect.Slice 185 | } 186 | -------------------------------------------------------------------------------- /util_test.go: -------------------------------------------------------------------------------- 1 | package jmespath 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/jmespath/go-jmespath/internal/testify/assert" 7 | ) 8 | 9 | func TestSlicePositiveStep(t *testing.T) { 10 | assert := assert.New(t) 11 | input := make([]interface{}, 5) 12 | input[0] = 0 13 | input[1] = 1 14 | input[2] = 2 15 | input[3] = 3 16 | input[4] = 4 17 | result, err := slice(input, []sliceParam{{0, true}, {3, true}, {1, true}}) 18 | assert.Nil(err) 19 | assert.Equal(input[:3], result) 20 | } 21 | 22 | func TestIsFalseJSONTypes(t *testing.T) { 23 | assert := assert.New(t) 24 | assert.True(isFalse(false)) 25 | assert.True(isFalse("")) 26 | var empty []interface{} 27 | assert.True(isFalse(empty)) 28 | m := make(map[string]interface{}) 29 | assert.True(isFalse(m)) 30 | assert.True(isFalse(nil)) 31 | 32 | } 33 | 34 | func TestIsFalseWithUserDefinedStructs(t *testing.T) { 35 | assert := assert.New(t) 36 | type nilStructType struct { 37 | SliceOfPointers []*string 38 | } 39 | nilStruct := nilStructType{SliceOfPointers: nil} 40 | assert.True(isFalse(nilStruct.SliceOfPointers)) 41 | 42 | // A user defined struct will never be false though, 43 | // even if it's fields are the zero type. 44 | assert.False(isFalse(nilStruct)) 45 | } 46 | 47 | func TestIsFalseWithNilInterface(t *testing.T) { 48 | assert := assert.New(t) 49 | var a *int 50 | var nilInterface interface{} = a 51 | assert.True(isFalse(nilInterface)) 52 | } 53 | 54 | func TestIsFalseWithMapOfUserStructs(t *testing.T) { 55 | assert := assert.New(t) 56 | type foo struct { 57 | Bar string 58 | Baz string 59 | } 60 | m := make(map[int]foo) 61 | assert.True(isFalse(m)) 62 | } 63 | 64 | func TestObjsEqual(t *testing.T) { 65 | assert := assert.New(t) 66 | assert.True(objsEqual("foo", "foo")) 67 | assert.True(objsEqual(20, 20)) 68 | assert.True(objsEqual([]int{1, 2, 3}, []int{1, 2, 3})) 69 | assert.True(objsEqual(nil, nil)) 70 | assert.True(!objsEqual(nil, "foo")) 71 | assert.True(objsEqual([]int{}, []int{})) 72 | assert.True(!objsEqual([]int{}, nil)) 73 | } 74 | --------------------------------------------------------------------------------