Skip to content
Browse files

Fix for a coffeescript problem.

  • Loading branch information...
1 parent aed847b commit f1c8513f829cf1bd69456e82064d95794c73a4b3 @russellmcc committed Mar 12, 2012
Showing with 187 additions and 187 deletions.
  1. +1 −1 .npmignore
  2. +100 −100 lib/osc-utilities.coffee
  3. +10 −10 package.json
  4. +76 −76 test/test-osc-utilities.coffee
View
2 .npmignore
@@ -1 +1 @@
-node_modules
+node_modules/
View
200 lib/osc-utilities.coffee
@@ -7,15 +7,15 @@
# require("coffee-script");
# osc-utils = require("osc/lib/osc-utilities");
#
-# See the comments in osc.coffee for more information about the structure of
+# See the comments in osc.coffee for more information about the structure of
# the objects we're dealing with here.
#
# ## Dependencies
# require the minimal binary packing utilities
binpack = require "binpack"
-# ## Exported Functions
+# ## Exported Functions
# Utility for working with buffers. takes an array of buffers,
# output one buffer with all of the array concatenated
@@ -25,11 +25,11 @@ binpack = require "binpack"
exports.concat = (buffers) ->
if not IsArray buffers
throw new Error "concat must take an array of buffers"
-
+
for buffer in buffers
if not Buffer.isBuffer(buffer)
throw new Error "concat must take an array of buffers"
-
+
sumLength = 0
sumLength += buffer.length for buffer in buffers
@@ -51,19 +51,19 @@ exports.concat = (buffers) ->
# (i.e. contains a \u0000 character)
exports.toOscString = (str, strict) ->
throw new Error "can't pack a non-string into an osc-string" if not (typeof str == "string")
-
+
# strip off any \u0000 characters.
nullIndex = str.indexOf("\u0000")
-
+
# if we're being strict, we can't allow strings with null characters
throw StrictError "Can't pack an osc-string that contains NULL characters" if (nullIndex != -1 and strict)
str = str[0...nullIndex] if nullIndex != -1
-
+
# osc-strings must have length divisible by 4 and end with at least one zero.
- for i in [0..(padding str)]
+ for i in [0...(padding str)]
str += "\u0000"
-
+
# create a new buffer from the string.
new Buffer(str)
@@ -72,7 +72,7 @@ exports.toOscString = (str, strict) ->
# with the following layout:
# { string : "blah" rest : <Buffer>}.
#
-# `strict`, as above, is an optional boolean parameter that defaults to false -
+# `strict`, as above, is an optional boolean parameter that defaults to false -
# if it is true, then an invalid buffer will always return null.
#
exports.splitOscString = (buffer, strict) ->
@@ -81,46 +81,46 @@ exports.splitOscString = (buffer, strict) ->
# extract the string
rawStr = buffer.toString "utf8"
nullIndex = rawStr.indexOf "\u0000"
-
+
# the rest of the code doesn't apply if there's no null character.
if nullIndex == -1
throw new Error "All osc-strings must contain a null character" if strict
return {string:rawStr, rest:(new Buffer 0)}
-
+
# extract the string.
- str = rawStr[0...nullIndex]
-
+ str = rawStr[0...nullIndex]
+
# find the length of the string's buffer
splitPoint = Buffer.byteLength(str) + padding(str)
-
+
# in strict mode, don't succeed if there's not enough padding.
throw StrictError "Not enough padding for osc-string" if strict and splitPoint > buffer.length
-
+
# if we're in strict mode, check that all the padding is null
if strict
for i in [Buffer.byteLength(str)...splitPoint]
throw StrictError "Not enough or incorrect padding for osc-string" if buffer[i] != 0
-
+
# return a split
rest = buffer[splitPoint...(buffer.length)]
-
+
{string: str, rest: rest}
-
+
# This has similar semantics to splitOscString but works with integers instead.
# bytes is the number of bytes in the integer, defaults to 4.
exports.splitInteger = (buffer, type) ->
type = "Int32" if not type?
bytes = (binpack["pack" + type] 0).length
-
+
throw new Error "buffer is not big enough for integer type" if buffer.length < bytes
-
+
num = 0
-
+
# integers are stored in big endian format.
value = binpack["unpack" + type] buffer[0...bytes], "big"
-
+
rest = buffer[bytes...(buffer.length)]
-
+
return {integer : value, rest : rest}
exports.toIntegerBuffer = (number, type) ->
@@ -133,7 +133,7 @@ exports.toIntegerBuffer = (number, type) ->
# - split : a function to split a buffer into a decoded value and the rest of the buffer.
# - toArg : a function that takes the representation of the type and outputs a buffer.
oscTypeCodes =
- s : {
+ s : {
representation : "string"
split : (buffer, strict) ->
# just pass it through to splitOscString
@@ -143,9 +143,9 @@ oscTypeCodes =
throw new Error "expected string" if typeof value isnt "string"
exports.toOscString value, strict
}
- i : {
+ i : {
representation : "integer"
- split : (buffer, strict) ->
+ split : (buffer, strict) ->
split = exports.splitInteger buffer
{value : split.integer, rest : split.rest}
toArg : (value, strict) ->
@@ -188,7 +188,7 @@ oscTypeCodes =
toArg : (value, strict) ->
throw new Error "expected node.js Buffer" if not Buffer.isBuffer value
size = exports.toIntegerBuffer value.length
- exports.concat [size, value]
+ exports.concat [size, value]
}
T : {
representation : "true"
@@ -225,61 +225,61 @@ oscTypeCodes =
toArg : (value, strict) ->
new Buffer 0
}
-
+
# simple function that converts a type code into it's javascript
# string representation.
exports.oscTypeCodeToTypeString = (code) ->
oscTypeCodes[code]?.representation
-
+
# simple function that converts a javascript string representation
# into its OSC type code.
exports.typeStringToOscTypeCode = (rep) ->
for own code, {representation : str} of oscTypeCodes
return code if str is rep
return null
-
+
exports.argToTypeCode = (arg, strict) ->
# if there's an explicit type annotation, back-translate that.
return code if arg?.type? and (typeof arg.type is 'string') and (code = exports.typeStringToOscTypeCode arg.type)?
-
+
value = if arg?.value? then arg.value else arg
-
+
# now, we try to guess the type.
throw new Error 'Argument has no value' if strict and not value?
-
+
# if it's a string, use 's'
if typeof value is 'string'
return 's'
-
+
# if it's a number, use 'f' by default.
if typeof value is 'number'
return 'f'
-
+
# if it's a buffer, use 'b'
if Buffer.isBuffer(value)
return 'b'
-
+
#### These are 1.1 specific types.
-
+
# if it's a boolean, use 'T' or 'F'
if typeof value is 'boolean'
if value then return 'T' else return 'F'
-
+
# if it's null, use 'N'
if value is null
return 'N'
-
+
throw new Error "I don't know what type this is supposed to be."
-# Splits out an argument from buffer. Same thing as splitOscString but
+# Splits out an argument from buffer. Same thing as splitOscString but
# works for all argument types.
exports.splitOscArgument = (buffer, type, strict) ->
osctype = exports.typeStringToOscTypeCode type
if osctype?
oscTypeCodes[osctype].split buffer, strict
else
throw new Error "I don't understand how I'm supposed to unpack #{type}"
-
+
# Create a buffer with the given javascript type
exports.toOscArgument = (value, type, strict) ->
osctype = exports.typeStringToOscTypeCode type
@@ -294,66 +294,66 @@ exports.toOscArgument = (value, type, strict) ->
exports.fromOscMessage = (buffer, strict) ->
# break off the address
{ string : address, rest : buffer} = exports.splitOscString buffer, strict
-
+
# technically, addresses have to start with '/'.
throw StrictError 'addresses must start with /' if strict and address[0] isnt '/'
-
+
# if there's no type string, this is technically illegal, but
# the specification says we should accept this until all
# implementations that send message without a type string are fixed.
# this will never happen, so we should accept this, even in
# strict mode.
return {address : address, arguments : []} if not buffer.length
- # if there's more data but no type string, we can't parse the arguments.
+ # if there's more data but no type string, we can't parse the arguments.
{string : types, rest : buffer} = exports.splitOscString buffer, strict
-
+
# if the first letter isn't a ',' this isn't a valid type so we can't
# parse the arguments.
if types[0] isnt ','
throw StrictError 'Argument lists must begin with ,' if strict
- return {address : address, arguments : []}
-
+ return {address : address, arguments : []}
+
# we don't need the comma anymore
types = types[1..(types.length)]
-
+
args = []
# grab each argument.
for type in types
# by the standard, we have to ignore the whole message if we don't understand an argument
typeString = exports.oscTypeCodeToTypeString type
throw new Error "I don't understand the argument code #{type}" if not typeString?
-
+
arg = exports.splitOscArgument buffer, typeString, strict
-
+
# consume the argument from the buffer
buffer = arg.rest if arg?
-
+
# add it to the list.
args.push(
type : typeString
value : arg?.value
)
-
+
{address : address, arguments : args, oscType : "message"}
-
+
#
# Try to parse an OSC bundle into a javascript object.
#
exports.fromOscBundle = (buffer, strict) ->
# break off the bundletag
{ string : bundleTag, rest : buffer} = exports.splitOscString buffer, strict
-
+
# bundles have to start with "#bundle".
throw new Error "osc-bundles must begin with \#bundle" if bundleTag isnt "\#bundle"
-
+
# grab the 8 - bit timetag
{ integer : timetag, rest : buffer} = exports.splitInteger buffer, "UInt64"
# convert each element.
- convertedElems = mapBundleList buffer, (buffer) ->
+ convertedElems = mapBundleList buffer, (buffer) ->
exports.fromOscPacket buffer, strict
-
+
return {timetag : timetag, elements : convertedElems, oscType : "bundle"}
#
@@ -364,7 +364,7 @@ exports.fromOscPacket = (buffer, strict) ->
exports.fromOscBundle buffer, strict
else
exports.fromOscMessage buffer, strict
-
+
#
# convert a javascript format message into an osc buffer
#
@@ -376,20 +376,20 @@ exports.toOscMessage = (message, strict) ->
arguments = message?.arguments
if (not arguments?) and (message?.args?)
arguments = message?.args
-
+
if arguments is undefined
arguments = []
-
+
# pack single arguments
if not IsArray arguments
old_arg = arguments
arguments = []
arguments[0] = old_arg
-
+
oscaddr = exports.toOscString address, strict
osctype = ","
oscarguments = []
-
+
# fill in arguments
for arg in arguments
typeCode = exports.argToTypeCode arg, strict
@@ -404,14 +404,14 @@ exports.toOscMessage = (message, strict) ->
# convert the type tag into an oscString.
osctype = exports.toOscString osctype
-
+
# bundle everything together.
allArgs = exports.concat oscarguments
exports.concat [oscaddr, osctype, allArgs]
#
# convert a javascript format bundle into an osc buffer
-#
+#
exports.toOscBundle = (bundle, strict) ->
# the bundle must have timetag and elements.
throw StrictError "bundles must have timetags." if strict and not bundle?.timetag?
@@ -421,69 +421,69 @@ exports.toOscBundle = (bundle, strict) ->
elemstr = elements
elements = []
elements.push elemstr
-
+
oscBundleTag = exports.toOscString "\#bundle"
oscTimeTag = exports.toIntegerBuffer timetag, "UInt64"
-
+
oscElems = []
for elem in elements
try
# try to convert this sub-element into a buffer
buff = exports.toOscPacket elem, strict
-
+
# okay, pack in the size.
size = exports.toIntegerBuffer buff.length
oscElems.push exports.concat [size, buff]
catch e
null
-
- allElems = exports.concat oscElems
+
+ allElems = exports.concat oscElems
exports.concat [oscBundleTag, oscTimeTag, allElems]
-
+
# convert a javascript format bundle or message into a buffer
exports.toOscPacket = (bundleOrMessage, strict) ->
# first, determine whether or not this is a bundle.
if bundleOrMessage?.oscType?
return exports.toOscBundle bundleOrMessage, strict if bundleOrMessage.oscType is "bundle"
return exports.toOscMessage bundleOrMessage, strict
-
+
# bundles have "timetags" and "elements"
return exports.toOscBundle bundleOrMessage, strict if bundleOrMessage?.timetag? or bundleOrMessage?.elements?
-
+
exports.toOscMessage bundleOrMessage, strict
#
# Helper function for transforming all messages in a bundle with a given message
# transform.
#
exports.applyMessageTranformerToBundle = (transform) -> (buffer) ->
-
+
# parse out the bundle-id and the tag, we don't want to change these
{ string, rest : buffer} = exports.splitOscString buffer
-
+
# bundles have to start with "#bundle".
throw new Error "osc-bundles must begin with \#bundle" if string isnt "\#bundle"
-
+
bundleTagBuffer = exports.toOscString string
-
+
# we know that the timetag is 8 bytes, we don't want to mess with it, so grab it as
# a buffer. There is some subtle loss of precision with the round trip from
# int64 to float64.
timetagBuffer = buffer[0...8]
buffer = buffer[8...buffer.length]
-
+
# convert each element.
- elems = mapBundleList buffer, (buffer) ->
+ elems = mapBundleList buffer, (buffer) ->
exports.applyTransform(
- buffer,
- transform,
+ buffer,
+ transform,
exports.applyMessageTranformerToBundle transform
)
totalLength = bundleTagBuffer.length + timetagBuffer.length
totalLength += 4 + elem.length for elem in elems
-
- # okay, now we have to reconcatenate everything.
+
+ # okay, now we have to reconcatenate everything.
outBuffer = new Buffer totalLength
bundleTagBuffer.copy outBuffer, 0
timetagBuffer.copy outBuffer, bundleTagBuffer.length
@@ -499,7 +499,7 @@ exports.applyMessageTranformerToBundle = (transform) -> (buffer) ->
#
# Applies a transformation function (that is, a function from buffers to buffers)
# to each element of given osc-bundle or message.
-#
+#
# `buffer` is the buffer to transform, which must be a buffer of a full packet.
# `messageTransform` is function from message buffers to message buffers
# `bundleTransform` is an optional parameter for functions from bundle buffers to bundle buffers.
@@ -509,12 +509,12 @@ exports.applyMessageTranformerToBundle = (transform) -> (buffer) ->
exports.applyTransform = (buffer, mTransform, bundleTransform) ->
if not bundleTransform?
bundleTransform = exports.applyMessageTranformerToBundle mTransform
-
+
if isOscBundleBuffer buffer
bundleTransform buffer
else
mTransform buffer
-
+
# Converts a javascript function from string to string to a function
# from message buffer to message buffer, applying the function to the
# parsed strings.
@@ -523,11 +523,11 @@ exports.applyTransform = (buffer, mTransform, bundleTransform) ->
#
exports.addressTransform = (transform) -> (buffer) ->
# parse out the address
- {string, rest} = exports.splitOscString buffer
-
+ {string, rest} = exports.splitOscString buffer
+
# apply the function
string = transform string
-
+
# re-concatenate
exports.concat [
exports.toOscString string
@@ -541,7 +541,7 @@ exports.addressTransform = (transform) -> (buffer) ->
exports.messageTransform = (transform) -> (buffer) ->
message = exports.fromOscMessage buffer
exports.toOscMessage transform message
-
+
## Private utilities
#
@@ -559,16 +559,16 @@ StrictError = (str) ->
padding = (str) ->
bufflength = Buffer.byteLength(str)
4 - (bufflength % 4)
-
+
#
# Internal function to check if this is a message or bundle.
#
isOscBundleBuffer = (buffer, strict) ->
# both formats begin with strings, so we should just grab the front but not consume it.
{string} = exports.splitOscString buffer, strict
-
+
return string is "\#bundle"
-
+
#
# Does something for each element in an array of osc-message-or-bundles,
# each prefixed by a length (such as appears in osc-messages), then
@@ -584,25 +584,25 @@ mapBundleList = (buffer, func) ->
elems = while buffer.length
# the length of the element is stored in an integer
{integer : size, rest : buffer} = exports.splitInteger buffer
-
+
# if the size is bigger than the packet, something's messed up, so give up.
- if size > buffer.length
- throw new Error "Invalid bundle list: size of element is bigger than buffer"
+ if size > buffer.length
+ throw new Error "Invalid bundle list: size of element is bigger than buffer"
thisElemBuffer = buffer[0...size]
-
+
# move the buffer to after the element we're just parsing.
buffer = buffer[size...buffer.length]
-
+
# record this element
try
func thisElemBuffer
catch e
null
-
+
# remove all null from elements
nonNullElems = []
for elem in elems
(nonNullElems.push elem) if elem?
-
+
nonNullElems
View
20 package.json
@@ -1,6 +1,6 @@
{
"name": "osc-min",
- "version": "0.0.2",
+ "version": "0.0.3",
"main": "lib/index",
"author": {
"name" : "Russell McClellan",
@@ -18,20 +18,20 @@
"type": "git",
"url": "http://github.com/ghostfact/node-osc-min.git"
},
- "dependencies" : [
- "binpack",
- "coffee-script"
- ],
- "devDependencies" : [
- "expresso",
- "docket>=0.0.3"
- ],
+ "dependencies" : {
+ "binpack" : "*",
+ "coffee-script" : ">=1.2.0"
+ },
+ "devDependencies" : {
+ "expresso" : "*",
+ "docket" : ">=0.0.3"
+ },
"directories": {
"lib": "lib",
"examples" : "examples"
},
"engines": {
- "node": ">=0.3.0"
+ "node": ">=0.6.0"
},
"scripts": {
"test" : "cake test",
View
152 test/test-osc-utilities.coffee
@@ -3,15 +3,15 @@
# actual unit tests.
#
-osc = require "osc-utilities"
+osc = require "../lib/osc-utilities"
assert = require "assert"
# Basic string tests.
testString = (str, expected_len) ->
str : str
len : expected_len
-
+
testData = [
testString("abc", 4)
testString("abcd", 8)
@@ -27,54 +27,54 @@ testStringLength = (str, expected_len) ->
exports["basic strings length"] = ->
for data in testData
testStringLength data.str, data.len
-
+
testStringRoundTrip = (str, strict) ->
oscstr = osc.toOscString(str)
str2 = osc.splitOscString(oscstr, strict)?.string
assert.strictEqual(str, str2)
-
+
exports["basic strings round trip"] = ->
for data in testData
testStringRoundTrip data.str
-
-
+
+
exports["non strings fail toOscString"] = ->
assert.throws -> osc.toOscString(7)
-
-
+
+
exports["strings with null characters don't fail toOscString by default"] = ->
assert.notEqual(osc.toOscString("\u0000"), null)
-
-
+
+
exports["strings with null characters fail toOscString in strict mode"] = ->
assert.throws -> osc.toOscString("\u0000", true)
-
-
+
+
exports["osc buffers with no null characters fail splitOscString in strict mode"] = ->
assert.throws -> osc.splitOscString new Buffer("abc"), true
-
+
exports["osc buffers with non-null characters after a null character fail fromOscString in strict mode"] = ->
assert.throws -> osc.fromOscString new Buffer("abc\u0000abcd"), true
-
+
exports["basic strings pass fromOscString in strict mode"] = ->
for data in testData
testStringRoundTrip data.str, true
-
+
exports["osc buffers with non-four length fail in strict mode"] = ->
assert.throws -> osc.fromOscString new Buffer("abcd\u0000\u0000"), true
-
+
exports["splitOscString throws when passed a non-buffer"] = ->
assert.throws -> osc.splitOscString "test"
exports["splitOscString of an osc-string matches the string"] = ->
split = osc.splitOscString osc.toOscString "testing it"
assert.strictEqual(split?.string, "testing it")
assert.strictEqual(split?.rest?.length, 0)
-
+
exports["splitOscString works with an over-allocated buffer"] = ->
buffer = osc.toOscString "testing it"
@@ -83,27 +83,27 @@ exports["splitOscString works with an over-allocated buffer"] = ->
split = osc.splitOscString overallocated
assert.strictEqual(split?.string, "testing it")
assert.strictEqual(split?.rest?.length, 4)
-
-
+
+
exports["splitOscString works with just a string by default"] = ->
split = osc.splitOscString (new Buffer "testing it")
assert.strictEqual(split?.string, "testing it")
assert.strictEqual(split?.rest?.length, 0)
-
-
+
+
exports["splitOscString strict fails for just a string"] = ->
assert.throws -> osc.splitOscString (new Buffer "testing it"), true
-
+
exports["splitOscString strict fails for string with not enough padding"] = ->
assert.throws -> osc.splitOscString (new Buffer "testing \u0000\u0000"), true
-
+
exports["splitOscString strict succeeds for strings with valid padding"] = ->
split = osc.splitOscString (new Buffer "testing it\u0000\u0000aaaa"), true
assert.strictEqual(split?.string, "testing it")
assert.strictEqual(split?.rest?.length, 4)
-
+
exports["splitOscString strict fails for string with invalid padding"] = ->
assert.throws -> osc.splitOscString (new Buffer "testing it\u0000aaaaa"), true
@@ -119,15 +119,15 @@ exports["toIntegerBuffer throws when passed a non-number"] = ->
exports["splitInteger fails when sent a buffer that's too small"] = ->
assert.throws -> osc.splitInteger new Buffer 3, "Int32"
-
+
exports["splitOscArgument fails when given a bogus type"] = ->
assert.throws -> osc.splitOscArgument new Buffer 8, "bogus"
exports["fromOscMessage with no type string works"] = ->
translate = osc.fromOscMessage osc.toOscString "/stuff"
assert.strictEqual translate?.address, "/stuff"
assert.deepEqual translate?.arguments, []
-
+
exports["fromOscMessage with type string and no arguments works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ","
@@ -137,7 +137,7 @@ exports["fromOscMessage with type string and no arguments works"] = ->
translate = osc.fromOscMessage oscmessage
assert.strictEqual translate?.address, "/stuff"
assert.deepEqual translate?.arguments, []
-
+
exports["fromOscMessage with string argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",s"
@@ -146,15 +146,15 @@ exports["fromOscMessage with string argument works"] = ->
assert.strictEqual translate?.address, "/stuff"
assert.strictEqual translate?.arguments?[0]?.type, "string"
assert.strictEqual translate?.arguments?[0]?.value, "argu"
-
+
exports["fromOscMessage with true argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",T"
translate = osc.fromOscMessage osc.concat [oscaddr, osctype]
assert.strictEqual translate?.address, "/stuff"
assert.strictEqual translate?.arguments?[0]?.type, "true"
assert.strictEqual translate?.arguments?[0]?.value, true
-
+
exports["fromOscMessage with false argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",F"
@@ -187,8 +187,8 @@ exports["fromOscMessage with blob argument works"] = ->
assert.strictEqual translate?.address, "/stuff"
assert.strictEqual translate?.arguments?[0]?.type, "blob"
assert.strictEqual (translate?.arguments?[0]?.value?.toString "utf8"), "argu"
-
-
+
+
exports["fromOscMessage with integer argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",i"
@@ -197,7 +197,7 @@ exports["fromOscMessage with integer argument works"] = ->
assert.strictEqual translate?.address, "/stuff"
assert.strictEqual translate?.arguments?[0]?.type, "integer"
assert.strictEqual (translate?.arguments?[0]?.value), 888
-
+
exports["fromOscMessage with timetag argument works"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",t"
@@ -206,7 +206,7 @@ exports["fromOscMessage with timetag argument works"] = ->
assert.strictEqual translate?.address, "/stuff"
assert.strictEqual translate?.arguments?[0]?.type, "timetag"
assert.strictEqual (translate?.arguments?[0]?.value), 8888
-
+
exports["fromOscMessage with multiple arguments works."] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString ",sbi"
@@ -225,9 +225,9 @@ exports["fromOscMessage with multiple arguments works."] = ->
exports["fromOscMessage strict fails if type string has no comma"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString "fake"
- assert.throws ->
+ assert.throws ->
osc.fromOscMessage (osc.concat [oscaddr, osctype]), true
-
+
exports["fromOscMessage non-strict works if type string has no comma"] = ->
oscaddr = osc.toOscString "/stuff"
osctype = osc.toOscString "fake"
@@ -238,19 +238,19 @@ exports["fromOscMessage non-strict works if type string has no comma"] = ->
exports["fromOscMessage strict fails if type address doesn't begin with /"] = ->
oscaddr = osc.toOscString "stuff"
osctype = osc.toOscString ","
- assert.throws ->
+ assert.throws ->
osc.fromOscMessage (osc.concat [oscaddr, osctype]), true
-
-
+
+
exports["fromOscBundle works with no messages"] = ->
oscbundle = osc.toOscString "#bundle"
osctimetag = osc.toIntegerBuffer 0, "UInt64"
buffer = osc.concat [oscbundle, osctimetag]
translate = osc.fromOscBundle buffer
assert.strictEqual translate?.timetag, 0
assert.deepEqual translate?.elements, []
-
-
+
+
exports["fromOscBundle works with single message"] = ->
oscbundle = osc.toOscString "#bundle"
osctimetag = osc.toIntegerBuffer 0, "UInt64"
@@ -263,8 +263,8 @@ exports["fromOscBundle works with single message"] = ->
assert.strictEqual translate?.timetag, 0
assert.strictEqual translate?.elements?.length, 1
assert.strictEqual translate?.elements?[0]?.address, "/addr"
-
-
+
+
exports["fromOscBundle works with multiple messages"] = ->
oscbundle = osc.toOscString "#bundle"
osctimetag = osc.toIntegerBuffer 0, "UInt64"
@@ -282,8 +282,8 @@ exports["fromOscBundle works with multiple messages"] = ->
assert.strictEqual translate?.elements?.length, 2
assert.strictEqual translate?.elements?[0]?.address, "/addr"
assert.strictEqual translate?.elements?[1]?.address, "/addr2"
-
-
+
+
exports["fromOscBundle works with nested bundles"] = ->
oscbundle = osc.toOscString "#bundle"
osctimetag = osc.toIntegerBuffer 0, "UInt64"
@@ -301,7 +301,7 @@ exports["fromOscBundle works with nested bundles"] = ->
assert.strictEqual translate?.elements?.length, 2
assert.strictEqual translate?.elements?[0]?.address, "/addr"
assert.strictEqual translate?.elements?[1]?.timetag, 0
-
+
exports["fromOscBundle works with non-understood messages"] = ->
oscbundle = osc.toOscString "#bundle"
osctimetag = osc.toIntegerBuffer 0, "UInt64"
@@ -344,7 +344,7 @@ roundTripMessage = (args) ->
assert.strictEqual roundTrip?.arguments?[i]?.type, args[i].type if args[i]?.type?
if Buffer.isBuffer comp
for j in [0...comp.length]
- assert.strictEqual roundTrip?.arguments?[i]?.value?[j], comp[j]
+ assert.strictEqual roundTrip?.arguments?[i]?.value?[j], comp[j]
else
assert.strictEqual roundTrip?.arguments?[i]?.value, comp
@@ -354,7 +354,7 @@ exports["toOscArgument fails when given bogus type"] = ->
# we tested fromOsc* manually, so just use roundtrip testing for toOsc*
exports["toOscMessage with no arguments works"] = ->
roundTripMessage []
-
+
exports["toOscMessage strict with null argument throws"] = ->
assert.throws -> osc.toOscMessage {address : "/addr", arguments : [null]}, true
@@ -399,7 +399,7 @@ exports["toOscMessage with args shortcut works"] = ->
assert.strictEqual roundTrip?.arguments?.length, 1
assert.strictEqual roundTrip?.arguments?[0]?.value, 13
assert.strictEqual roundTrip?.arguments?[0]?.type, "float"
-
+
exports["toOscMessage with single blob argument works"] = ->
buff = new Buffer 18
oscMessage = {
@@ -411,7 +411,7 @@ exports["toOscMessage with single blob argument works"] = ->
assert.strictEqual roundTrip?.arguments?.length, 1
buffeq roundTrip?.arguments?[0]?.value, buff
assert.strictEqual roundTrip?.arguments?[0]?.type, "blob"
-
+
exports["toOscMessage with single string argument works"] = ->
oscMessage = {
address : "/addr"
@@ -420,12 +420,12 @@ exports["toOscMessage with single string argument works"] = ->
roundTrip = osc.fromOscMessage (osc.toOscMessage oscMessage)
assert.strictEqual roundTrip?.address, "/addr"
assert.strictEqual roundTrip?.arguments?.length, 1
- assert.strictEqual roundTrip?.arguments?[0]?.value, "strr"
+ assert.strictEqual roundTrip?.arguments?[0]?.value, "strr"
assert.strictEqual roundTrip?.arguments?[0]?.type, "string"
-
+
exports["toOscMessage with integer argument works"] = ->
roundTripMessage [8]
-
+
exports["toOscMessage with buffer argument works"] = ->
# buffer will have random contents, but that's okay.
roundTripMessage [new Buffer 16]
@@ -441,13 +441,13 @@ exports["toOscMessage with type true works"] = ->
assert.strictEqual roundTrip.arguments.length, 1
assert.strictEqual roundTrip.arguments[0].value, true
assert.strictEqual roundTrip.arguments[0].type, "true"
-
+
exports["toOscMessage with type false works"] = ->
roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", arguments : false}
assert.strictEqual roundTrip.arguments.length, 1
assert.strictEqual roundTrip.arguments[0].value, false
assert.strictEqual roundTrip.arguments[0].type, "false"
-
+
exports["toOscMessage with type bang argument works"] = ->
roundTrip = osc.fromOscMessage osc.toOscMessage {address: "/addr", arguments : {type:"bang"}}
assert.strictEqual roundTrip.arguments.length, 1
@@ -471,27 +471,27 @@ exports["toOscMessage with type null works"] = ->
exports["toOscMessage with float argument works"] = ->
roundTripMessage [{value : 6, type : "float"}]
-
+
exports["toOscMessage just a string works"] = ->
message = osc.fromOscMessage osc.toOscMessage "bleh"
assert.strictEqual message.address, "bleh"
assert.strictEqual message.arguments.length, 0
-
+
exports["toOscMessage with multiple arguments works"] = ->
roundTripMessage ["str", 7, (new Buffer 30), 6]
exports["toOscMessage with integer argument works"] = ->
roundTripMessage [{value : 7, type: "integer"}]
-
+
exports["toOscMessage fails with no address"] = ->
- assert.throws -> osc.toOscMessage {arguments : []}
-
+ assert.throws -> osc.toOscMessage {arguments : []}
+
toOscMessageThrowsHelper = (arg) ->
assert.throws -> osc.toOscMessage(
address : "/addr"
arguments : [arg]
)
-
+
exports["toOscMessage fails when string type is specified but wrong"] = ->
toOscMessageThrowsHelper(
value : 7
@@ -503,25 +503,25 @@ exports["toOscMessage fails when integer type is specified but wrong"] = ->
value : "blah blah"
type : "integer"
)
-
+
exports["toOscMessage fails when float type is specified but wrong"] = ->
toOscMessageThrowsHelper(
value : "blah blah"
type : "float"
)
-
+
exports["toOscMessage fails when timetag type is specified but wrong"] = ->
toOscMessageThrowsHelper(
value : "blah blah"
type : "timetag"
)
-
+
exports["toOscMessage fails when double type is specified but wrong"] = ->
toOscMessageThrowsHelper(
value : "blah blah"
type : "double"
)
-
+
exports["toOscMessage fails when blob type is specified but wrong"] = ->
toOscMessageThrowsHelper(
value : "blah blah"
@@ -547,9 +547,9 @@ roundTripBundle = (elems) ->
if typeof elems is "object"
assert.strictEqual roundTrip?.elements?[i]?.timetag, elems[i].timetag
assert.strictEqual roundTrip?.elements?[i]?.address, elems[i].address
- else
+ else
assert.strictEqual roundTrip?.elements?[i]?.address, elems
-
+
exports["toOscBundle with no elements works"] = ->
roundTripBundle []
@@ -561,7 +561,7 @@ exports["toOscBundle with just a number fails"] = ->
exports["toOscBundle with one message works"] = ->
roundTripBundle [{address : "/addr"}]
-
+
exports["toOscBundle with nested bundles works"] = ->
roundTripBundle [{address : "/addr"}, {timetag : 0}]
@@ -575,7 +575,7 @@ exports["toOscBundle with bogus packets works"] = ->
exports["toOscBundle strict fails without timetags"] = ->
assert.throws -> osc.toOscBundle {elements :[]}, true
-
+
exports["identity applyTransform works with single message"] = ->
testBuffer = osc.toOscString "/message"
assert.strictEqual (osc.applyTransform testBuffer, (a) -> a), testBuffer
@@ -585,11 +585,11 @@ exports["nullary applyTransform works with single message"] = ->
assert.strictEqual (osc.applyTransform testBuffer, (a) -> new Buffer 0).length, 0
exports["toOscPacket works when explicitly set to bundle"] = ->
- roundTrip = osc.fromOscBundle osc.toOscPacket {timetag: 0, oscType:"bundle", elements :[]}, true
+ roundTrip = osc.fromOscBundle osc.toOscPacket {timetag: 0, oscType:"bundle", elements :[]}, true
assert.strictEqual roundTrip.elements.length, 0
exports["toOscPacket works when explicitly set to message"] = ->
- roundTrip = osc.fromOscPacket osc.toOscPacket {address: "/bleh", oscType:"message", arguments :[]}, true
+ roundTrip = osc.fromOscPacket osc.toOscPacket {address: "/bleh", oscType:"message", arguments :[]}, true
assert.strictEqual roundTrip.arguments.length, 0
assert.strictEqual roundTrip.address, "/bleh"
@@ -621,8 +621,8 @@ exports["addressTransform works with identity"] = ->
transformed = osc.applyTransform testBuffer, osc.addressTransform((a) -> a)
for i in [0...testBuffer.length]
assert.equal transformed[i], testBuffer[i]
-
-
+
+
exports["addressTransform works with bundles"] = ->
base = {
timetag : 0
@@ -645,8 +645,8 @@ exports["messageTransform works with identity function for single message"] = ->
arguments: []
buff = osc.toOscPacket message
buffeq (osc.applyTransform buff, osc.messageTransform (a) -> a), buff
-
-
+
+
exports["messageTransform works with bundles"] = ->
message = {
timetag : 0
@@ -657,5 +657,5 @@ exports["messageTransform works with bundles"] = ->
}
buff = osc.toOscPacket message
buffeq (osc.applyTransform buff, osc.messageTransform (a) -> a), buff
-
-
+
+

0 comments on commit f1c8513

Please sign in to comment.
Something went wrong with that request. Please try again.