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