From bc70c1fb163367e76eae40e989fa894fdffc574d Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 16 May 2021 14:18:18 +1000 Subject: [PATCH] Added blank alias example --- pkg/yqlib/doc/Anchor and Alias Operators.md | 16 ++++++++++++++++ pkg/yqlib/operator_anchors_aliases_test.go | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/yqlib/doc/Anchor and Alias Operators.md b/pkg/yqlib/doc/Anchor and Alias Operators.md index dfbdc924..ecfa272c 100644 --- a/pkg/yqlib/doc/Anchor and Alias Operators.md +++ b/pkg/yqlib/doc/Anchor and Alias Operators.md @@ -169,6 +169,22 @@ b: &meow purr a: *meow ``` +## Set alias to blank does nothing +Given a sample.yml file of: +```yaml +b: &meow purr +a: cat +``` +then +```bash +yq eval '.a alias = ""' sample.yml +``` +will output +```yaml +b: &meow purr +a: cat +``` + ## Set alias relatively using assign-update Given a sample.yml file of: ```yaml diff --git a/pkg/yqlib/operator_anchors_aliases_test.go b/pkg/yqlib/operator_anchors_aliases_test.go index bdb24ab2..a611c750 100644 --- a/pkg/yqlib/operator_anchors_aliases_test.go +++ b/pkg/yqlib/operator_anchors_aliases_test.go @@ -90,6 +90,14 @@ var anchorOperatorScenarios = []expressionScenario{ "D0, P[], (doc)::{b: &meow purr, a: *meow}\n", }, }, + { + description: "Set alias to blank does nothing", + document: `{b: &meow purr, a: cat}`, + expression: `.a alias = ""`, + expected: []string{ + "D0, P[], (doc)::{b: &meow purr, a: cat}\n", + }, + }, { skipDoc: true, document: `{b: &meow purr, a: cat}`,