Skip to content

Commit

Permalink
fix: check length comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sirkon committed May 22, 2019
1 parent 69e773c commit 959d5d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/generator/gogen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,29 @@ func (g *Generator) indent() *srcobj.Body {
func (g *Generator) RestLengthCheck(operator string, length int) error {
var operatorAction func(srcobj.Source, srcobj.Source) srcobj.Source
var errorFormat string
var charsLit string
if length > 1 {
charsLit = "characters"
} else {
charsLit = "character"
}
var comment string
switch operator {
case "<":
operatorAction = srcobj.OperatorGE
errorFormat = "rest is longer than required (%d symbols)"
comment = fmt.Sprintf("checks if the rest is less than %d %s long", length, charsLit)
case "==":
operatorAction = srcobj.OperatorNEq
errorFormat = "rest is not %d symbols long"
comment = fmt.Sprintf("checks if the rest is exactly %d %s long", length, charsLit)
case ">":
operatorAction = srcobj.OperatorLE
errorFormat = "rest is shorter than required (%d symbols)"
comment = fmt.Sprintf("checks if the rest is more than %d %s long", length, charsLit)
}
g.body.Append(srcobj.Literal("\n"))
g.body.Append(srcobj.Comment(comment))
g.body.Append(
srcobj.If{
Expr: operatorAction(
Expand Down
7 changes: 7 additions & 0 deletions testing/parsing_lde.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
This file was autogenerated via
-----------------------------------------------------------------
Expand Down Expand Up @@ -3040,12 +3041,18 @@ type RestLength struct {
// Extract ...
func (p *RestLength) Extract(line []byte) (bool, error) {
p.Rest = line

// checks if the rest is exactly 15 characters long
if len(p.Rest) != 15 {
return false, nil
}

// checks if the rest is less than 16 characters long
if len(p.Rest) >= 16 {
return false, nil
}

// checks if the rest is more than 14 characters long
if len(p.Rest) <= 14 {
return false, nil
}
Expand Down

0 comments on commit 959d5d7

Please sign in to comment.