-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from muzzammilshahid/helpers-tests
Add tests for helpers
- Loading branch information
Showing
2 changed files
with
82 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import "dart:typed_data"; | ||
|
||
import "package:test/test.dart"; | ||
import "package:wampproto/messages.dart"; | ||
import "package:wampproto/serializers.dart"; | ||
|
||
import "package:xconn/src/helpers.dart"; | ||
|
||
class TestSerializer implements Serializer { | ||
@override | ||
Uint8List serialize(final Message message) { | ||
return Uint8List.fromList("".codeUnits); | ||
} | ||
|
||
@override | ||
Message deserialize(final Object message) { | ||
return Hello("realm", {}, "", []); | ||
} | ||
} | ||
|
||
void main() { | ||
test("getSubProtocol", () { | ||
// with json Serializer | ||
var jsonProtocol = getSubProtocol(JSONSerializer()); | ||
expect(jsonProtocol, jsonSubProtocol); | ||
|
||
// with cbor Serializer | ||
var cborProtocol = getSubProtocol(CBORSerializer()); | ||
expect(cborProtocol, cborSubProtocol); | ||
|
||
// with msgpack Serializer | ||
var msgpackProtocol = getSubProtocol(MsgPackSerializer()); | ||
expect(msgpackProtocol, msgpackSubProtocol); | ||
|
||
// with invalid Serializer | ||
expect(() => getSubProtocol(TestSerializer()), throwsArgumentError); | ||
}); | ||
|
||
test("getSerializer", () { | ||
// with json subProtocol | ||
var jsonSerializer = getSerializer(jsonSubProtocol); | ||
expect(jsonSerializer, isA<JSONSerializer>()); | ||
|
||
// null should also return jsonSerializer | ||
var jsonSerializer1 = getSerializer(null); | ||
expect(jsonSerializer1, isA<JSONSerializer>()); | ||
|
||
// with cbor subProtocol | ||
var cborSerializer = getSerializer(cborSubProtocol); | ||
expect(cborSerializer, isA<CBORSerializer>()); | ||
|
||
// with msgpack subProtocol | ||
var msgpackSerializer = getSerializer(msgpackSubProtocol); | ||
expect(msgpackSerializer, isA<MsgPackSerializer>()); | ||
|
||
// with invalid subProtocol | ||
expect(() => getSerializer("abc"), throwsException); | ||
}); | ||
|
||
test("wampErrorString", () { | ||
// with no args or kwargs | ||
final error = Error(Register.id, 1, "wamp.error.no_such_procedure"); | ||
var errString = wampErrorString(error); | ||
expect(errString, "wamp.error.no_such_procedure"); | ||
|
||
// with args only | ||
final errorArgs = Error(Register.id, 1, "wamp.error.no_such_procedure", args: [1, "two"]); | ||
var errArgsString = wampErrorString(errorArgs); | ||
expect(errArgsString, "wamp.error.no_such_procedure: 1, two"); | ||
|
||
// with kwargs only | ||
final errorKwArgs = Error(Register.id, 1, "wamp.error.no_such_procedure", kwargs: {"key": "value"}); | ||
var errKwArgsString = wampErrorString(errorKwArgs); | ||
expect(errKwArgsString, "wamp.error.no_such_procedure: key=value"); | ||
|
||
// with args and kwargs | ||
final errorArgsKwArgs = | ||
Error(Register.id, 1, "wamp.error.no_such_procedure", args: [1, "two"], kwargs: {"key": "value"}); | ||
var errArgsKwArgsString = wampErrorString(errorArgsKwArgs); | ||
expect(errArgsKwArgsString, "wamp.error.no_such_procedure: 1, two: key=value"); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.