forked from praeclarum/CLanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestsBase.cs
43 lines (38 loc) · 1.44 KB
/
TestsBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Linq;
using CLanguage.Interpreter;
using CLanguage.Syntax;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static CLanguage.CLanguageService;
namespace CLanguage.Tests
{
public class TestsBase
{
protected CInterpreter Run (string code, params int[] expectedErrors)
{
return Run (code, null, expectedErrors);
}
protected CInterpreter Run (string code, MachineInfo mi, params int[] expectedErrors)
{
var fullCode = "void start() { __cinit(); main(); } " + code;
var printer = new TestPrinter (expectedErrors);
var i = CLanguageService.CreateInterpreter (fullCode, mi ?? new TestMachineInfo (), printer: printer);
printer.CheckForErrors ();
i.Reset ("start");
i.Step ();
return i;
}
protected Executable Compile (string code, params int[] expectedErrors)
{
return Compile (code, null, expectedErrors);
}
protected Executable Compile (string code, MachineInfo mi, params int[] expectedErrors)
{
var fullCode = "void start() { __cinit(); main(); } " + code;
var printer = new TestPrinter (expectedErrors);
var i = CLanguageService.CreateInterpreter (fullCode, mi ?? new TestMachineInfo (), printer: printer);
printer.CheckForErrors ();
return i.Executable;
}
}
}