Skip to content

Fix a bug and a documentation mistake #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Node/Buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ exports.toArray = function (buff) {
};
};

exports.getAtOffsetImpl = function (nothing) {
return function (just) {
return function (buff) {
return function (offset) {
exports.getAtOffsetImpl = function (just) {
return function (nothing) {
return function (offset) {
return function (buff) {
return function() {
var octet = buff[offset];
return octet == null ? nothing
: just(buff[i]);
: just(octet);
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Buffer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Data.Maybe (Maybe(..))
import Node.Encoding (Encoding, encodingToNode)

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

-- | Type synonym indicating the value refers to an offset in a buffer.
Expand Down
13 changes: 12 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module Test.Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log, CONSOLE())
import Data.Maybe (Maybe(..))
import Data.Traversable (traverse)
import Node.Buffer (BUFFER, BufferValueType(..), toArray, concat', fromArray, fill, copy, readString, fromString, toString, read, write, create)
import Node.Buffer (BUFFER, BufferValueType(..), toArray, concat', fromArray, fill, copy, readString, fromString, toString, read, write, create, getAtOffset)
import Node.Encoding (Encoding(..))
import Test.Assert (ASSERT, assert')

Expand Down Expand Up @@ -41,6 +42,9 @@ main = do
log "concat'"
testConcat'

log "getAtOffset"
testGetAtOffset

testReadWrite :: Test
testReadWrite = do
buf <- create 1
Expand Down Expand Up @@ -120,6 +124,13 @@ testConcat' = do

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

testGetAtOffset :: Test
testGetAtOffset = do
buf <- fromArray [1, 2, 3, 4]
assertEq (Just 2) =<< getAtOffset 1 buf
assertEq Nothing =<< getAtOffset 4 buf
assertEq Nothing =<< getAtOffset (-1) buf

assertEq :: forall a. (Eq a, Show a) => a -> a -> Test
assertEq x y =
if x == y
Expand Down