Skip to content

Commit

Permalink
Improve accuracy to tokei standards
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Aug 26, 2018
1 parent b9c5d60 commit 1c3b483
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 49 deletions.
2 changes: 1 addition & 1 deletion processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func CountStats(fileJob *FileJob) {
}
}

index += offsetJump + 1
index += offsetJump
}
}

Expand Down
126 changes: 78 additions & 48 deletions processor/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,54 +580,54 @@ class A {
}
}

//func TestCountStatsAccuracy(t *testing.T) {
// ProcessConstants()
// fileJob := FileJob{
// Language: "Java",
// }
//
// fileJob.Content = []byte(`/* 23 lines 16 code 4 comments 3 blanks */
//
///*
//* Simple test class
//*/
//public class Test
//{
// int j = 0; // Not counted
// public static void main(String[] args)
// {
// Foo f = new Foo();
// f.bar();
//
// }
//}
//
//class Foo
//{
// public void bar()
// {
// System.out.println("FooBar"); //Not counted
// }
//}`)
//
// CountStats(&fileJob)
//
// if fileJob.Lines != 23 {
// t.Errorf("Expected 23 lines")
// }
//
// if fileJob.Code != 16 {
// t.Errorf("Expected 16 lines got %d", fileJob.Code)
// }
//
// if fileJob.Comment != 4 {
// t.Errorf("Expected 4 lines got %d", fileJob.Comment)
// }
//
// if fileJob.Blank != 3 {
// t.Errorf("Expected 3 lines got %d", fileJob.Blank)
// }
//}
func TestCountStatsAccuracy(t *testing.T) {
ProcessConstants()
fileJob := FileJob{
Language: "Java",
}

fileJob.Content = []byte(`/* 23 lines 16 code 4 comments 3 blanks */
/*
* Simple test class
*/
public class Test
{
int j = 0; // Not counted
public static void main(String[] args)
{
Foo f = new Foo();
f.bar();
}
}
class Foo
{
public void bar()
{
System.out.println("FooBar"); //Not counted
}
}`)

CountStats(&fileJob)

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

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

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

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

func TestCountStats(t *testing.T) {
ProcessConstants()
Expand All @@ -649,6 +649,36 @@ func TestCountStats(t *testing.T) {
}
}

func TestCountStatsTwo(t *testing.T) {
ProcessConstants()
fileJob := FileJob{
Language: "C++",
}

fileJob.Content = []byte(`/* 15 lines 7 code 4 comments 4 blanks */
#include <iostream>
using namespace std;
/*
* Simple test
*/
int main()
{
cout<<"Hello world"<<endl;
return 0;
}
`)

CountStats(&fileJob)

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

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

0 comments on commit 1c3b483

Please sign in to comment.