From cc06f8302c3614390a2ea4095a39a0b444e553f3 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 13 Jul 2022 12:09:45 -0400 Subject: graphics: Add SGLSL module. --- tests/sglsl.scm | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/sglsl.scm (limited to 'tests') diff --git a/tests/sglsl.scm b/tests/sglsl.scm new file mode 100644 index 0000000..fa41b1c --- /dev/null +++ b/tests/sglsl.scm @@ -0,0 +1,99 @@ +;;; Chickadee Game Toolkit +;;; Copyright © 2022 David Thompson +;;; +;;; Chickadee is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published +;;; by the Free Software Foundation, either version 3 of the License, +;;; or (at your option) any later version. +;;; +;;; Chickadee is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see +;;; . + +(define-module (tests sglsl) + #:use-module (tests utils) + #:use-module (srfi srfi-64) + #:use-module (chickadee graphics sglsl)) + +(define* (test-glsl name exp expected) + (test-equal name + (with-output-to-string (lambda () (sglsl->glsl exp))) + expected)) + +(with-tests "sglsl" + (test-glsl "true" #true "true") + (test-glsl "false" #false "false") + (test-glsl "integers" 4 "4") + (test-glsl "floats" 4.5 "4.5") + (test-glsl "rationals->floats" 1/2 "0.5") + (test-glsl "+" '(+ 1 2) "(1+2)") + (test-glsl "-" '(- 2 1) "(2-1)") + (test-glsl "*" '(* 2 2) "(2*2)") + (test-glsl "/" '(/ 4 2) "(4/2)") + (test-glsl "=" '(= foo 1) "(foo=1)") + (test-glsl "+=" '(+= foo 2) "(foo+=2)") + (test-glsl "-=" '(-= foo 2) "(foo-=2)") + (test-glsl "*=" '(*= foo 2) "(foo*=2)") + (test-glsl "/=" '(/= foo 2) "(foo/=2)") + (test-glsl "==" '(== foo 1) "(foo==1)") + (test-glsl "!=" '(!= foo 1) "(foo!=1)") + (test-glsl ">" '(> foo 1) "(foo>1)") + (test-glsl ">=" '(>= foo 1) "(foo>=1)") + (test-glsl "<" '(< foo 1) "(foo<1)") + (test-glsl "<=" '(<= foo 1) "(foo<=1)") + (test-glsl "||" '(|| foo bar) "(foo||bar)") + (test-glsl "&&" '(&& foo bar) "(foo&&bar)") + (test-glsl "++" '(++ foo) "foo++") + (test-glsl "--" '(-- foo) "foo--") + (test-glsl "pre++" '(pre++ foo) "++foo") + (test-glsl "pre--" '(pre-- foo) "--foo") + (test-glsl "negation" '(! (|| foo bar)) "!(foo||bar)") + (test-glsl "break" 'break "break") + (test-glsl "continue" 'continue "continue") + (test-glsl "discard" 'discard "discard") + (test-glsl "if" '(if (== foo bar) 1) + "if((foo==bar)){1}") + (test-glsl "if/else" '(if (== foo bar) 1 2) + "if((foo==bar)){1}else{2}") + (test-glsl "ternary" '(? (== foo bar) 1 2) + "((foo==bar)?1:2)") + (test-glsl "for loop" '(for ((= i 0) (< i 10) (++ i)) (= (@ foo i) 0)) + "for((i=0);(i<10);i++){(foo[i]=0);}") + (test-glsl "variable reference" 'foo "foo") + (test-glsl "struct dereference" '(-> foo bar baz) "foo.bar.baz") + (test-glsl "array dereference" '(@ foo 1 2) "foo[1][2]") + (test-glsl "struct+array dereference" '(@ (-> foo bar) 0) "foo.bar[0]") + (test-glsl "variable definition with initial value" + '(var float foo 1.2) + "float foo=1.2") + (test-glsl "variable definition with undefined value" + '(var float foo) + "float foo") + (test-glsl "variable definition with array dimensions" + '(var float (foo 4 4)) + "float foo[4][4]") + (test-glsl "function definition" + '(function (float square (float x)) (return (* x x))) + "float square(float x){return (x*x);}") + (test-glsl "struct definition" + '(struct Light ((vec3 position) (vec3 direction))) + "struct Light{vec3 position;vec3 direction;}") + (test-glsl "constant definition" '(const float pi 3.14159) + "const float pi=3.14159") + (test-glsl "uniform declaration" '(uniform vec3 position) + "uniform vec3 position") + (test-glsl "uniform declaration with array dimensions" + '(uniform vec3 (position 2 3)) + "uniform vec3 position[2][3]") + (test-glsl "input declaration" '(in vec3 position) + "in vec3 position") + (test-glsl "output declaration" '(out vec3 position) + "out vec3 position") + (test-glsl "function call" '(vec4 1 2 3 4) "vec4(1,2,3,4)") + (test-glsl "multiple expressions" '((++ foo) (-- bar)) + "foo++;bar--;")) -- cgit v1.2.3