From de0716e87502a24ae67539a3e61bf86ed81ab58a Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 15 Jan 2022 18:22:26 +1100 Subject: [PATCH] Tweaking select docs --- pkg/yqlib/doc/operators/select.md | 42 +++++++++++++++---------------- pkg/yqlib/operator_select_test.go | 22 ++++++++-------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg/yqlib/doc/operators/select.md b/pkg/yqlib/doc/operators/select.md index b3de5ab2..cc9c56b8 100644 --- a/pkg/yqlib/doc/operators/select.md +++ b/pkg/yqlib/doc/operators/select.md @@ -2,26 +2,6 @@ Select is used to filter arrays and maps by a boolean expression. -## Select elements from array with regular expression -See more regular expression examples under the `string` operator docs. - -Given a sample.yml file of: -```yaml -- this_0 -- not_this -- nor_0_this -- thisTo_4 -``` -then -```bash -yq eval '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml -``` -will output -```yaml -this_0 -thisTo_4 -``` - ## Select elements from array using wildcard prefix Given a sample.yml file of: ```yaml @@ -75,6 +55,26 @@ go going ``` +## Select elements from array with regular expression +See more regular expression examples under the `string` operator docs. + +Given a sample.yml file of: +```yaml +- this_0 +- not_this +- nor_0_this +- thisTo_4 +``` +then +```bash +yq eval '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml +``` +will output +```yaml +this_0 +thisTo_4 +``` + ## Select items from a map Given a sample.yml file of: ```yaml @@ -92,7 +92,7 @@ cat dog ``` -## Use select + with_entries to filter map keys +## Use select and with_entries to filter map keys Given a sample.yml file of: ```yaml name: bob diff --git a/pkg/yqlib/operator_select_test.go b/pkg/yqlib/operator_select_test.go index 5aeed8f4..24702abd 100644 --- a/pkg/yqlib/operator_select_test.go +++ b/pkg/yqlib/operator_select_test.go @@ -27,16 +27,6 @@ var selectOperatorScenarios = []expressionScenario{ expression: `select(false)`, expected: []string{}, }, - { - description: "Select elements from array with regular expression", - subdescription: "See more regular expression examples under the `string` operator docs.", - document: `[this_0, not_this, nor_0_this, thisTo_4]`, - expression: `.[] | select(test("[a-zA-Z]+_[0-9]$"))`, - expected: []string{ - "D0, P[0], (!!str)::this_0\n", - "D0, P[3], (!!str)::thisTo_4\n", - }, - }, { description: "Select elements from array using wildcard prefix", document: `[cat,goat,dog]`, @@ -65,6 +55,16 @@ var selectOperatorScenarios = []expressionScenario{ "D0, P[3], (!!str)::going\n", }, }, + { + description: "Select elements from array with regular expression", + subdescription: "See more regular expression examples under the `string` operator docs.", + document: `[this_0, not_this, nor_0_this, thisTo_4]`, + expression: `.[] | select(test("[a-zA-Z]+_[0-9]$"))`, + expected: []string{ + "D0, P[0], (!!str)::this_0\n", + "D0, P[3], (!!str)::thisTo_4\n", + }, + }, { skipDoc: true, document: "a: hello", @@ -107,7 +107,7 @@ var selectOperatorScenarios = []expressionScenario{ }, }, { - description: "Use select + with_entries to filter map keys", + description: "Use select and with_entries to filter map keys", document: `{name: bob, legs: 2, game: poker}`, expression: `with_entries(select(.key | test("ame$")))`, expected: []string{