// Copyright 2024 Matthew Rich . All rights reserved. package folio import ( "github.com/stretchr/testify/assert" "testing" "decl/internal/mapper" "log/slog" ) // Registry maps documents // lookup document by uri // lookup document by declaration // generate declaration for document/config func TestNewRegistry(t *testing.T) { r := NewRegistry() assert.NotNil(t, r) r.ResourceTypes = TestResourceTypes var docs mapper.Getter[*Declaration, *Document] = r decl := NewDeclaration() _, notexists := docs.Get(decl) assert.False(t, notexists) doc := NewDocument(r) res, e := doc.NewResource("foo://") assert.Nil(t, e) slog.Info("TestNewRegistry", "doc", doc) assert.Equal(t, doc.ResourceDeclarations[0].Attributes, res) r.DeclarationMap[doc.ResourceDeclarations[0]] = doc _, exists := docs.Get(doc.ResourceDeclarations[0]) assert.True(t, exists) } func TestRegistryResourceTypes(t *testing.T) { r := NewRegistry() assert.NotNil(t, r) r.ResourceTypes = TestResourceTypes doc := r.NewDocument("") assert.NotNil(t, doc) res, e := doc.NewResource("foo://") assert.Nil(t, e) assert.NotNil(t, res) decl := doc.ResourceDeclarations[0] assert.Equal(t, decl.Attributes, res) assert.Equal(t, TypeName("foo"), decl.Type) mappedDoc, ok := r.DeclarationMap[decl] assert.True(t, ok) assert.Equal(t, doc, mappedDoc) }