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

C++ parser tests almost all pass #86

Open
wants to merge 17 commits into
base: srcml-update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions ABB.SrcML.Data.Test/BuiltInTypeFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ClassSetup() {
[Category("Todo")]
public void TestCppBuiltIns_WithDoubleWord() {
// #a.cpp #example: "unsigned int a;"; MODIFIER TYPE a; MODIFIER TYPE b;
string xmlFormat = @"{0} {1} a; {0} {1} b";
string xmlFormat = @"{0} {1} a; {0} {1} b;";

foreach(var builtInModifier in new string[] { "unsigned", "signed", "long" }) {
foreach(var builtIn in new string[] { "int", "double" }) {
Expand Down Expand Up @@ -98,7 +98,7 @@ from declaration in stmt.GetExpressions().OfType<VariableDeclaration>()
[Test]
public void TestJavaBuiltIns() {
// #a.java TYPE a; TYPE b;
string xmlFormat = @"TYPE a; TYPE b;";
string xmlFormat = @"{0} a; {0} b;";

foreach(var builtIn in new string[] { "byte", "short", "int", "long", "float", "double", "boolean", "char" }) {
LibSrcMLRunner run = new LibSrcMLRunner();
Expand Down
1,063 changes: 517 additions & 546 deletions ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs

Large diffs are not rendered by default.

461 changes: 179 additions & 282 deletions ABB.SrcML.Data.Test/CSharpCodeParserTests.cs

Large diffs are not rendered by default.

66 changes: 25 additions & 41 deletions ABB.SrcML.Data.Test/CodeParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
using NUnit.Framework;
using System.Collections.ObjectModel;

namespace ABB.SrcML.Data.Test
{
namespace ABB.SrcML.Data.Test {
[TestFixture]
[Category("Build")]
public class CodeParserTests
{
public class CodeParserTests {
private Dictionary<Language, AbstractCodeParser> codeParsers;
private Dictionary<Language, SrcMLFileUnitSetup> fileSetup;

[TestFixtureSetUp]
public void ClassSetup()
{
public void ClassSetup() {
codeParsers = new Dictionary<Language, AbstractCodeParser>() {
{Language.CPlusPlus, new CPlusPlusCodeParser()},
{Language.CSharp, new CSharpCodeParser()},
Expand All @@ -47,12 +44,11 @@ public void ClassSetup()
[TestCase(Language.CPlusPlus)]
[TestCase(Language.CSharp)]
[TestCase(Language.Java)]
public void TestTwoVariableDeclarations(Language lang)
{
public void TestTwoVariableDeclarations(Language lang) {
int a, b;
string xml = @"int a,b;";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var testUnit = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.cpp");

var globalScope = codeParsers[lang].ParseFileUnit(testUnit);
Expand All @@ -70,15 +66,14 @@ public void TestTwoVariableDeclarations(Language lang)

[TestCase(Language.CSharp)]
[TestCase(Language.Java)]
public void TestField(Language lang)
{
public void TestField(Language lang) {

string xml = @"class A {
int Foo;
Bar baz;
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand All @@ -99,15 +94,14 @@ public void TestField(Language lang)
}

[TestCase(Language.CPlusPlus)]
public void TestField_Cpp(Language lang)
{
public void TestField_Cpp(Language lang) {

string xml = @"class A {
int Foo;
Bar baz;
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand All @@ -129,10 +123,7 @@ public void TestField_Cpp(Language lang)

[TestCase(Language.CSharp)]
[TestCase(Language.Java)]
public void TestMethodCallCreation(Language lang)
{
// A.cs

public void TestMethodCallCreation(Language lang) {
string xml = @"class A {
public int Execute() {
B b = new B();
Expand All @@ -146,7 +137,7 @@ public int Execute() {
}
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var fileUnit = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");
var globalScope = codeParsers[lang].ParseFileUnit(fileUnit);

Expand Down Expand Up @@ -201,11 +192,10 @@ public int Execute() {
[TestCase(Language.CPlusPlus)]
[TestCase(Language.CSharp)]
[TestCase(Language.Java)]
public void TestSimpleExpression(Language lang)
{
public void TestSimpleExpression(Language lang) {
string xml = @"foo = 2+3;";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand Down Expand Up @@ -233,11 +223,10 @@ public void TestSimpleExpression(Language lang)
[TestCase(Language.CPlusPlus)]
[TestCase(Language.CSharp)]
[TestCase(Language.Java)]
public void TestSubExpression(Language lang)
{
public void TestSubExpression(Language lang) {
string xml = @"foo = (2+3)*5;";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand Down Expand Up @@ -276,8 +265,7 @@ public void TestSubExpression(Language lang)
[TestCase(Language.CPlusPlus)]
[TestCase(Language.Java)]
[TestCase(Language.CSharp)]
public void TestGetChildren_Statements(Language lang)
{
public void TestGetChildren_Statements(Language lang) {
string xml = @"if(foo == 0) {
return;
try {
Expand All @@ -289,7 +277,7 @@ public void TestGetChildren_Statements(Language lang)
return;
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand All @@ -300,11 +288,10 @@ public void TestGetChildren_Statements(Language lang)
[TestCase(Language.CPlusPlus)]
[TestCase(Language.Java)]
[TestCase(Language.CSharp)]
public void TestGetChildren_Expressions(Language lang)
{
public void TestGetChildren_Expressions(Language lang) {
string xml = @"Foo f = (bar + baz(qux(17))).Xyzzy();";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand All @@ -315,16 +302,15 @@ public void TestGetChildren_Expressions(Language lang)
[TestCase(Language.CPlusPlus)]
[TestCase(Language.Java)]
[TestCase(Language.CSharp)]
public void TestResolveLocalVariable(Language lang)
{
public void TestResolveLocalVariable(Language lang) {
string xml = @"int Foo() {
if(MethodCall()) {
int bar = 17;
bar = 42;
}
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand All @@ -341,15 +327,14 @@ public void TestResolveLocalVariable(Language lang)
[TestCase(Language.CPlusPlus)]
[TestCase(Language.Java)]
[TestCase(Language.CSharp)]
public void TestResolveLocalVariable_ParentExpression(Language lang)
{
public void TestResolveLocalVariable_ParentExpression(Language lang) {
string xml = @"int Foo() {
for(int i = 0; i < bar; i++) {
printf(i);
}
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand All @@ -366,16 +351,15 @@ public void TestResolveLocalVariable_ParentExpression(Language lang)
[TestCase(Language.CPlusPlus)]
[TestCase(Language.Java)]
[TestCase(Language.CSharp)]
public void TestResolveLocalVariable_Parameter(Language lang)
{
public void TestResolveLocalVariable_Parameter(Language lang) {
string xml = @"int Foo(int num, bool option) {
if(option) {
printf(num);
}
return 0;
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "A.cpp", lang, new Collection<UInt32>() { }, false);
string srcML = run.GenerateSrcMLFromString(xml, "A.cpp", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
XElement xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "A.cpp");

var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
Expand Down
13 changes: 11 additions & 2 deletions ABB.SrcML.Data.Test/DataFileNameMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -39,18 +40,26 @@ public void FixtureTeardown() {
TestCase(true),
TestCase(false)]
public void TestDataFileNameMap(bool compressionEnabled) {
//I'm not exactly sure what this test is testing for, but the way files are named by the library
//is not playing well with this test. Seems like it wants a specific file extension. Some decision
//will have to be made about how to handle this problem. Does the library need to generate names differently?
//Or maybe this test should be different?
var generator = new DataGenerator();
var mapping = new DataFileNameMapping(TEST_DIRECTORY, compressionEnabled);
var sourcePath = @"..\..\TestInputs\function_def.cpp";
var srcmlPath = @"..\..\TestInputs\function_def.xml";

var mappedPath = mapping.GetTargetPath(sourcePath);

var actualExtension = Path.GetExtension(mappedPath);
var expectedExtension = (compressionEnabled ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION);
StringAssert.AreEqualIgnoringCase(expectedExtension, actualExtension);

generator.Generate(srcmlPath, mappedPath);
//generator.Generate(srcmlPath, mappedPath);
LibSrcMLRunner runner = new LibSrcMLRunner();
runner.GenerateSrcMLFromFile(srcmlPath, mappedPath, Language.CPlusPlus, new Collection<uint> { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary<string, Language> { });


Assert.That(File.Exists(mappedPath), String.Format("Could not generate {0}", mappedPath));

var data = XmlSerialization.Load(mappedPath, compressionEnabled);
Expand Down
Loading