diff --git a/Parlot.sln b/Parlot.sln index fd5d0d4..18d3077 100644 --- a/Parlot.sln +++ b/Parlot.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "src\Samples\Samples.csproj", "{B9A796FE-4BEB-499A-B506-25F20C749527}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,6 +70,18 @@ Global {3DF3E827-7AEE-4130-9925-D6DB26C420CC}.Release|x64.Build.0 = Release|Any CPU {3DF3E827-7AEE-4130-9925-D6DB26C420CC}.Release|x86.ActiveCfg = Release|Any CPU {3DF3E827-7AEE-4130-9925-D6DB26C420CC}.Release|x86.Build.0 = Release|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Debug|x64.ActiveCfg = Debug|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Debug|x64.Build.0 = Debug|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Debug|x86.ActiveCfg = Debug|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Debug|x86.Build.0 = Debug|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Release|Any CPU.Build.0 = Release|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Release|x64.ActiveCfg = Release|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Release|x64.Build.0 = Release|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Release|x86.ActiveCfg = Release|Any CPU + {B9A796FE-4BEB-499A-B506-25F20C749527}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -76,6 +90,7 @@ Global {44F5D7FE-63A0-45BD-B743-9711C273B5A2} = {0D1E6480-3C81-4951-8F44-BF74398BA8D4} {9452A111-5A01-4D3C-AA9F-F3AE4F1255C2} = {5E61AAE8-0C62-47A5-B218-A3235253710E} {3DF3E827-7AEE-4130-9925-D6DB26C420CC} = {5E61AAE8-0C62-47A5-B218-A3235253710E} + {B9A796FE-4BEB-499A-B506-25F20C749527} = {0D1E6480-3C81-4951-8F44-BF74398BA8D4} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E81DADB4-B5AD-452A-A308-813B0618F303} diff --git a/README.md b/README.md index 0763734..5faf12e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The Fluent API provides simple parser combinators that are assembled to express The main goal of this API is to provide an easy-to-read grammar. Another advantage is that grammars are built at runtime, and they can be extended dynamically. The following example is a complete parser that creates a mathematical expression tree (AST). -The source is available [here](./test/Parlot.Tests/Calc/FluentParser.cs). +The source is available [here](./src/Samples/Calc/FluentParser.cs). ```c# public static readonly Parser Expression; diff --git a/test/Parlot.Tests/Calc/Expression.cs b/src/Samples/Calc/Expression.cs similarity index 100% rename from test/Parlot.Tests/Calc/Expression.cs rename to src/Samples/Calc/Expression.cs diff --git a/test/Parlot.Tests/Calc/FluentParser.cs b/src/Samples/Calc/FluentParser.cs similarity index 100% rename from test/Parlot.Tests/Calc/FluentParser.cs rename to src/Samples/Calc/FluentParser.cs diff --git a/test/Parlot.Tests/Calc/Interpreter.cs b/src/Samples/Calc/Interpreter.cs similarity index 100% rename from test/Parlot.Tests/Calc/Interpreter.cs rename to src/Samples/Calc/Interpreter.cs diff --git a/test/Parlot.Tests/Calc/Parser.cs b/src/Samples/Calc/Parser.cs similarity index 100% rename from test/Parlot.Tests/Calc/Parser.cs rename to src/Samples/Calc/Parser.cs diff --git a/test/Parlot.Tests/Json/JsonModel.cs b/src/Samples/Json/JsonModel.cs similarity index 100% rename from test/Parlot.Tests/Json/JsonModel.cs rename to src/Samples/Json/JsonModel.cs diff --git a/test/Parlot.Tests/Json/JsonParser.cs b/src/Samples/Json/JsonParser.cs similarity index 100% rename from test/Parlot.Tests/Json/JsonParser.cs rename to src/Samples/Json/JsonParser.cs diff --git a/src/Samples/Samples.csproj b/src/Samples/Samples.csproj new file mode 100644 index 0000000..93334d6 --- /dev/null +++ b/src/Samples/Samples.csproj @@ -0,0 +1,12 @@ + + + + net6.0;net8.0 + false + + + + + + + diff --git a/test/Parlot.Benchmarks/Parlot.Benchmarks.csproj b/test/Parlot.Benchmarks/Parlot.Benchmarks.csproj index eca0f07..15b6aca 100644 --- a/test/Parlot.Benchmarks/Parlot.Benchmarks.csproj +++ b/test/Parlot.Benchmarks/Parlot.Benchmarks.csproj @@ -13,9 +13,10 @@ - + - + + diff --git a/test/Parlot.Tests/BenchmarksTests.cs b/test/Parlot.Tests/BenchmarksTests.cs new file mode 100644 index 0000000..d6b518c --- /dev/null +++ b/test/Parlot.Tests/BenchmarksTests.cs @@ -0,0 +1,239 @@ +using Parlot.Benchmarks; +using Xunit; + +namespace Parlot.Tests +{ + public class BenchmarksTests + { + [Fact] + public void CreateCompiledSmallParser() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.CreateCompiledSmallParser(); + Assert.NotNull(result); + } + + [Fact] + public void CreateCompiledExpressionParser() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.CreateCompiledExpressionParser(); + Assert.NotNull(result); + } + + [Fact] + public void CursorMatchHello() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.CursorMatchHello(); + Assert.NotNull(result); + } + + [Fact] + public void CursorMatchGoodbye() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.CursorMatchGoodbye(); + Assert.NotNull(result); + } + + [Fact] + public void CursorMatchNone() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.CursorMatchNone(); + Assert.Null(result); + } + + [Fact] + public void Lookup() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.Lookup(); + Assert.Equal('d', result); + } + + [Fact] + public void SkipWhiteSpace_1() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.SkipWhiteSpace_1(); + Assert.Equal('a', result); + } + + [Fact] + public void SkipWhiteSpace_10() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.SkipWhiteSpace_10(); + Assert.Equal('a', result); + } + + [Fact] + public void DecodeStringWithoutEscapes() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.DecodeStringWithoutEscapes(); + Assert.Equal("This is a new line \n \t and a tab and some \xa0", result); + } + + [Fact] + public void DecodeStringWithEscapes() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.DecodeStringWithEscapes(); + Assert.Equal("This is a new line \n \t and a tab and some \xa0", result); + } + + [Fact] + public void ExpressionRawSmall() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.ExpressionRawSmall(); + Assert.NotNull(result); + } + + [Fact] + public void ExpressionCompiledSmall() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.ExpressionCompiledSmall(); + Assert.NotNull(result); + } + + [Fact] + public void ExpressionFluentSmall() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.ExpressionCompiledSmall(); + Assert.NotNull(result); + } + + [Fact] + public void ExpressionRawBig() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.ExpressionRawBig(); + Assert.NotNull(result); + } + + [Fact] + public void ExpressionCompiledBig() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.ExpressionCompiledBig(); + Assert.NotNull(result); + } + + [Fact] + public void ExpressionFluentBig() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.ExpressionCompiledBig(); + Assert.NotNull(result); + } + + [Fact] + public void BigJson() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.BigJson(); + Assert.NotNull(result); + } + + [Fact] + public void BigJsonCompiled() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.BigJsonCompiled(); + Assert.NotNull(result); + } + + [Fact] + public void DeepJson() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.DeepJson(); + Assert.NotNull(result); + } + + [Fact] + public void DeepJsonCompiled() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.DeepJsonCompiled(); + Assert.NotNull(result); + } + + [Fact] + public void LongJson() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.LongJson(); + Assert.NotNull(result); + } + + [Fact] + public void LongJsonCompiled() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.LongJsonCompiled(); + Assert.NotNull(result); + } + + [Fact] + public void WideJson() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.WideJson(); + } + + [Fact] + public void WideJsonCompiled() + { + var benchmarks = new ParlotBenchmarks(); + benchmarks.Setup(); + var result = benchmarks.WideJsonCompiled(); + Assert.NotNull(result); + } + + [Fact] + public void ParlotEmailCompiled() + { + var benchmarks = new RegexBenchmarks(); + var result = benchmarks.ParlotEmailCompiled(); + Assert.True(result); + } + + [Fact] + public void ParlotEmail() + { + var benchmarks = new RegexBenchmarks(); + var result = benchmarks.ParlotEmail(); + Assert.True(result); + } + } +} diff --git a/test/Parlot.Tests/Parlot.Tests.csproj b/test/Parlot.Tests/Parlot.Tests.csproj index 55bcf5f..8438771 100644 --- a/test/Parlot.Tests/Parlot.Tests.csproj +++ b/test/Parlot.Tests/Parlot.Tests.csproj @@ -1,13 +1,15 @@  - net6.0;net8.0 + net8.0 false latest + +