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
83 changes: 83 additions & 0 deletions embedding/commentfilter/c_style_filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 commentfilter_test

import (
. "embed-code/embed-code-go/embedding/commentfilter"

. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("C and C++", func() {
It("should strip all comments without treating literals as comments", func() {
lines := []string{
"// header comment",
"#include <stdio.h>",
"",
"/* block comment */",
"const char slash = '/';",
"const char* url = \"http://example.org\";",
"int create() { return 1; } // inline comment",
}

expected := []string{
"#include <stdio.h>",
"",
"const char slash = '/';",
"const char* url = \"http://example.org\";",
"int create() { return 1; } ",
}

assertFiltered("sample.cpp", RetainNone, lines, expected)
})

It("should keep inline comments", func() {
lines := []string{
"// header comment",
"int create();",
"/* block comment */",
"int count(); // inline comment",
}

expected := []string{
"// header comment",
"int create();",
"int count(); // inline comment",
}

assertFiltered("sample.cpp", RetainInline, lines, expected)
})

It("should keep block comments", func() {
lines := []string{
"// header comment",
"int create();",
"/* block comment */",
"int count(); // inline comment",
}

expected := []string{
"int create();",
"/* block comment */",
"int count(); ",
}

assertFiltered("sample.hpp", RetainBlock, lines, expected)
})
})
19 changes: 4 additions & 15 deletions embedding/commentfilter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ var filtersByExtension = map[string]filterEntry{
".hxx": filterConfig(MarkerCommentFilter{Syntax: cStyleSyntax}, regularModes),

// JavaScript
".js": filterConfig(MarkerCommentFilter{Syntax: jsSyntax}, allModes),
".jsx": filterConfig(MarkerCommentFilter{Syntax: jsSyntax}, allModes),
".ts": filterConfig(MarkerCommentFilter{Syntax: jsSyntax}, allModes),
".tsx": filterConfig(MarkerCommentFilter{Syntax: jsSyntax}, allModes),
".js": filterConfig(JavaScriptCommentFilter{}, allModes),
".jsx": filterConfig(JavaScriptCommentFilter{}, allModes),
".ts": filterConfig(JavaScriptCommentFilter{}, allModes),
".tsx": filterConfig(JavaScriptCommentFilter{}, allModes),
Comment thread
Vladyslav-Kuksiuk marked this conversation as resolved.

// Go
".go": filterConfig(MarkerCommentFilter{Syntax: goSyntax}, regularModes),
Expand Down Expand Up @@ -103,17 +103,6 @@ var javaSyntax = CommentMarker{
QuoteChars: "\"'",
}

var jsSyntax = CommentMarker{
Inline: []string{"//"},
Block: []BlockMarker{
{Start: cStyleBlockCommentStart, End: cStyleBlockCommentEnd},
},
Documentation: DocumentationMarker{
Block: []BlockMarker{{Start: cStyleDocCommentStart, End: cStyleBlockCommentEnd}},
},
QuoteChars: jsQuoteChars,
}

var csharpSyntax = CommentMarker{
Inline: []string{"//"},
Block: []BlockMarker{
Expand Down
57 changes: 57 additions & 0 deletions embedding/commentfilter/csharp_filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 commentfilter_test

import (
. "embed-code/embed-code-go/embedding/commentfilter"

. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("C#", func() {
It("should keep XML documentation comments", func() {
lines := []string{
"/// <summary>Creates a value.</summary>",
"// implementation note",
"public string Create() => \"// literal\";",
}

expected := []string{
"/// <summary>Creates a value.</summary>",
"public string Create() => \"// literal\";",
}

assertFiltered("Api.cs", RetainDocumentation, lines, expected)
})

It("should keep inline comments", func() {
lines := []string{
"/// <summary>Creates a value.</summary>",
"// implementation note",
"public string Create() => \"// literal\";",
}

expected := []string{
"// implementation note",
"public string Create() => \"// literal\";",
}

assertFiltered("Api.cs", RetainInline, lines, expected)
})
})
Loading
Loading