Skip to content

Commit 1460848

Browse files
committed
Switch to # for comments
1 parent 44a1af5 commit 1460848

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

v2/codetags/parser_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ func TestParse(t *testing.T) {
6464
},
6565
{
6666
name: "name with comment",
67-
input: "name // comment",
67+
input: "name # comment",
6868
expect: mkt("name"),
6969
},
7070
{
7171
name: "name with comment after extra spaces",
72-
input: "name \t // comment",
72+
input: "name \t # comment",
7373
expect: mkt("name"),
7474
},
7575
{
@@ -118,7 +118,7 @@ func TestParse(t *testing.T) {
118118
},
119119
{
120120
name: "argument with comment",
121-
input: "name(arg) // comment",
121+
input: "name(arg) # comment",
122122
expect: mkta("name", mksa("arg")),
123123
},
124124
{
@@ -392,32 +392,32 @@ func TestParse(t *testing.T) {
392392
// Scalar values with comments
393393
{
394394
name: "integer value with comment",
395-
input: `key=1 // comment`,
395+
input: `key=1 # comment`,
396396
expect: mktv("key", "1", ValueTypeInt),
397397
},
398398
{
399399
name: "true value with comment",
400-
input: `key=true // comment`,
400+
input: `key=true # comment`,
401401
expect: mktv("key", "true", ValueTypeBool),
402402
},
403403
{
404404
name: "false value with comment",
405-
input: `key=false // comment`,
405+
input: `key=false # comment`,
406406
expect: mktv("key", "false", ValueTypeBool),
407407
},
408408
{
409409
name: "identifier value with comment",
410-
input: `key=ident // comment`,
410+
input: `key=ident # comment`,
411411
expect: mktv("key", "ident", ValueTypeString),
412412
},
413413
{
414414
name: "quoted string value with comment",
415-
input: `key="quoted" // comment`,
415+
input: `key="quoted" # comment`,
416416
expect: mktv("key", "quoted", ValueTypeString),
417417
},
418418
{
419419
name: "backtick string value with comment",
420-
input: "key=`quoted` // comment",
420+
input: "key=`quoted` # comment",
421421
expect: mktv("key", "quoted", ValueTypeString),
422422
},
423423

@@ -458,30 +458,30 @@ func TestParse(t *testing.T) {
458458
// Tag values with comments
459459
{
460460
name: "simple tag value with comment",
461-
input: `key=+key2 // comment`,
461+
input: `key=+key2 # comment`,
462462
expect: mktt("key", &Tag{Name: "key2"}),
463463
},
464464
{
465465
name: "tag value with empty parentheses and comment",
466-
input: `key=+key2() // comment`,
466+
input: `key=+key2() # comment`,
467467
expect: mktt("key", &Tag{Name: "key2"}),
468468
},
469469
{
470470
name: "tag value with argument and comment",
471-
input: `key=+key2(arg) // comment`,
471+
input: `key=+key2(arg) # comment`,
472472
expect: mktt("key", &Tag{Name: "key2", Args: []Arg{{Value: "arg", Type: ArgTypeString}}}),
473473
},
474474
{
475475
name: "tag value with named arguments and comment",
476-
input: `key=+key2(k1: v1, k2: v2) // comment`,
476+
input: `key=+key2(k1: v1, k2: v2) # comment`,
477477
expect: mktt("key", &Tag{Name: "key2", Args: []Arg{
478478
{Name: "k1", Value: "v1", Type: ArgTypeString},
479479
{Name: "k2", Value: "v2", Type: ArgTypeString},
480480
}}),
481481
},
482482
{
483483
name: "3 level nested tag values with comment",
484-
input: `key=+key2=+key3 // comment`,
484+
input: `key=+key2=+key3 # comment`,
485485
expect: mktt("key", &Tag{
486486
Name: "key2",
487487
ValueType: ValueTypeTag,
@@ -534,9 +534,9 @@ func TestParse(t *testing.T) {
534534
},
535535
{
536536
name: "raw value with comment",
537-
input: `key=true // comment`,
537+
input: `key=true # comment`,
538538
parseOptions: []ParseOption{RawValues(true)},
539-
expect: mktv("key", "true // comment", ValueTypeRaw),
539+
expect: mktv("key", "true # comment", ValueTypeRaw),
540540
},
541541
{
542542
name: "raw value with tag syntax",

v2/codetags/scanner.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ func (s *scanner) skipWhitespace() rune {
5656
return s.peek()
5757
}
5858

59+
func (s *scanner) remainder() string {
60+
result := string(s.buf[s.pos:])
61+
s.pos = len(s.buf)
62+
return result
63+
}
64+
65+
const (
66+
EOF = -1
67+
)
68+
5969
func (s *scanner) nextIsTrailingComment() bool {
6070
if s.pos >= len(s.buf)-1 {
6171
return false
@@ -64,7 +74,7 @@ func (s *scanner) nextIsTrailingComment() bool {
6474
switch {
6575
case unicode.IsSpace(s.buf[i]):
6676
continue
67-
case s.buf[i] == '/' && s.buf[i+1] == '/':
77+
case s.buf[i] == '#':
6878
return true
6979
default:
7080
return false
@@ -73,16 +83,6 @@ func (s *scanner) nextIsTrailingComment() bool {
7383
return false
7484
}
7585

76-
func (s *scanner) remainder() string {
77-
result := string(s.buf[s.pos:])
78-
s.pos = len(s.buf)
79-
return result
80-
}
81-
82-
const (
83-
EOF = -1
84-
)
85-
8686
func (s *scanner) nextNumber() (string, error) {
8787
const (
8888
stBegin = "stBegin"

v2/comments_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestExtractSingleBoolCommentTag(t *testing.T) {
5050
commentLines := []string{
5151
"Human comment that is ignored.",
5252
"+TRUE=true",
53-
"+FALSE=false // comment",
53+
"+FALSE=false # comment",
5454
"+MULTI=true",
5555
"+MULTI=false",
5656
"+MULTI=multi",
@@ -267,9 +267,9 @@ func TestExtractFunctionStyleCommentTags(t *testing.T) {
267267
}, {
268268
name: "ParseValues - comments ignored",
269269
comments: []string{
270-
"+boolTag=true // this is a boolean",
271-
"+intTag=42 // this is an integer",
272-
"+stringTag=\"quoted string\" // this is a string",
270+
"+boolTag=true # this is a boolean",
271+
"+intTag=42 # this is an integer",
272+
"+stringTag=\"quoted string\" # this is a string",
273273
},
274274
parseValues: true,
275275
expect: map[string][]Tag{

0 commit comments

Comments
 (0)