diff --git a/formatter/format_test.go b/formatter/format_test.go index 3e20b3b..fcb664e 100644 --- a/formatter/format_test.go +++ b/formatter/format_test.go @@ -24,6 +24,9 @@ func (e *testErrorListener) SyntaxError(_ antlr.Recognizer, _ interface{}, line, func TestStatement(t *testing.T) { if testing.Verbose() { log.SetLevel(log.TraceLevel) + log.SetFormatter(&log.TextFormatter{ + DisableQuote: true, + }) } tests := []struct { @@ -378,6 +381,18 @@ b);`, WhatId IN :this.oldAccountProfileIds ]);`, }, + { + `Account a = new Account( +Name = 'Acme', +Type = 'Something', // a comment +BillingPostalCode = '90210' +);`, + `Account a = new Account( + Name = 'Acme', + Type = 'Something', // a comment + BillingPostalCode = '90210' +);`, + }, } dmp := diffmatchpatch.New() for i, tt := range tests { diff --git a/formatter/formatter.go b/formatter/formatter.go index 2400d7d..46f3729 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -186,6 +186,11 @@ func removeExtraCommentIndentation(input string) string { newlinePrefixedInlineComment := regexp.MustCompile("\n\t*\uFFF9\n") input = newlinePrefixedInlineComment.ReplaceAllString(input, "\uFFF9\n") + log.Trace(fmt.Sprintf("ADJUSTED(6): %q", input)) + + tabPrefixedInlineComment := regexp.MustCompile(`([\w,]+)` + "\t+\uFFF9") + input = tabPrefixedInlineComment.ReplaceAllString(input, "$1 \uFFF9") + log.Trace(fmt.Sprintf("ADJUSTED(7): %q", input)) // Remove inline comment delimeters inlineCommentPattern := regexp.MustCompile(`(?s)` + "\uFFF9" + `(.*?)` + "\uFFFB")