69 lines
2.8 KiB
C#
69 lines
2.8 KiB
C#
|
using Xunit;
|
||
|
using Lisp_Environment = Jellyfin.Plugin.SmartPlaylist.Lisp.Environment;
|
||
|
using Lisp_Boolean = Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler.Boolean;
|
||
|
using Jellyfin.Plugin.SmartPlaylist.Lisp;
|
||
|
using Jellyfin.Plugin.SmartPlaylist.Lisp.Compiler;
|
||
|
|
||
|
namespace Tests
|
||
|
{
|
||
|
public class Test {
|
||
|
[Fact]
|
||
|
public static void StringTokenStreamTest() {
|
||
|
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");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "literal");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "string");
|
||
|
Assert.Equal(sts.get().value, "\"");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "def");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "ghj");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "+");
|
||
|
Assert.Equal(sts.get().value, "100");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "-");
|
||
|
Assert.Equal(sts.get().value, "+");
|
||
|
Assert.Equal(sts.get().value, "300");
|
||
|
Assert.Equal(sts.get().value, " ");
|
||
|
Assert.Equal(sts.get().value, "1");
|
||
|
Assert.Equal(sts.get().value, ")");
|
||
|
sts.commit();
|
||
|
Assert.Equal(sts.available(), 0);
|
||
|
}
|
||
|
|
||
|
[Fact]
|
||
|
public static void ParserTest() {
|
||
|
string program = "( + 1 ( * 2 3))";
|
||
|
StringTokenStream sts = StringTokenStream.generate(program);
|
||
|
Parser p = new Parser(sts);
|
||
|
Assert.Equal(program, string.Format("{0}", p.parse()));
|
||
|
}
|
||
|
|
||
|
[Fact]
|
||
|
public static void EvaluateTest() {
|
||
|
Expression p = new Parser(StringTokenStream.generate("(+ 5 (+ 1 2 3))")).parse();
|
||
|
var e = Lisp_Environment.create();
|
||
|
Entry r = (Entry) e.eval(p);
|
||
|
Assert.Equal(((Integer) r.expression).value, 11);
|
||
|
|
||
|
r = (Entry) Lisp_Environment.create().eval("(> 1 2)");
|
||
|
Assert.Equal(((Lisp_Boolean) r.expression).value, false);
|
||
|
|
||
|
r = (Entry) Lisp_Environment.create().eval("(if (> 1 2) 3 4)");
|
||
|
Assert.Equal(((Integer) r.expression).value, 4);
|
||
|
|
||
|
r = (Entry) Lisp_Environment.create().eval("(begin (define x 1) 4)");
|
||
|
Assert.Equal(((Integer) r.expression).value, 4);
|
||
|
|
||
|
|
||
|
r = (Entry) Lisp_Environment.create().eval("(apply + (1 2))");
|
||
|
Assert.Equal(((Integer) r.expression).value, 3);
|
||
|
}
|
||
|
}
|
||
|
}
|