Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# IDE metadata.
.idea/
*.iml

# OS metadata.
.DS_Store

# Go build and test outputs.
/dist/
/out/
**/build/
coverage.out
9 changes: 4 additions & 5 deletions embedding/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (p Processor) Embed() (*parsing.Context, error) {
}
if context.IsContainsEmbedding() && context.IsContentChanged() {
data := []byte(strings.Join(context.GetResult(), "\n"))
err = os.WriteFile(p.DocFilePath, data, os.FileMode(files.ReadWriteExecPermission))
err = os.WriteFile(p.DocFilePath, data, os.FileMode(files.DocumentationFilePermission))
if err != nil {
return &context, err
}
Expand All @@ -143,12 +143,11 @@ func (p Processor) FindChangedEmbeddings() ([]parsing.Instruction, error) {
return nil, nil
}
context, err := p.fillEmbeddingContext()
changedEmbeddings := context.FindChangedEmbeddings()
if err != nil {
return changedEmbeddings, err
return nil, err
}

return changedEmbeddings, nil
return context.FindChangedEmbeddings(), nil
}

// IsUpToDate reports whether the embedding of the target markdown is up-to-date with the code file.
Expand Down Expand Up @@ -446,7 +445,7 @@ func getFilesByPatterns(root string, patterns []string) ([]string, error) {
return result, nil
}

// Returns the elements of the first array excluding those present in the second array.
// removeElements returns values from first that are not present in second.
func removeElements(first, second []string) []string {
secondMap := make(map[string]struct{})
for _, value := range second {
Expand Down
6 changes: 4 additions & 2 deletions files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import (
)

const (
ReadWriteExecPermission uint32 = 0777
WritePermission uint32 = 0600
// DocumentationFilePermission is the mode used when writing documentation data files.
DocumentationFilePermission uint32 = 0644
// WritePermission is the mode used for private writable files in tests and fixtures.
WritePermission uint32 = 0600
)

// IsFileExist reports whether the given path (relative or absolute) to a file exists in the
Expand Down
130 changes: 130 additions & 0 deletions type/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright 2026, TeamDev. All rights reserved.
//
// Redistribution and use in source and/or binary forms, with or without
// modification, must retain the above copyright notice and the following
// disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package _type_test

import (
"testing"

_type "embed-code/embed-code-go/type"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v3"
)

// TestTypes runs the type package specs.
func TestTypes(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Types Suite")
}

var _ = Describe("NamedPathList", func() {

It("should unmarshal a single path string", func() {
var config struct {
Paths _type.NamedPathList `yaml:"paths"`
}

err := yaml.Unmarshal([]byte("paths: ' ../examples '\n"), &config)

Expect(err).ShouldNot(HaveOccurred())
Expect(config.Paths).Should(Equal(_type.NamedPathList{
{Path: "../examples"},
}))
})

It("should unmarshal a sequence of path strings", func() {
var config struct {
Paths _type.NamedPathList `yaml:"paths"`
}

err := yaml.Unmarshal([]byte("paths:\n - ' ../examples '\n - ../runtime\n"), &config)

Expect(err).ShouldNot(HaveOccurred())
Expect(config.Paths).Should(Equal(_type.NamedPathList{
{Path: "../examples"},
{Path: "../runtime"},
}))
})

It("should unmarshal a sequence of named paths", func() {
var config struct {
Paths _type.NamedPathList `yaml:"paths"`
}

err := yaml.Unmarshal([]byte(
"paths:\n"+
" - name: examples\n"+
" path: ../examples\n"+
" - name: runtime\n"+
" path: ../runtime\n",
), &config)

Expect(err).ShouldNot(HaveOccurred())
Expect(config.Paths).Should(Equal(_type.NamedPathList{
{Name: "examples", Path: "../examples"},
{Name: "runtime", Path: "../runtime"},
}))
})

It("should reject mapping values", func() {
var config struct {
Paths _type.NamedPathList `yaml:"paths"`
}

err := yaml.Unmarshal([]byte("paths:\n name: examples\n path: ../examples\n"), &config)

Expect(err).Should(MatchError(ContainSubstring("invalid format for named paths")))
})
})

var _ = Describe("StringList", func() {

It("should unmarshal a comma-separated string", func() {
var config struct {
Patterns _type.StringList `yaml:"patterns"`
}

err := yaml.Unmarshal([]byte("patterns: ' docs/*.md, , guides/*.html '\n"), &config)

Expect(err).ShouldNot(HaveOccurred())
Expect(config.Patterns).Should(Equal(_type.StringList{"docs/*.md", "guides/*.html"}))
})

It("should unmarshal a sequence of strings", func() {
var config struct {
Patterns _type.StringList `yaml:"patterns"`
}

err := yaml.Unmarshal([]byte("patterns:\n - ' docs/*.md '\n - guides/*.html\n"), &config)

Expect(err).ShouldNot(HaveOccurred())
Expect(config.Patterns).Should(Equal(_type.StringList{"docs/*.md", "guides/*.html"}))
})

It("should reject mapping values", func() {
var config struct {
Patterns _type.StringList `yaml:"patterns"`
}

err := yaml.Unmarshal([]byte("patterns:\n markdown: docs/*.md\n"), &config)

Expect(err).Should(MatchError(ContainSubstring("invalid format for string list")))
})
})
Loading