Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cpp parsing test file #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions parsing/cppParser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package parsing

import (
"bytes"
"testing"
)

func TestParseCppSourceUnit(t *testing.T) {
testCases := []struct {
name string
fileContent string
expected []string
}{
{
name: "simple class without imports",
fileContent: `package de.sandstorm.test;

public class Main {

};`,
expected: []string{"de", "sandstorm", "test", "Main"},
},
{
name: "simple class without imports with default visibility",
fileContent: `package de.sandstorm.test;

class Main {

};`,
expected: []string{"de", "sandstorm", "test", "Main"},
},
{
name: "simple class with internal dependencies",
fileContent: `package de.sandstorm.test;

#include "path/dependency.h" // some comment

public class Main {

};`,
expected: [][]string{
[]string{"de", "sandstorm", "test", "Main"},
[]string{"path", "dependency.h"}
},
},
{
name: "simple class with external dependencies",
fileContent: `package de.sandstorm.test;

#include <dependency.h> // some comment

public class Main {

};`,
expected: [][]string{
[]string{"de", "sandstorm", "test", "Main"},
[]string{"dependency.h"}
},
},
{
name: "simple class with external dependencies",
fileContent: `package de.sandstorm.test;

#include <dependency> // links to a file which contains the actual dependencies

public class Main {

};`,
expected: [][]string{
[]string{"de", "sandstorm", "test", "Main"},
[]string{"dependency"}
},
}
// TODO: test private static final class
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
file := bytes.NewBufferString(testCase.fileContent)
AssertEquals(t,
testCase.expected,
ParseJavaSourceUnit(file),
)
})
}
}

func TestParseJavaImports(t *testing.T) {
testCases := []struct {
name string
fileContent string
expected [][]string
}{
{
name: "simple class with mixed imports",
fileContent: `
package de.sandstorm.test;

#include <QList>;
#include <path/QList2.h>;
#include "myQList.h";
#include "path/myQList.h";

public class Main {

}
`,
expected: [][]string{
[]string{"de", "sandstorm", "test", "Main"},
[]string{"QList"},
[]string{"path", "QList2.h"},
[]string{"myList.h"},
[]string{"path", "myList.h"}
},
},
// TODO: test with different parameters
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
file := bytes.NewBufferString(testCase.fileContent)
actual, _ := ParseJavaImports(
file)
AssertEquals(t,
testCase.expected,
actual)
})
}
}