Check in packages.

This commit is contained in:
Richard Feldman
2017-10-26 03:03:03 +02:00
parent ef07ce6f52
commit b964fb9a6d
2046 changed files with 401572 additions and 101 deletions

View File

@@ -0,0 +1,35 @@
Elm.Native.TestHelpers = {};
Elm.Native.TestHelpers.make = function(localRuntime)
{
localRuntime.Native = localRuntime.Native || {};
localRuntime.Native.TestHelpers = localRuntime.Native.TestHelpers || {};
if (localRuntime.Native.TestHelpers.values)
{
return localRuntime.Native.TestHelpers.values;
}
var VirtualDom = Elm.Native.VirtualDom.make(localRuntime);
function unsafeRecordCallCount(f) {
function wrapper(a) {
wrapper.__elm_test_call_count += 1;
return f(a);
}
wrapper.__elm_test_call_count = 0;
return wrapper;
}
function unsafeQueryCallCount(f) {
if (f.__elm_test_call_count === undefined) {
return -1;
}
return f.__elm_test_call_count;
}
Elm.Native.TestHelpers.values = {
unsafeRecordCallCount: unsafeRecordCallCount,
unsafeQueryCallCount: unsafeQueryCallCount,
updateAndReplace: F3(VirtualDom.updateAndReplace)
};
return localRuntime.Native.TestHelpers.values = Elm.Native.TestHelpers.values;
};

View File

@@ -0,0 +1,72 @@
module TestCases.Lazy where
import VirtualDom exposing (Node, lazy)
import ElmTest.Assertion exposing (assertEqual)
import ElmTest.Test exposing (Test, suite, test)
import TestHelpers exposing (renderDom, updateDom, unsafeRecordCallCount, unsafeQueryCallCount)
renderRecord : { x: String, y: String } -> Node
renderRecord r =
VirtualDom.text <| "The values: " ++ r.x ++ ", " ++ r.y
renderPrimitive : Int -> Node
renderPrimitive x =
VirtualDom.text <| "The value: " ++ (toString x)
testLazyIdenticalRecord =
test "isn't called again with identical record" <|
let record = { x = "a", y = "b" }
wrappedRender = unsafeRecordCallCount renderRecord
v1 = renderDom <| lazy wrappedRender record
v2 = updateDom v1 <| lazy wrappedRender record
v3 = updateDom v2 <| lazy wrappedRender record
in
assertEqual 1 <| unsafeQueryCallCount wrappedRender
testLazyIdenticalPrimitive =
test "isn't called again with identical primitive" <|
let wrappedRender = unsafeRecordCallCount renderPrimitive
v1 = renderDom <| lazy wrappedRender 5
v2 = updateDom v1 <| lazy wrappedRender 5
v3 = updateDom v2 <| lazy wrappedRender 5
in
assertEqual 1 <| unsafeQueryCallCount wrappedRender
testLazyRecordMutationOfIdenticalValue =
test "isn't called again with record mutation of identical value" <|
let record = { x = "a", y = "b" }
wrappedRender = unsafeRecordCallCount renderRecord
v1 = renderDom <| lazy wrappedRender record
v2 = updateDom v1 <| lazy wrappedRender { record | x = "a" }
v3 = updateDom v2 <| lazy wrappedRender { record | x = "a", y = "b" }
in
assertEqual 1 <| unsafeQueryCallCount wrappedRender
testNotLazyDifferentRecord =
test "is called again with an equivalent but different record" <|
let wrappedRender = unsafeRecordCallCount renderRecord
v1 = renderDom <| lazy wrappedRender { x = "a", y = "b" }
v2 = updateDom v1 <| lazy wrappedRender { x = "a", y = "b" }
v3 = updateDom v2 <| lazy wrappedRender { x = "a", y = "b" }
in
assertEqual 3 <| unsafeQueryCallCount wrappedRender
tests : Test
tests =
suite
"Lazy"
[
testLazyIdenticalRecord,
testLazyIdenticalPrimitive,
-- Re-enable this test when core supports checking
-- record update values for identity before copying:
-- testLazyRecordMutationOfIdenticalValue,
testNotLazyDifferentRecord
]

View File

@@ -0,0 +1,34 @@
module TestHelpers where
import VirtualDom exposing (Node)
import Native.TestHelpers
import Native.VirtualDom
unsafeRecordCallCount : (a -> b) -> (a -> b)
unsafeRecordCallCount =
Native.TestHelpers.unsafeRecordCallCount
unsafeQueryCallCount : (a -> b) -> Int
unsafeQueryCallCount =
Native.TestHelpers.unsafeQueryCallCount
type OpaqueDom = OpaqueDom
render : Node -> OpaqueDom
render =
Native.VirtualDom.render
updateAndReplace : OpaqueDom -> Node -> Node -> OpaqueDom
updateAndReplace =
Native.TestHelpers.updateAndReplace
renderDom : Node -> (OpaqueDom, Node)
renderDom vdom =
(render vdom, vdom)
updateDom : (OpaqueDom, Node) -> Node -> (OpaqueDom, Node)
updateDom (oldDom, oldVDom) newVDom =
(updateAndReplace oldDom oldVDom newVDom, newVDom)

View File

@@ -0,0 +1,18 @@
import ElmTest.Runner.Console exposing (runDisplay)
import ElmTest.Test exposing (Test, suite)
import Console exposing (IO)
import Task exposing (Task)
import TestCases.Lazy
tests : Test
tests =
suite
"VirtualDom Library Tests"
[
TestCases.Lazy.tests
]
port runner : Signal (Task x ())
port runner = Console.run (runDisplay tests)

View File

@@ -0,0 +1,18 @@
{
"version": "1.0.0",
"summary": "Test for VirtualDom",
"license": "BSD3",
"repository": "https://github.com/evancz/virtual-dom.git",
"exposed-modules": [],
"source-directories": [
".",
"build/virtual-dom/"
],
"native-modules": true,
"dependencies": {
"elm-lang/core": "2.0.0 <= v < 4.0.0",
"laszlopandy/elm-console": "1.0.0 <= v < 2.0.0",
"deadfoxygrandpa/elm-test": "1.0.3 <= v < 2.0.0"
},
"elm-version": "0.16.0 <= v < 0.17.0"
}