Skip to content

Commit 9b9a7dc

Browse files
committed
Add isCompatible and toString functions to Platform module.
1 parent 709c598 commit 9b9a7dc

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/Compiler/Platform.gren

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module Compiler.Platform exposing
22
( Platform(..)
3+
, isCompatible
4+
--
5+
, toString
36
, toJson
47
, jsonDecoder
58
)
@@ -15,6 +18,19 @@ type Platform
1518
| Common
1619

1720

21+
isCompatible : Platform -> Platform -> Bool
22+
isCompatible a b =
23+
a == b || b == Common
24+
25+
26+
toString : Platform -> String
27+
toString platform =
28+
when platform is
29+
Common -> "common"
30+
Browser -> "browser"
31+
Node -> "node"
32+
33+
1834
toJson : Platform -> Encode.Value
1935
toJson platform =
2036
when platform is

tests/src/Main.gren

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Test.SemanticVersionRange as SemanticVersionRange
99
import Test.Compiler.Dependencies as Dependencies
1010
import Test.Compiler.PackageName as PackageName
1111
import Test.Compiler.ModuleName as ModuleName
12+
import Test.Compiler.Platform as Platform
1213
import Test.String.EditDistance as EditDistance
1314
import Node exposing (Program)
1415

@@ -24,5 +25,6 @@ main =
2425
, SemanticVersionRange.tests
2526
, PackageName.tests
2627
, ModuleName.tests
28+
, Platform.tests
2729
, EditDistance.tests
2830
]

tests/src/Test/Compiler/Platform.gren

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Test.Compiler.Platform exposing (tests)
2+
3+
import Expect exposing (Expectation)
4+
import Test exposing (Test, describe, test)
5+
import Fuzz exposing (Fuzzer)
6+
import Compiler.Platform as P
7+
8+
9+
tests : Test
10+
tests =
11+
describe "Platform"
12+
[ describe "isCompatible"
13+
[ test "equals" <| \{} ->
14+
Expect.all
15+
[ \_ -> Expect.equal True (P.isCompatible P.Node P.Node)
16+
, \_ -> Expect.equal True (P.isCompatible P.Browser P.Browser)
17+
, \_ -> Expect.equal True (P.isCompatible P.Common P.Common)
18+
]
19+
{}
20+
, test "common is always compatible" <| \{} ->
21+
Expect.all
22+
[ \_ -> Expect.equal True (P.isCompatible P.Node P.Common)
23+
, \_ -> Expect.equal True (P.isCompatible P.Browser P.Common)
24+
]
25+
{}
26+
]
27+
]

0 commit comments

Comments
 (0)