366991046a
地址已绑定编译结果,支持历史记录切换功能 Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Reviewed-on: PostGuard/Canon#51 Co-authored-by: Ichirinko <1621543655@qq.com> Co-committed-by: Ichirinko <1621543655@qq.com>
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using Canon.Core.Abstractions;
|
|
using Canon.Core.CodeGenerators;
|
|
using Canon.Core.GrammarParser;
|
|
using Canon.Core.LexicalParser;
|
|
using Canon.Core.SyntaxNodes;
|
|
using Canon.Tests.Utils;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Canon.Tests.CCodeGeneratorTests;
|
|
|
|
public class BasicTests
|
|
{
|
|
private readonly IGrammarParser _parser = GeneratedGrammarParser.Instance;
|
|
private readonly ILexer _lexer = new Lexer();
|
|
private readonly ITestOutputHelper _outputHelper;
|
|
|
|
public BasicTests(ITestOutputHelper outputHelper)
|
|
{
|
|
_outputHelper = outputHelper;
|
|
}
|
|
|
|
[Fact]
|
|
public void ProgramStructTest()
|
|
{
|
|
CCodeBuilder builder = new();
|
|
|
|
const string program = """
|
|
program DoNothing;
|
|
begin
|
|
end.
|
|
""";
|
|
|
|
IEnumerable<SemanticToken> tokens = _lexer.Tokenize(new StringSourceReader(program));
|
|
|
|
ProgramStruct root = _parser.Analyse(tokens);
|
|
root.GenerateCCode(builder);
|
|
|
|
string result = builder.Build();
|
|
_outputHelper.WriteLine(result);
|
|
Assert.Equal("#include <PascalCoreLib.h> int main(){statement; return 0;}", result);
|
|
}
|
|
}
|