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

Commit

Permalink
[#22] Add REM comment style
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycokwet authored and fbiville committed Jun 15, 2019
1 parent dafd863 commit 18222b1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
18 changes: 18 additions & 0 deletions core/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -193,6 +210,7 @@ func supportedStyles() map[string]CommentStyle {
"Hash": Hash{},
"DashDash": DashDash{},
"SemiColon": SemiColon{},
"REM": Rem{},
}
}

Expand Down
1 change: 1 addition & 0 deletions core/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "),
)
})
2 changes: 1 addition & 1 deletion core/configuration_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (cl *ConfigurationLoader) validateConfiguration(configFile *string) error {
}

func loadSchema() *jsonsch.Schema {
schema, err := jsonsch.NewSchema(jsonsch.NewReferenceLoader("https://fbiville.github.io/headache/schema.json"))
schema, err := jsonsch.NewSchema(jsonsch.NewReferenceLoader("file:///Users/fbiville/workspace/headache/docs/schema.json"))
if err != nil {
log.Printf("headache configuration warning: cannot load schema, skipping configuration validation. See reason below:\n\t%v\n", err)
return nil
Expand Down
21 changes: 21 additions & 0 deletions core/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"SlashSlash",
"Hash",
"DashDash",
"SemiColon"
"SemiColon",
"REM"
]
},
"includes": {
Expand Down

0 comments on commit 18222b1

Please sign in to comment.