Skip to content

Commit ba3b5de

Browse files
authoredFeb 10, 2017
Merge pull request #16 from rightfold/master
Fix a bug and a documentation mistake
2 parents 74f83b3 + aaade1d commit ba3b5de

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
 

‎src/Node/Buffer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ exports.toArray = function (buff) {
8989
};
9090
};
9191

92-
exports.getAtOffsetImpl = function (nothing) {
93-
return function (just) {
94-
return function (buff) {
95-
return function (offset) {
92+
exports.getAtOffsetImpl = function (just) {
93+
return function (nothing) {
94+
return function (offset) {
95+
return function (buff) {
9696
return function() {
9797
var octet = buff[offset];
9898
return octet == null ? nothing
99-
: just(buff[i]);
99+
: just(octet);
100100
};
101101
};
102102
};

‎src/Node/Buffer.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Data.Maybe (Maybe(..))
2828
import Node.Encoding (Encoding, encodingToNode)
2929

3030
-- | Type synonym indicating the value should be an octet (0-255). If the value
31-
-- | provided is outside this range it will be used as modulo 255.
31+
-- | provided is outside this range it will be used as modulo 256.
3232
type Octet = Int
3333

3434
-- | Type synonym indicating the value refers to an offset in a buffer.

‎test/Main.purs

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ module Test.Main where
33
import Prelude
44
import Control.Monad.Eff (Eff)
55
import Control.Monad.Eff.Console (log, CONSOLE())
6+
import Data.Maybe (Maybe(..))
67
import Data.Traversable (traverse)
7-
import Node.Buffer (BUFFER, BufferValueType(..), toArray, concat', fromArray, fill, copy, readString, fromString, toString, read, write, create)
8+
import Node.Buffer (BUFFER, BufferValueType(..), toArray, concat', fromArray, fill, copy, readString, fromString, toString, read, write, create, getAtOffset)
89
import Node.Encoding (Encoding(..))
910
import Test.Assert (ASSERT, assert')
1011

@@ -41,6 +42,9 @@ main = do
4142
log "concat'"
4243
testConcat'
4344

45+
log "getAtOffset"
46+
testGetAtOffset
47+
4448
testReadWrite :: Test
4549
testReadWrite = do
4650
buf <- create 1
@@ -120,6 +124,13 @@ testConcat' = do
120124

121125
assertEq [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] out
122126

127+
testGetAtOffset :: Test
128+
testGetAtOffset = do
129+
buf <- fromArray [1, 2, 3, 4]
130+
assertEq (Just 2) =<< getAtOffset 1 buf
131+
assertEq Nothing =<< getAtOffset 4 buf
132+
assertEq Nothing =<< getAtOffset (-1) buf
133+
123134
assertEq :: forall a. (Eq a, Show a) => a -> a -> Test
124135
assertEq x y =
125136
if x == y

0 commit comments

Comments
 (0)
Please sign in to comment.