Skip to content
Permalink
Browse files

[#22] Add REM comment style

  • Loading branch information...
Psycokwet authored and fbiville committed Jun 15, 2019
1 parent dafd863 commit 476353c6f68896e80433dea4cfaaf28b2c28398d
Showing with 51 additions and 1 deletion.
  1. +18 −0 core/comment.go
  2. +1 −0 core/comment_test.go
  3. +21 −0 core/configuration_test.go
  4. +9 −0 core/configuration_validator_test.go
  5. +2 −1 docs/schema.json
@@ -108,6 +108,23 @@ func (SemiColon) GetClosingString() string {
return ""
}


type Rem struct {
}

func (Rem) GetName() string {
return "REM"
}
func (Rem) GetOpeningString() string {
return ""
}
func (Rem) GetString() string {
return "REM "
}
func (Rem) GetClosingString() string {
return ""
}

func ParseCommentStyle(str string) CommentStyle {
styles := supportedStyles()
keys := extractKeys(styles)
@@ -193,6 +210,7 @@ func supportedStyles() map[string]CommentStyle {
"Hash": Hash{},
"DashDash": DashDash{},
"SemiColon": SemiColon{},
"REM": Rem{},
}
}

@@ -23,5 +23,6 @@ var _ = Describe("Comment", func() {
Entry("matches Hash comment style", "Hash", "", "", "# "),
Entry("matches DashDash comment style", "DashDash", "", "", "-- "),
Entry("matches SemiColon comment style", "SemiColon", "", "", "; "),
Entry("matches REM comment style", "REM", "", "", "REM "),
)
})
@@ -166,6 +166,27 @@ var _ = Describe("Configuration parser", func() {
Expect(onlyPaths(changeSet.Files)).To(Equal([]FileChange{{Path: "hello-world.go"}}))
})

It("pre-computes the final configuration with REM comment style", func() {
configuration := &core.Configuration{
HeaderFile: "some-header",
CommentStyle: "REM",
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("REM Copyright {{.YearRange}} ACME Labs\nREM\nREM Some fictional license"))
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",
@@ -93,6 +93,15 @@ var _ = Describe("Configuration validator", func() {
Expect(validationError).To(BeNil())
})

It("accepts valid configuration with REM comment style", func() {
fileReader.On("Open", "docs.json").
Return(inMemoryFile(`{"headerFile": "some-file.txt", "style": "REM", "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)
@@ -17,7 +17,8 @@
"SlashSlash",
"Hash",
"DashDash",
"SemiColon"
"SemiColon",
"REM"
]
},
"includes": {

0 comments on commit 476353c

Please sign in to comment.
You can’t perform that action at this time.