Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
[#22] Contribute SlashStarStar
Browse files Browse the repository at this point in the history
  • Loading branch information
AElMehdi authored and Florent Biville committed Aug 1, 2019
1 parent 5f3479e commit d5e361c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
16 changes: 16 additions & 0 deletions core/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ func (Rem) GetClosingString() string {
return ""
}

type SlashStarStar struct{}

func (SlashStarStar) GetName() string {
return "SlashStarStar"
}
func (SlashStarStar) GetOpeningString() string {
return "/**"
}
func (SlashStarStar) GetString() string {
return " * "
}
func (SlashStarStar) GetClosingString() string {
return " */"
}

func ParseCommentStyle(str string) CommentStyle {
styles := supportedStyles()
keys := extractKeys(styles)
Expand Down Expand Up @@ -211,6 +226,7 @@ func supportedStyles() map[string]CommentStyle {
"DashDash": DashDash{},
"SemiColon": SemiColon{},
"REM": Rem{},
"SlashStarStar": SlashStarStar{},
}
}

Expand Down
1 change: 1 addition & 0 deletions core/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ var _ = Describe("Comment", func() {
Entry("matches DashDash comment style", "DashDash", "", "", "-- "),
Entry("matches SemiColon comment style", "SemiColon", "", "", "; "),
Entry("matches REM comment style", "REM", "", "", "REM "),
Entry("matches SlashStarStar comment style", "SlashStarStar", "/**", " */", " * "),
)
})
21 changes: 21 additions & 0 deletions core/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ var _ = Describe("Configuration parser", func() {
Expect(onlyPaths(changeSet.Files)).To(Equal([]FileChange{{Path: "hello-world.go"}}))
})

It("pre-computes the final configuration with SlashStarStar comment style", func() {
configuration := &core.Configuration{
HeaderFile: "some-header",
CommentStyle: "SlashStarStar",
Includes: includes,
Excludes: excludes,
TemplateData: data,
}
tracker.On("RetrieveVersionedTemplate", configuration).
Return(unchangedHeaderContents("Copyright {{.Year}} {{.Owner}}\n\nSome fictional license", data, revision), nil)
versioningClient.On("GetChanges", revision).Return(initialChanges, nil)
pathMatcher.On("MatchFiles", initialChanges, includes, excludes, fileSystem).Return(resultingChanges)
versioningClient.On("AddMetadata", resultingChanges, clock).Return(resultingChanges, nil)

changeSet, err := core.ParseConfiguration(configuration, systemConfiguration, tracker, pathMatcher)

Expect(err).To(BeNil())
Expect(changeSet.HeaderContents).To(Equal("/**\n * Copyright {{.YearRange}} ACME Labs\n *\n * Some fictional license\n */"))
Expect(onlyPaths(changeSet.Files)).To(Equal([]FileChange{{Path: "hello-world.go"}}))
})

It("pre-computes the header contents with SlashStar comment style", func() {
configuration := &core.Configuration{
HeaderFile: "some-header",
Expand Down
9 changes: 9 additions & 0 deletions core/configuration_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ var _ = Describe("Configuration validator", func() {
Expect(validationError).To(BeNil())
})

It("accepts valid configuration with SlashStarStar comment style", func() {
fileReader.On("Open", "docs.json").
Return(inMemoryFile(`{"headerFile": "some-file.txt", "style": "SlashStarStar", "includes": ["**/*.go"]}`), nil)

validationError := validator.Validate("file://docs.json")

Expect(validationError).To(BeNil())
})

It("rejects configuration with missing header file", func() {
fileReader.On("Open", "docs.json").
Return(inMemoryFile(`{"style": "SlashStar", "includes": ["**/*.go"]}`), nil)
Expand Down
3 changes: 2 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"Hash",
"DashDash",
"SemiColon",
"REM"
"REM",
"SlashStarStar"
]
},
"includes": {
Expand Down

0 comments on commit d5e361c

Please sign in to comment.