-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
1 deletion.
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
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
58 changes: 58 additions & 0 deletions
58
src/Tests/FlatSharpEndToEndTests/ToStringMethods/ToStringMethods.cs
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,58 @@ | ||
using FlatSharp.Internal; | ||
|
||
namespace FlatSharpEndToEndTests.ToStringMethods; | ||
|
||
[TestClass] | ||
public class ToStringTests | ||
{ | ||
[TestMethod] | ||
public void Table_ToString() | ||
{ | ||
Assert.AreEqual("MyTable { FieldA = hello, FieldB = 123 }", new MyTable { FieldA = "hello", FieldB = 123}.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void EmptyTable_ToString() | ||
{ | ||
Assert.AreEqual("MyEmptyTable { }", new MyEmptyTable().ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void Struct_ToString() | ||
{ | ||
Assert.AreEqual("MyStruct { FieldA = 456, FieldB = 123 }", new MyStruct { FieldA = 456, FieldB = 123}.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void ValueStruct_ToString() | ||
{ | ||
Assert.AreEqual("MyValueStruct { FieldX = 1, FieldY = 2 }", new MyValueStruct { FieldX = 1f, FieldY = 2f}.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void UnionStructs_ToString() | ||
{ | ||
Assert.AreEqual("StructUnion { A { V = 0 } }", new StructUnion(new A { V = 0 }).ToString()); | ||
Assert.AreEqual("StructUnion { B { V = 1 } }", new StructUnion(new B { V = 1 }).ToString()); | ||
Assert.AreEqual("StructUnion { C { V = 2 } }", new StructUnion(new C { V = 2 }).ToString()); | ||
Assert.AreEqual("StructUnion { D { V = 3 } }", new StructUnion(new D { V = 3 }).ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void UnionTables_ToString() | ||
{ | ||
Assert.AreEqual("TableUnion { MyTable { FieldA = hello, FieldB = 10 } }", new TableUnion(new MyTable { FieldA = "hello", FieldB = 10 }).ToString()); | ||
Assert.AreEqual("TableUnion { MyEmptyTable { } }", new TableUnion(new MyEmptyTable()).ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void UnionMixed_ToString() | ||
{ | ||
Assert.AreEqual("MixedUnion { A { V = 0 } }", new MixedUnion(new A { V = 0 }).ToString()); | ||
Assert.AreEqual("MixedUnion { A { V = 2 } }", new MixedUnion(new A { V = 2 }).ToString()); | ||
Assert.AreEqual("MixedUnion { B { V = 0 } }", new MixedUnion(new B { V = 0 }).ToString()); | ||
Assert.AreEqual("MixedUnion { MyTable { FieldA = hi, FieldB = 21 } }", new MixedUnion(new MyTable { FieldA = "hi", FieldB = 21 }).ToString()); | ||
Assert.AreEqual("MixedUnion { MyEmptyTable { } }", new MixedUnion(new MyEmptyTable()).ToString()); | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Tests/FlatSharpEndToEndTests/ToStringMethods/ToStringMethods.fbs
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,37 @@ | ||
// Declare FlatSharp attributes. | ||
|
||
attribute "fs_serializer"; | ||
attribute "fs_valueStruct"; | ||
|
||
namespace FlatSharpEndToEndTests.ToStringMethods; | ||
|
||
|
||
table MyTable (fs_serializer) { | ||
FieldA: string; | ||
FieldB: int; | ||
} | ||
|
||
table MyEmptyTable (fs_serializer) { | ||
} | ||
|
||
struct MyStruct { | ||
FieldA: int; | ||
FieldB: int; | ||
} | ||
|
||
|
||
struct MyValueStruct (fs_valueStruct) { | ||
FieldX: float; | ||
FieldY: float; | ||
} | ||
|
||
struct A { V : uint; } | ||
struct B { V : uint; } | ||
struct C { V : uint; } | ||
struct D { V : uint; } | ||
|
||
union StructUnion { A, B, C, D } | ||
|
||
union TableUnion { MyTable, MyEmptyTable } | ||
|
||
union MixedUnion { A, B, MyTable, MyEmptyTable } |