-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TranslatedFunction.SpecialFunctionKind for identifying construc…
- Loading branch information
1 parent
756b969
commit c828ec1
Showing
3 changed files
with
155 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Biohazrd | ||
{ | ||
public enum SpecialFunctionKind | ||
{ | ||
None, | ||
Constructor, | ||
Destructor, | ||
OperatorOverload, | ||
ConversionOverload | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using Biohazrd.Tests.Common; | ||
using Xunit; | ||
|
||
namespace Biohazrd.Tests | ||
{ | ||
public sealed class TranslatedFunctionTests : BiohazrdTestBase | ||
{ | ||
[Fact] | ||
public void SpecialFunctionKind_NormalFunction() | ||
{ | ||
TranslatedLibrary library = CreateLibrary("void Function();"); | ||
TranslatedFunction function = library.FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.None, function.SpecialFunctionKind); | ||
} | ||
|
||
[Fact] | ||
public void SpecialFunctionKind_NormalMethod() | ||
{ | ||
TranslatedLibrary library = CreateLibrary | ||
(@" | ||
class MyClass | ||
{ | ||
public: | ||
void Method(); | ||
}; | ||
" | ||
); | ||
TranslatedFunction method = library.FindDeclaration<TranslatedRecord>().FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.None, method.SpecialFunctionKind); | ||
} | ||
|
||
[Fact] | ||
public void SpecialFunctionKind_Constructor() | ||
{ | ||
TranslatedLibrary library = CreateLibrary | ||
(@" | ||
class MyClass | ||
{ | ||
public: | ||
MyClass(); | ||
}; | ||
" | ||
); | ||
TranslatedFunction method = library.FindDeclaration<TranslatedRecord>().FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.Constructor, method.SpecialFunctionKind); | ||
} | ||
|
||
[Fact] | ||
public void SpecialFunctionKind_Destructor() | ||
{ | ||
TranslatedLibrary library = CreateLibrary | ||
(@" | ||
class MyClass | ||
{ | ||
public: | ||
~MyClass(); | ||
}; | ||
" | ||
); | ||
TranslatedFunction method = library.FindDeclaration<TranslatedRecord>().FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.Destructor, method.SpecialFunctionKind); | ||
} | ||
|
||
[Fact] | ||
public void SpecialFunctionKind_OperatorOverloadFunction() | ||
{ | ||
TranslatedLibrary library = CreateLibrary | ||
(@" | ||
struct MyStruct { }; | ||
bool operator==(MyStruct, MyStruct); | ||
" | ||
); | ||
TranslatedFunction function = library.FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.OperatorOverload, function.SpecialFunctionKind); | ||
} | ||
|
||
[Fact] | ||
public void SpecialFunctionKind_OperatorOverloadMethod() | ||
{ | ||
TranslatedLibrary library = CreateLibrary | ||
(@" | ||
class MyClass | ||
{ | ||
public: | ||
int operator[](int i); | ||
}; | ||
" | ||
); | ||
TranslatedFunction method = library.FindDeclaration<TranslatedRecord>().FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.OperatorOverload, method.SpecialFunctionKind); | ||
} | ||
|
||
[Fact] | ||
public void SpecialFunctionKind_ConversionOverload() | ||
{ | ||
TranslatedLibrary library = CreateLibrary | ||
(@" | ||
class MyClass | ||
{ | ||
public: | ||
operator int(); | ||
}; | ||
" | ||
); | ||
TranslatedFunction method = library.FindDeclaration<TranslatedRecord>().FindDeclaration<TranslatedFunction>(); | ||
Assert.Equal(SpecialFunctionKind.ConversionOverload, method.SpecialFunctionKind); | ||
} | ||
} | ||
} |