[C#] Use @ for keyword escaping (#6834)

This commit is contained in:
Derek Bailey
2021-09-09 10:29:27 -07:00
committed by GitHub
parent 1d063d87cf
commit 8fb8c2ce1d
19 changed files with 111 additions and 164 deletions

View File

@@ -137,17 +137,17 @@
<Compile Include="..\optional_scalars\ScalarStuff.cs">
<Link>optional_scalars\ScalarStuff.cs</Link>
</Compile>
<Compile Include="..\keyword_test\ABC.cs">
<Link>keyword_test\ABC.cs</Link>
<Compile Include="..\KeywordTest\ABC.cs">
<Link>KeywordTest\ABC.cs</Link>
</Compile>
<Compile Include="..\keyword_test\public.cs">
<Link>keyword_test\public.cs</Link>
<Compile Include="..\KeywordTest\public.cs">
<Link>KeywordTest\public.cs</Link>
</Compile>
<Compile Include="..\keyword_test\KeywordsInTable.cs">
<Link>keyword_test\KeywordsInTable.cs</Link>
<Compile Include="..\KeywordTest\KeywordsInTable.cs">
<Link>KeywordTest\KeywordsInTable.cs</Link>
</Compile>
<Compile Include="..\keyword_test\KeywordsInUnion.cs">
<Link>keyword_test\KeywordsInUnion.cs</Link>
<Compile Include="..\KeywordTest\KeywordsInUnion.cs">
<Link>KeywordTest\KeywordsInUnion.cs</Link>
</Compile>
</ItemGroup>

View File

@@ -168,17 +168,17 @@
<Compile Include="..\optional_scalars\ScalarStuff.cs">
<Link>optional_scalars\ScalarStuff.cs</Link>
</Compile>
<Compile Include="..\keyword_test\ABC.cs">
<Link>keyword_test\ABC.cs</Link>
<Compile Include="..\KeywordTest\ABC.cs">
<Link>KeywordTest\ABC.cs</Link>
</Compile>
<Compile Include="..\keyword_test\public.cs">
<Link>keyword_test\public.cs</Link>
<Compile Include="..\KeywordTest\public.cs">
<Link>KeywordTest\public.cs</Link>
</Compile>
<Compile Include="..\keyword_test\KeywordsInTable.cs">
<Link>keyword_test\KeywordsInTable.cs</Link>
<Compile Include="..\KeywordTest\KeywordsInTable.cs">
<Link>KeywordTest\KeywordsInTable.cs</Link>
</Compile>
<Compile Include="..\keyword_test\KeywordsInUnion.cs">
<Link>keyword_test\KeywordsInUnion.cs</Link>
<Compile Include="..\KeywordTest\KeywordsInUnion.cs">
<Link>KeywordTest\KeywordsInUnion.cs</Link>
</Compile>
<Compile Include="Assert.cs" />
<Compile Include="ByteBufferTests.cs" />

View File

@@ -19,6 +19,7 @@ using System.Text;
using System.Threading;
using MyGame.Example;
using optional_scalars;
using KeywordTest;
namespace FlatBuffers.Test
{
@@ -1117,5 +1118,26 @@ namespace FlatBuffers.Test
Assert.AreEqual(OptionalByte.Two, scalarStuff.MaybeEnum);
Assert.AreEqual(OptionalByte.Two, scalarStuff.DefaultEnum);
}
[FlatBuffersTestMethod]
public void TestKeywordEscaping() {
Assert.AreEqual((int)KeywordTest.@public.NONE, 0);
Assert.AreEqual((int)KeywordTest.ABC.@void, 0);
Assert.AreEqual((int)KeywordTest.ABC.where, 1);
Assert.AreEqual((int)KeywordTest.ABC.@stackalloc, 2);
var fbb = new FlatBufferBuilder(1);
var offset = KeywordsInTable.CreateKeywordsInTable(
fbb, KeywordTest.ABC.@stackalloc, KeywordTest.@public.NONE);
fbb.Finish(offset.Value);
KeywordsInTable keywordsInTable =
KeywordsInTable.GetRootAsKeywordsInTable(fbb.DataBuffer);
Assert.AreEqual(keywordsInTable.Is, KeywordTest.ABC.@stackalloc);
Assert.AreEqual(keywordsInTable.Private, KeywordTest.@public.NONE);
}
}
}

View File

@@ -19,12 +19,12 @@ $DOTNET sln add $PROJ_FILE
$DOTNET restore -r linux-x64 $PROJ_FILE
# Testing C# on Linux using Mono.
msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:minimal $PROJ_FILE
msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:quiet $PROJ_FILE
mono $TEMP_BIN/FlatBuffers.Test.exe
rm -fr $TEMP_BIN
# Repeat with unsafe versions
msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:minimal $PROJ_FILE
msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:quiet $PROJ_FILE
mono $TEMP_BIN/FlatBuffers.Test.exe
rm -fr $TEMP_BIN
@@ -36,17 +36,17 @@ $DOTNET sln add $CORE_PROJ_FILE
$DOTNET restore -r linux-x64 $CORE_PROJ_FILE
# Testing C# on Linux using .Net Core.
msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:minimal $CORE_PROJ_FILE
msbuild -property:Configuration=Release,OutputPath=$TEMP_BIN -verbosity:quiet $CORE_PROJ_FILE
$TEMP_BIN/FlatBuffers.Core.Test.exe
rm -fr $TEMP_BIN
# Repeat with unsafe versions
msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:minimal $CORE_PROJ_FILE
msbuild -property:Configuration=Release,UnsafeByteBuffer=true,OutputPath=$TEMP_BIN -verbosity:quiet $CORE_PROJ_FILE
$TEMP_BIN/FlatBuffers.Core.Test.exe
rm -fr $TEMP_BIN
# Repeat with SpanT versions
msbuild -property:Configuration=Release,EnableSpanT=true,OutputPath=$TEMP_BIN -verbosity:minimal $CORE_PROJ_FILE
msbuild -property:Configuration=Release,EnableSpanT=true,OutputPath=$TEMP_BIN -verbosity:quiet $CORE_PROJ_FILE
$TEMP_BIN/FlatBuffers.Core.Test.exe
rm -fr $TEMP_BIN