diff --git a/datamodel/low/extraction_functions_test.go b/datamodel/low/extraction_functions_test.go index 53e8580..71b8e53 100644 --- a/datamodel/low/extraction_functions_test.go +++ b/datamodel/low/extraction_functions_test.go @@ -1004,6 +1004,39 @@ one: } } +func TestExtractMap_NoLookupWithExtensions_UsingMerge(t *testing.T) { + + yml := `components:` + + var idxNode yaml.Node + mErr := yaml.Unmarshal([]byte(yml), &idxNode) + assert.NoError(t, mErr) + idx := index.NewSpecIndex(&idxNode) + + yml = `x-yeah: &yeah + night: fun +x-hey: you +one: + x-choo: choo + <<: *yeah` + + var cNode yaml.Node + e := yaml.Unmarshal([]byte(yml), &cNode) + assert.NoError(t, e) + + things, err := ExtractMapNoLookupExtensions[*test_Good](cNode.Content[0], idx, true) + assert.NoError(t, err) + assert.Len(t, things, 3) + + for k, v := range things { + if k.Value == "x-hey" || k.Value == "x-yeah" || k.Value == "night" || k.Value == "<<" { + continue + } + assert.Equal(t, "one", k.Value) + assert.Len(t, v.ValueNode.Content, 6) + } +} + func TestExtractMap_NoLookupWithoutExtensions(t *testing.T) { yml := `components:` diff --git a/utils/utils_test.go b/utils/utils_test.go index 4165f97..5721052 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -802,6 +802,33 @@ thangs: *anchorA` } +func TestNodeAlias_Nil(t *testing.T) { + ref := NodeAlias(nil) + assert.Nil(t, ref) +} + +func TestNodeAlias_IsNodeAlias_Nil(t *testing.T) { + + _, isAlias := IsNodeAlias(nil) + assert.False(t, isAlias) + +} + +func TestNodeAlias_IsNodeAlias_False(t *testing.T) { + + yml := `things: + - Stuff + - Junk +thangs: none` + + var node yaml.Node + _ = yaml.Unmarshal([]byte(yml), &node) + + _, isAlias := IsNodeAlias(node.Content[0].Content[3]) + assert.False(t, isAlias) + +} + func TestCheckForMergeNodes(t *testing.T) { yml := `x-common-definitions: @@ -850,6 +877,15 @@ func TestIsNodeRefValue_False(t *testing.T) { assert.Empty(t, val) } +func TestIsNodeRefValue_Nil(t *testing.T) { + + ref, node, val := IsNodeRefValue(nil) + + assert.False(t, ref) + assert.Nil(t, node) + assert.Empty(t, val) +} + func TestCheckEnumForDuplicates_Success(t *testing.T) { yml := "- yes\n- no\n- crisps" var rootNode yaml.Node