-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle non-merge aliasing #416
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,12 +98,16 @@ key2: value6 | |
}) | ||
|
||
t.Run("YamlAliases", func(t *testing.T) { | ||
b := []byte(`foo: &foo | ||
b := []byte(`foo: &foofoo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The anchor and the key do not need to have the same value. This makes sure we don't actually use the anchor value for anything. |
||
bar: 1 | ||
baz: "baz" | ||
baz: &baz "baz" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using a top-level anchor, I used one inside a map to make sure this case is also covered. |
||
spam: | ||
ham: "eggs" | ||
<<: *foo | ||
bar: 0 | ||
<<: *foofoo | ||
baz: "bazbaz" | ||
Comment on lines
+106
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sure that the
|
||
|
||
baz: *baz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds a test for regular dereferencing. |
||
`) | ||
|
||
dec := dencoding.NewYAMLDecoder(bytes.NewReader(b)) | ||
|
@@ -121,16 +125,15 @@ spam: | |
got = append(got, v) | ||
} | ||
|
||
fooMap := dencoding.NewMap(). | ||
Set("bar", int64(1)). | ||
Set("baz", "baz") | ||
spamMap := dencoding.NewMap(). | ||
Set("ham", "eggs"). | ||
Set("foo", fooMap) | ||
|
||
exp := dencoding.NewMap(). | ||
Set("foo", fooMap). | ||
Set("spam", spamMap) | ||
Set("foo", dencoding.NewMap(). | ||
Set("bar", int64(1)). | ||
Set("baz", "baz")). | ||
Set("spam", dencoding.NewMap(). | ||
Set("ham", "eggs"). | ||
Set("bar", int64(1)). | ||
Set("baz", "bazbaz")). | ||
Set("baz", "baz") | ||
Comment on lines
+129
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the new override tests, I found it easiest to not use the |
||
|
||
if len(got) != 1 { | ||
t.Errorf("expected result len of %d, got %d", 1, len(got)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to merge the content of the alias into the current content of the map, I found it easiest to turn this into a queue rather than trying to manipulate the index.