mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-01 10:52:24 +01:00
Add elm syntax regression test
This commit is contained in:
committed by
David Peter
parent
0c3344d0c4
commit
66c7aca2f6
32
tests/syntax-tests/source/Elm/LICENSE.md
Normal file
32
tests/syntax-tests/source/Elm/LICENSE.md
Normal file
@@ -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.
|
137
tests/syntax-tests/source/Elm/test.elm
Normal file
137
tests/syntax-tests/source/Elm/test.elm
Normal file
@@ -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);
|
||||
}
|
||||
|]
|
Reference in New Issue
Block a user