Add another tokenizer test.

This commit is contained in:
redxef 2024-10-25 02:18:38 +02:00
parent faca13d393
commit 1be3b17bae
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -20,8 +20,8 @@ namespace Tests
public class Test {
[Fact]
public static void StringTokenStreamTest() {
StringTokenStream sts = StringTokenStream.generate("(\"some literal string\" def ghj +100 -+300 1)");
public static void TestTokenizer() {
StringTokenStream sts = StringTokenStream.generate("(\"some literal string\" def ghj +100 -+300 1 ++ !=)");
Assert.Equal(sts.get().value, "(");
Assert.Equal(sts.get().value, "\"");
Assert.Equal(sts.get().value, "some");
@ -43,13 +43,17 @@ namespace Tests
Assert.Equal(sts.get().value, "300");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "1");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "++");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "!=");
Assert.Equal(sts.get().value, ")");
sts.commit();
Assert.Equal(sts.available(), 0);
}
[Fact]
public static void ParserTest() {
public static void TestParser() {
string program = "(+ 1 (* 2 3))";
StringTokenStream sts = StringTokenStream.generate(program);
Parser p = new Parser(sts);
@ -62,9 +66,10 @@ namespace Tests
}
[Fact]
public static void EvaluateTest() {
Expression e = new Executor().eval("(+ 5 (+ 1 2 3))");
Assert.Equal(((Integer) e).value, 11);
public static void TestFunctions() {
IList<Tuple<string, Expression>> cases = new List<Tuple<string, Expression>>();
Expression e = new Executor().eval("(+ 10 20)");
Assert.Equal(((Integer) e).value, 30);
e = new Executor().eval("(> 1 2)");
Assert.Equal(((Lisp_Boolean) e).value, false);