Skip to content

Commit

Permalink
Merge 543aed0 into 9e84558
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 6, 2019
2 parents 9e84558 + 543aed0 commit fa5f5e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion processor/workers.go
Expand Up @@ -142,7 +142,12 @@ func codeState(

switch tokenType, offsetJump, endString := langFeatures.Tokens.Match(fileJob.Content[i:]); tokenType {
case TString:
currentState = SString
// It is safe to -1 here as to enter the code state we need to have
// transitioned from blank to here hence i should always be >= 1
// This check is to ensure we aren't in a character declaration
if fileJob.Content[i-1] != '\\' {
currentState = SString
}
return i, currentState, endString, endComments

case TSlcomment:
Expand Down
32 changes: 32 additions & 0 deletions processor/workers_test.go
Expand Up @@ -808,6 +808,38 @@ func TestGuessLanguageLanguageEmptyContent(t *testing.T) {
}
}

// Captures checking if a quote is prefixed by \ such as in
// a char which should otherwise trigger the string state which is incorrect
func TestCountStatsIssue73(t *testing.T) {
ProcessConstants()
fileJob := FileJob{
Language: "Java",
}

fileJob.Content = []byte(`'\"'{
code
`)

CountStats(&fileJob)

if fileJob.Lines != 3 {
t.Errorf("Expected 3 lines")
}

if fileJob.Code != 2 {
t.Errorf("Expected 2 lines got %d", fileJob.Code)
}

if fileJob.Comment != 0 {
t.Errorf("Expected 0 lines got %d", fileJob.Comment)
}

if fileJob.Blank != 1 {
t.Errorf("Expected 1 lines got %d", fileJob.Blank)
}
}

//////////////////////////////////////////////////
// Benchmarks Below
//////////////////////////////////////////////////
Expand Down

0 comments on commit fa5f5e6

Please sign in to comment.