summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthias Devlamynck <matthias.devlamynck@mailoo.org>2020-10-04 12:49:26 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-04 15:19:54 +0200
commit66c7aca2f6e50e13c07b52dd9c169fb2d713510d (patch)
tree26ce7abc0f9c5a64e0ec27b08b2f6622b9dfbc7a /tests
parent0c3344d0c4db888ea039480d85121600a9c2222d (diff)
Add elm syntax regression test
Diffstat (limited to 'tests')
-rw-r--r--tests/syntax-tests/highlighted/Elm/test.elm137
-rw-r--r--tests/syntax-tests/source/Elm/LICENSE.md32
-rw-r--r--tests/syntax-tests/source/Elm/test.elm137
3 files changed, 306 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/Elm/test.elm b/tests/syntax-tests/highlighted/Elm/test.elm
new file mode 100644
index 00000000..86efe4df
--- /dev/null
+++ b/tests/syntax-tests/highlighted/Elm/test.elm
@@ -0,0 +1,137 @@
+-- elm install elm-explorations/linear-algebra
+-- elm install elm-explorations/webgl
+
+
+import Browser
+import Browser.Events as E
+import Html exposing (Html)
+import Html.Attributes exposing (width, height, style)
+import Math.Matrix4 as Mat4 exposing (Mat4)
+import Math.Vector3 as Vec3 exposing (Vec3, vec3)
+import WebGL
+
+
+
+-- MAIN
+
+
+main =
+ Browser.element
+ { init = init
+ , view = view
+ , update = update
+ , subscriptions = subscriptions
+ }
+
+
+
+-- MODEL
+
+
+type alias Model =
+ Float
+
+
+init : () -> (Model, Cmd Msg)
+init () =
+ ( 0, Cmd.none )
+
+
+
+-- UPDATE
+
+
+type Msg
+ = TimeDelta Float
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg currentTime =
+ case msg of
+ TimeDelta delta ->
+ ( delta + currentTime, Cmd.none )
+
+
+
+-- SUBSCRIPTIONS
+
+
+subscriptions : Model -> Sub Msg
+subscriptions _ =
+ E.onAnimationFrameDelta TimeDelta
+
+
+
+-- VIEW
+
+
+view : Model -> Html msg
+view t =
+ WebGL.toHtml
+ [ width 400, height 400, style "display" "block"
+ ]
+ [ WebGL.entity vertexShader fragmentShader mesh { perspective = perspective (t / 1000) }
+ ]
+
+
+perspective : Float -> Mat4
+perspective t =
+ Mat4.mul
+ (Mat4.makePerspective 45 1 0.01 100)
+ (Mat4.makeLookAt (vec3 (4 * cos t) 0 (4 * sin t)) (vec3 0 0 0) (vec3 0 1 0))
+
+
+
+-- MESH
+
+
+type alias Vertex =
+ { position : Vec3
+ , color : Vec3
+ }
+
+
+mesh : WebGL.Mesh Vertex
+mesh =
+ WebGL.triangles
+ [ ( Vertex (vec3 0 0 0) (vec3 1 0 0)
+ , Vertex (vec3 1 1 0) (vec3 0 1 0)
+ , Vertex (vec3 1 -1 0) (vec3 0 0 1)
+ )
+ ]
+
+
+
+-- SHADERS
+
+
+type alias Uniforms =
+ { perspective : Mat4
+ }
+
+
+vertexShader : WebGL.Shader Vertex Uniforms { vcolor : Vec3 }
+vertexShader =
+ [glsl|
+ attribute vec3 position;
+ attribute vec3 color;
+ uniform mat4 perspective;
+ varying vec3 vcolor;
+
+ void main () {
+ gl_Position = perspective * vec4(position, 1.0);
+ vcolor = color;
+ }
+ |]
+
+
+fragmentShader : WebGL.Shader {} Uniforms { vcolor : Vec3 }
+fragmentShader =
+ [glsl|
+ precision mediump float;
+ varying vec3 vcolor;
+
+ void main () {
+ gl_FragColor = vec4(vcolor, 1.0);
+ }
+ |]
diff --git a/tests/syntax-tests/source/Elm/LICENSE.md b/tests/syntax-tests/source/Elm/LICENSE.md
new file mode 100644
index 00000000..b6bd01a5
--- /dev/null
+++ b/tests/syntax-tests/source/Elm/LICENSE.md
@@ -0,0 +1,32 @@
+The `test.elm` file has been added from [https://elm-lang.org/examples/triangle] under the following license:
+
+Copyright (c) 2012-present Evan Czaplicki
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Evan Czaplicki nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests/syntax-tests/source/Elm/test.elm b/tests/syntax-tests/source/Elm/test.elm
new file mode 100644
index 00000000..17a99f1a
--- /dev/null
+++ b/tests/syntax-tests/source/Elm/test.elm
@@ -0,0 +1,137 @@
+-- elm install elm-explorations/linear-algebra
+-- elm install elm-explorations/webgl
+
+
+import Browser
+import Browser.Events as E
+import Html exposing (Html)
+import Html.Attributes exposing (width, height, style)
+import Math.Matrix4 as Mat4 exposing (Mat4)
+import Math.Vector3 as Vec3 exposing (Vec3, vec3)
+import WebGL
+
+
+
+-- MAIN
+
+
+main =
+ Browser.element
+ { init = init
+ , view = view
+ , update = update
+ , subscriptions = subscriptions
+ }
+
+
+
+-- MODEL
+
+
+type alias Model =
+ Float
+
+
+init : () -> (Model, Cmd Msg)
+init () =
+ ( 0, Cmd.none )
+
+
+
+-- UPDATE
+
+
+type Msg
+ = TimeDelta Float
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg currentTime =
+ case msg of
+ TimeDelta delta ->
+ ( delta + currentTime, Cmd.none )
+
+
+
+-- SUBSCRIPTIONS
+
+
+subscriptions : Model -> Sub Msg
+subscriptions _ =
+ E.onAnimationFrameDelta TimeDelta
+
+
+
+-- VIEW
+
+
+view : Model -> Html msg
+view t =
+ WebGL.toHtml
+ [ width 400, height 400, style "display" "block"
+ ]
+ [ WebGL.entity vertexShader fragmentShader mesh { perspective = perspective (t / 1000) }
+ ]
+
+
+perspective : Float -> Mat4
+perspective t =
+ Mat4.mul
+ (Mat4.makePerspective 45 1 0.01 100)
+ (Mat4.makeLookAt (vec3 (4 * cos t) 0 (4 * sin t)) (vec3 0 0 0) (vec3 0 1 0))
+
+
+
+-- MESH
+
+
+type alias Vertex =
+ { position : Vec3
+ , color : Vec3
+ }
+
+
+mesh : WebGL.Mesh Vertex
+mesh =
+ WebGL.triangles
+ [ ( Vertex (vec3 0 0 0) (vec3 1 0 0)
+ , Vertex (vec3 1 1 0) (vec3 0 1 0)
+ , Vertex (vec3 1 -1 0) (vec3 0 0 1)
+ )
+ ]
+
+
+
+-- SHADERS
+
+
+type alias Uniforms =
+ { perspective : Mat4
+ }
+
+
+vertexShader : WebGL.Shader Vertex Uniforms { vcolor : Vec3 }
+vertexShader =
+ [glsl|
+ attribute vec3 position;
+ attribute vec3 color;
+ uniform mat4 perspective;
+ varying vec3 vcolor;
+
+ void main () {
+ gl_Position = perspective * vec4(position, 1.0);
+ vcolor = color;
+ }
+ |]
+
+
+fragmentShader : WebGL.Shader {} Uniforms { vcolor : Vec3 }
+fragmentShader =
+ [glsl|
+ precision mediump float;
+ varying vec3 vcolor;
+
+ void main () {
+ gl_FragColor = vec4(vcolor, 1.0);
+ }
+ |]