Skip to content

Commit 146469d

Browse files
committed
Split test dependencies out into spago-test.dhall
1 parent ff799d0 commit 146469d

File tree

6 files changed

+71
-56
lines changed

6 files changed

+71
-56
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ jobs:
3030
- name: Build source
3131
run: spago build --no-install --purs-args '--censor-lib --strict'
3232

33+
- name: Install test dependencies
34+
run: spago -x spago-test.dhall install
35+
36+
- name: Build tests
37+
run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --strict'
38+
3339
- name: Run tests
34-
run: spago test --no-install
40+
run: spago -x spago-test.dhall test --no-install

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@ These are some other packages which provide more `ArrayBuffer` features.
7575
### Base64
7676

7777
* [__base64-codec__](https://pursuit.purescript.org/packages/purescript-base64-codec)
78+
79+
## Development
80+
81+
Run the tests with
82+
83+
```sh
84+
spago -x spago-test.dhall test
85+
```

spago-test.dhall

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let conf = ./spago.dhall
2+
in conf // {
3+
, dependencies = conf.dependencies #
4+
[ "console"
5+
, "foldable-traversable"
6+
, "partial"
7+
, "refs"
8+
, "typelevel-prelude"
9+
, "tuples"
10+
, "quickcheck"
11+
, "quickcheck-laws"
12+
]
13+
, sources = conf.sources # [ "test/**/*.purs" ]
14+
}

spago.dhall

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@
22
, dependencies =
33
[ "arraybuffer-types"
44
, "arrays"
5-
, "console"
65
, "effect"
76
, "float32"
8-
, "foldable-traversable"
97
, "functions"
108
, "gen"
119
, "maybe"
1210
, "nullable"
13-
, "partial"
1411
, "prelude"
15-
, "quickcheck"
16-
, "quickcheck-laws"
17-
, "refs"
1812
, "tailrec"
19-
, "typelevel-prelude"
2013
, "uint"
2114
, "unfoldable"
22-
, "tuples"
2315
]
2416
, packages = ./packages.dhall
25-
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
17+
, sources = [ "src/**/*.purs" ]
2618
}

src/Data/ArrayBuffer/Typed/Unsafe.purs

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/Properties/Typed/Laws.purs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
module Test.Properties.Typed.Laws where
22

3-
import Data.ArrayBuffer.Typed (class TypedArray)
3+
import Prelude
4+
-- import Prelude (class Eq, class Monoid, class Ord, class Semigroup, class Show, bind, discard, pure, void, ($), (+), (<>), (<$>))
5+
-- import Prelude (class Eq, class Monoid, class Ord, class Semigroup, Unit, discard, void, ($), (+), (<$>), (<<<))
6+
import Data.ArrayBuffer.Typed (class TypedArray, toString)
47
import Data.ArrayBuffer.Typed.Gen (genFloat32, genFloat64, genInt16, genInt32, genInt8, genTypedArray, genUint16, genUint32, genUint8)
5-
import Data.ArrayBuffer.Typed.Unsafe (AV(..))
68
import Data.ArrayBuffer.Types (ArrayView, Float32, Float64, Int16, Int32, Int8, Uint16, Uint32, Uint8, Uint8Clamped, ArrayViewType)
79
import Data.Float32 as F
810
import Data.UInt (UInt)
911
import Effect (Effect)
1012
import Effect.Ref (Ref)
1113
import Effect.Ref as Ref
12-
import Prelude (class Eq, class Monoid, class Ord, class Semigroup, Unit, discard, void, ($), (+), (<$>), (<<<))
13-
import Test.QuickCheck (class Arbitrary)
14+
import Test.QuickCheck (class Arbitrary, arbitrary)
1415
import Test.QuickCheck.Gen (Gen)
1516
import Test.QuickCheck.Laws.Data (checkEq, checkMonoid, checkOrd, checkSemigroup)
1617
import Type.Prelude (Proxy(..))
18+
import Data.ArrayBuffer.Typed as TA
19+
import Data.Generic.Rep (class Generic)
20+
import Data.Maybe (Maybe(..))
21+
import Effect.Unsafe (unsafePerformEffect)
1722

1823
newtype A a = A a
1924

@@ -102,3 +107,35 @@ typedArrayLaws count = do
102107
f (Proxy :: Proxy (A (AV Uint32 UInt)))
103108
f (Proxy :: Proxy (A (AV Uint8 UInt)))
104109
f (Proxy :: Proxy (A (AV Uint8Clamped UInt)))
110+
111+
newtype AV :: forall k. ArrayViewType -> k -> Type
112+
newtype AV a t = AV (ArrayView a)
113+
114+
derive instance genericAV :: Generic (AV a t) _
115+
116+
instance ordArrayView :: (TypedArray a t, Ord t) => Ord (AV a t) where
117+
compare (AV a) (AV b) = unsafePerformEffect $ TA.compare a b
118+
119+
instance eqArrayView :: (TypedArray a t, Eq t) => Eq (AV a t) where
120+
eq (AV a) (AV b) = unsafePerformEffect $ TA.eq a b
121+
122+
instance showArrayView :: (TypedArray a t, Show t) => Show (AV a t) where
123+
show (AV a) = "T[" <> s <> "]"
124+
where s = unsafePerformEffect $ toString a
125+
126+
instance semigroupArrayView :: TypedArray a t => Semigroup (AV a t) where
127+
append (AV a) (AV b) = unsafePerformEffect do
128+
let la = TA.length a
129+
lb = TA.length b
130+
r <- TA.empty $ la + lb
131+
void $ TA.setTyped r (Just 0) a
132+
void $ TA.setTyped r (Just la) b
133+
pure $ AV r
134+
135+
instance monoidArrayView :: TypedArray a t => Monoid (AV a t) where
136+
mempty = AV $ unsafePerformEffect $ TA.empty 0
137+
138+
instance arbitraryArrayView :: (TypedArray a t, Arbitrary t) => Arbitrary (AV a t) where
139+
arbitrary = do
140+
xs <- arbitrary
141+
pure $ unsafePerformEffect $ AV <$> TA.fromArray xs

0 commit comments

Comments
 (0)