diff --git a/core/comment.go b/core/comment.go index 3eadb8f..3d070f2 100644 --- a/core/comment.go +++ b/core/comment.go @@ -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{}, } } diff --git a/core/comment_test.go b/core/comment_test.go index 0bc52e2..759f2f0 100644 --- a/core/comment_test.go +++ b/core/comment_test.go @@ -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 "), ) }) diff --git a/core/configuration_loader.go b/core/configuration_loader.go index 50017af..4ebdb28 100644 --- a/core/configuration_loader.go +++ b/core/configuration_loader.go @@ -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 diff --git a/core/configuration_test.go b/core/configuration_test.go index 28ea204..d0932a8 100644 --- a/core/configuration_test.go +++ b/core/configuration_test.go @@ -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", diff --git a/core/configuration_validator_test.go b/core/configuration_validator_test.go index 2da850d..238d64d 100644 --- a/core/configuration_validator_test.go +++ b/core/configuration_validator_test.go @@ -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) diff --git a/docs/schema.json b/docs/schema.json index 03164a6..fe7b404 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -17,7 +17,8 @@ "SlashSlash", "Hash", "DashDash", - "SemiColon" + "SemiColon", + "REM" ] }, "includes": {