style: prefer single quotes (#117)

This commit is contained in:
Evgeny Poberezkin 2021-10-09 13:12:12 +01:00 committed by GitHub
parent 19ef1f65db
commit fd247a4e6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 153 additions and 153 deletions

View File

@ -2,7 +2,7 @@ include: package:lints/recommended.yaml
linter:
rules:
prefer_double_quotes: true
prefer_single_quotes: true
constant_identifier_names: false
always_declare_return_types: true
avoid_dynamic_calls: true

View File

@ -3,5 +3,5 @@
/// More dartdocs go here.
library simplexmq;
export "src/protocol.dart";
export "src/transport.dart" show Transport;
export 'src/protocol.dart';
export 'src/transport.dart' show Transport;

View File

@ -1,4 +1,4 @@
import "dart:typed_data";
import 'dart:typed_data';
Uint8List encodeAscii(String s) => Uint8List.fromList(s.codeUnits);
@ -29,8 +29,8 @@ Uint8List concatN(List<Uint8List> bs) {
return a;
}
final charSpace = " ".codeUnitAt(0);
final charEqual = "=".codeUnitAt(0);
final charSpace = ' '.codeUnitAt(0);
final charEqual = '='.codeUnitAt(0);
final empty = Uint8List(0);
Uint8List unwords(Uint8List b1, Uint8List b2) {
@ -61,7 +61,7 @@ Uint8List unwordsN(List<Uint8List> bs) {
}
final _base64chars = Uint8List.fromList(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
.codeUnits);
List<int?> __base64lookup() {

View File

@ -1,18 +1,18 @@
import "dart:typed_data";
import "buffer.dart";
import 'dart:typed_data';
import 'buffer.dart';
typedef BinaryTags<T> = Map<T, Uint8List>;
int cc(String c) => c.codeUnitAt(0);
final char0 = cc("0");
final char9 = cc("9");
final charLowerA = cc("a");
final charLowerZ = cc("z");
final charUpperA = cc("A");
final charUpperZ = cc("Z");
final charPlus = cc("+");
final charSlash = cc("/");
final char0 = cc('0');
final char9 = cc('9');
final charLowerA = cc('a');
final charLowerZ = cc('z');
final charUpperA = cc('A');
final charUpperZ = cc('Z');
final charPlus = cc('+');
final charSlash = cc('/');
class Parser {
final Uint8List _s;

View File

@ -1,6 +1,6 @@
import "dart:typed_data";
import "buffer.dart";
import "parser.dart";
import 'dart:typed_data';
import 'buffer.dart';
import 'parser.dart';
abstract class SMPCommand {
Uint8List serialize();
@ -10,25 +10,25 @@ abstract class ClientCommand extends SMPCommand {}
abstract class BrokerCommand extends SMPCommand {}
final rsaPrefix = encodeAscii("rsa:");
final rsaPrefix = encodeAscii('rsa:');
Uint8List serializePubKey(Uint8List rcvPubKey) =>
concat(rsaPrefix, encode64(rcvPubKey));
final Uint8List cNEW = encodeAscii("NEW");
final Uint8List cSUB = encodeAscii("SUB");
final Uint8List cKEY = encodeAscii("KEY");
final Uint8List cACK = encodeAscii("ACK");
final Uint8List cOFF = encodeAscii("OFF");
final Uint8List cDEL = encodeAscii("DEL");
final Uint8List cSEND = encodeAscii("SEND");
final Uint8List cPING = encodeAscii("PING");
final Uint8List cIDS = encodeAscii("IDS");
final Uint8List cMSG = encodeAscii("MSG");
final Uint8List cEND = encodeAscii("END");
final Uint8List cOK = encodeAscii("OK");
final Uint8List cERR = encodeAscii("ERR");
final Uint8List cPONG = encodeAscii("PONG");
final Uint8List cNEW = encodeAscii('NEW');
final Uint8List cSUB = encodeAscii('SUB');
final Uint8List cKEY = encodeAscii('KEY');
final Uint8List cACK = encodeAscii('ACK');
final Uint8List cOFF = encodeAscii('OFF');
final Uint8List cDEL = encodeAscii('DEL');
final Uint8List cSEND = encodeAscii('SEND');
final Uint8List cPING = encodeAscii('PING');
final Uint8List cIDS = encodeAscii('IDS');
final Uint8List cMSG = encodeAscii('MSG');
final Uint8List cEND = encodeAscii('END');
final Uint8List cOK = encodeAscii('OK');
final Uint8List cERR = encodeAscii('ERR');
final Uint8List cPONG = encodeAscii('PONG');
enum SMPCmdTag {
NEW,
@ -148,23 +148,23 @@ class OK extends BrokerCommand {
enum ErrorType { BLOCK, CMD, AUTH, QUOTA, NO_MSG, INTERNAL }
final BinaryTags<ErrorType> errorTags = {
ErrorType.BLOCK: encodeAscii("BLOCK"),
ErrorType.CMD: encodeAscii("CMD"),
ErrorType.AUTH: encodeAscii("AUTH"),
ErrorType.QUOTA: encodeAscii("QUOTA"),
ErrorType.NO_MSG: encodeAscii("NO_MSG"),
ErrorType.INTERNAL: encodeAscii("INTERNAL"),
ErrorType.BLOCK: encodeAscii('BLOCK'),
ErrorType.CMD: encodeAscii('CMD'),
ErrorType.AUTH: encodeAscii('AUTH'),
ErrorType.QUOTA: encodeAscii('QUOTA'),
ErrorType.NO_MSG: encodeAscii('NO_MSG'),
ErrorType.INTERNAL: encodeAscii('INTERNAL'),
};
enum CmdErrorType { PROHIBITED, KEY_SIZE, SYNTAX, NO_AUTH, HAS_AUTH, NO_QUEUE }
final BinaryTags<CmdErrorType> cmdErrorTags = {
CmdErrorType.PROHIBITED: encodeAscii("PROHIBITED"),
CmdErrorType.KEY_SIZE: encodeAscii("KEY_SIZE"),
CmdErrorType.SYNTAX: encodeAscii("SYNTAX"),
CmdErrorType.NO_AUTH: encodeAscii("NO_AUTH"),
CmdErrorType.HAS_AUTH: encodeAscii("HAS_AUTH"),
CmdErrorType.NO_QUEUE: encodeAscii("NO_QUEUE"),
CmdErrorType.PROHIBITED: encodeAscii('PROHIBITED'),
CmdErrorType.KEY_SIZE: encodeAscii('KEY_SIZE'),
CmdErrorType.SYNTAX: encodeAscii('SYNTAX'),
CmdErrorType.NO_AUTH: encodeAscii('NO_AUTH'),
CmdErrorType.HAS_AUTH: encodeAscii('HAS_AUTH'),
CmdErrorType.NO_QUEUE: encodeAscii('NO_QUEUE'),
};
class ERR extends BrokerCommand {
@ -172,7 +172,7 @@ class ERR extends BrokerCommand {
final CmdErrorType? cmdErr;
ERR(this.err)
: cmdErr = err == ErrorType.CMD
? throw ArgumentError("CMD error should be created with ERR.CMD")
? throw ArgumentError('CMD error should be created with ERR.CMD')
: null;
ERR.cmd(this.cmdErr) : err = ErrorType.CMD;
@override

View File

@ -1,5 +1,5 @@
import "dart:async";
import "dart:typed_data";
import 'dart:async';
import 'dart:typed_data';
abstract class Transport {
Future<Uint8List> read(int n);

View File

@ -1,6 +1,6 @@
import "dart:typed_data";
import "package:simplexmq/src/buffer.dart";
import "package:test/test.dart";
import 'dart:typed_data';
import 'package:simplexmq/src/buffer.dart';
import 'package:test/test.dart';
final hello123 = Uint8List.fromList([104, 101, 108, 108, 111, 49, 50, 51]);
@ -14,17 +14,17 @@ class Base64Test {
}
void main() {
group("ascii encoding/decoding", () {
test("encodeAscii", () {
expect(encodeAscii("hello123"), hello123);
group('ascii encoding/decoding', () {
test('encodeAscii', () {
expect(encodeAscii('hello123'), hello123);
});
test("decodeAscii", () {
expect(decodeAscii(hello123), "hello123");
test('decodeAscii', () {
expect(decodeAscii(hello123), 'hello123');
});
});
group("base-64 encoding/decoding", () {
group('base-64 encoding/decoding', () {
String allBinaryChars() {
final a = Uint8List(256);
for (var i = 0; i < 256; i++) {
@ -34,33 +34,33 @@ void main() {
}
final base64tests = [
Base64Test("\x12\x34\x56\x78", "EjRWeA=="),
Base64Test("hello123", "aGVsbG8xMjM="),
Base64Test("Hello world", "SGVsbG8gd29ybGQ="),
Base64Test("Hello worlds!", "SGVsbG8gd29ybGRzIQ=="),
Base64Test("May", "TWF5"),
Base64Test("Ma", "TWE="),
Base64Test("M", "TQ=="),
Base64Test('\x12\x34\x56\x78', 'EjRWeA=='),
Base64Test('hello123', 'aGVsbG8xMjM='),
Base64Test('Hello world', 'SGVsbG8gd29ybGQ='),
Base64Test('Hello worlds!', 'SGVsbG8gd29ybGRzIQ=='),
Base64Test('May', 'TWF5'),
Base64Test('Ma', 'TWE='),
Base64Test('M', 'TQ=='),
Base64Test.withDescription(
"all binary chars",
'all binary chars',
allBinaryChars(),
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==",
'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==',
),
];
test("encode64", () {
test('encode64', () {
for (final t in base64tests) {
expect(encode64(encodeAscii(t.binary)), encodeAscii(t.base64));
}
});
test("decode64", () {
test('decode64', () {
for (final t in base64tests) {
expect(decode64(encodeAscii(t.base64)), encodeAscii(t.binary));
}
expect(decode64(encodeAscii("TWE")), null);
expect(decode64(encodeAscii("TWE==")), null);
expect(decode64(encodeAscii("TW!=")), null);
expect(decode64(encodeAscii('TWE')), null);
expect(decode64(encodeAscii('TWE==')), null);
expect(decode64(encodeAscii('TW!=')), null);
});
});
}

View File

@ -1,11 +1,11 @@
import "dart:typed_data";
import "package:simplexmq/src/buffer.dart";
import "package:simplexmq/src/protocol.dart";
import "package:test/test.dart";
import 'dart:typed_data';
import 'package:simplexmq/src/buffer.dart';
import 'package:simplexmq/src/protocol.dart';
import 'package:test/test.dart';
void main() {
group("Parsing & serializing SMP commands", () {
group("valid commands", () {
group('Parsing & serializing SMP commands', () {
group('valid commands', () {
Null Function() parseSerialize(SMPCommand cmd) => () {
final s = cmd.serialize();
expect(parseSMPCommand(s)?.serialize(), s);
@ -13,92 +13,92 @@ void main() {
null);
};
test("NEW", parseSerialize(NEW(encodeAscii("rsa:1234"))));
test("SUB", parseSerialize(SUB()));
test("KEY", parseSerialize(KEY(encodeAscii("rsa:1234"))));
test("ACK", parseSerialize(ACK()));
test("OFF", parseSerialize(OFF()));
test("DEL", parseSerialize(DEL()));
test("SEND", parseSerialize(SEND(encodeAscii("hello"))));
test("PING", parseSerialize(PING()));
test("IDS", parseSerialize(IDS(encodeAscii("abc"), encodeAscii("def"))));
test('NEW', parseSerialize(NEW(encodeAscii('rsa:1234'))));
test('SUB', parseSerialize(SUB()));
test('KEY', parseSerialize(KEY(encodeAscii('rsa:1234'))));
test('ACK', parseSerialize(ACK()));
test('OFF', parseSerialize(OFF()));
test('DEL', parseSerialize(DEL()));
test('SEND', parseSerialize(SEND(encodeAscii('hello'))));
test('PING', parseSerialize(PING()));
test('IDS', parseSerialize(IDS(encodeAscii('abc'), encodeAscii('def'))));
test(
"MSG",
parseSerialize(MSG(encodeAscii("fgh"), DateTime.now().toUtc(),
encodeAscii("hello"))));
test("END", parseSerialize(END()));
test("OK", parseSerialize(OK()));
test("ERR", parseSerialize(ERR(ErrorType.AUTH)));
test("ERR CMD", parseSerialize(ERR.cmd(CmdErrorType.SYNTAX)));
test("PONG", parseSerialize(PONG()));
'MSG',
parseSerialize(MSG(encodeAscii('fgh'), DateTime.now().toUtc(),
encodeAscii('hello'))));
test('END', parseSerialize(END()));
test('OK', parseSerialize(OK()));
test('ERR', parseSerialize(ERR(ErrorType.AUTH)));
test('ERR CMD', parseSerialize(ERR.cmd(CmdErrorType.SYNTAX)));
test('PONG', parseSerialize(PONG()));
});
group("invalid commands", () {
group('invalid commands', () {
void Function() parseFailure(String s) =>
() => expect(parseSMPCommand(encodeAscii(s)), null);
void Function() parseSuccess(String s) =>
() => expect(parseSMPCommand(encodeAscii(s)) is SMPCommand, true);
group("NEW", () {
test("ok", parseSuccess("NEW rsa:abcd"));
test("no key", parseFailure("NEW"));
test("invalid base64", parseFailure("NEW rsa:abc"));
test("double space", parseFailure("NEW rsa:abcd"));
group('NEW', () {
test('ok', parseSuccess('NEW rsa:abcd'));
test('no key', parseFailure('NEW'));
test('invalid base64', parseFailure('NEW rsa:abc'));
test('double space', parseFailure('NEW rsa:abcd'));
});
group("KEY", () {
test("ok", parseSuccess("KEY rsa:abcd"));
test("no key", parseFailure("KEY"));
test("invalid base64", parseFailure("KEY rsa:abc"));
test("double space", parseFailure("KEY rsa:abcd"));
group('KEY', () {
test('ok', parseSuccess('KEY rsa:abcd'));
test('no key', parseFailure('KEY'));
test('invalid base64', parseFailure('KEY rsa:abc'));
test('double space', parseFailure('KEY rsa:abcd'));
});
group("SEND", () {
test("ok", parseSuccess("SEND 5 hello "));
test("no size", parseFailure("SEND hello "));
test("incorrect size", parseFailure("SEND 6 hello "));
test("no trailing space", parseFailure("SEND 5 hello"));
test("double space 1", parseFailure("SEND 5 hello "));
test("double space 2", parseFailure("SEND 5 hello "));
group('SEND', () {
test('ok', parseSuccess('SEND 5 hello '));
test('no size', parseFailure('SEND hello '));
test('incorrect size', parseFailure('SEND 6 hello '));
test('no trailing space', parseFailure('SEND 5 hello'));
test('double space 1', parseFailure('SEND 5 hello '));
test('double space 2', parseFailure('SEND 5 hello '));
});
group("IDS", () {
test("ok", parseSuccess("IDS abcd efgh"));
test("no IDs", parseFailure("IDS"));
test("only one ID", parseFailure("IDS abcd"));
test("invalid base64 1", parseFailure("IDS abc efgh"));
test("invalid base64 2", parseFailure("IDS abcd efg"));
test("double space 1", parseFailure("IDS abcd efgh"));
test("double space 2", parseFailure("IDS abcd efgh"));
group('IDS', () {
test('ok', parseSuccess('IDS abcd efgh'));
test('no IDs', parseFailure('IDS'));
test('only one ID', parseFailure('IDS abcd'));
test('invalid base64 1', parseFailure('IDS abc efgh'));
test('invalid base64 2', parseFailure('IDS abcd efg'));
test('double space 1', parseFailure('IDS abcd efgh'));
test('double space 2', parseFailure('IDS abcd efgh'));
});
group("MSG", () {
final String ts = "2021-10-03T10:50:59.895Z";
test("ok", parseSuccess("MSG abcd $ts 5 hello "));
test("invalid base64", parseFailure("MSG abc $ts 5 hello "));
test("invalid timestamp 1",
parseFailure("MSG abc 2021-10-03T10:50:59.895 5 hello "));
test("invalid timestamp 2",
parseFailure("MSG abc 2021-14-03T10:50:59.895Z 5 hello "));
test("no size", parseFailure("MSG abcd $ts hello "));
test("incorrect size", parseFailure("MSG abcd $ts 6 hello "));
test("no trailing space", parseFailure("MSG abcd $ts 5 hello"));
test("double space 1", parseFailure("MSG abcd $ts 5 hello "));
test("double space 2", parseFailure("MSG abcd $ts 5 hello "));
test("double space 3", parseFailure("MSG abcd $ts 5 hello "));
test("double space 4", parseFailure("MSG abcd $ts 5 hello "));
group('MSG', () {
final String ts = '2021-10-03T10:50:59.895Z';
test('ok', parseSuccess('MSG abcd $ts 5 hello '));
test('invalid base64', parseFailure('MSG abc $ts 5 hello '));
test('invalid timestamp 1',
parseFailure('MSG abc 2021-10-03T10:50:59.895 5 hello '));
test('invalid timestamp 2',
parseFailure('MSG abc 2021-14-03T10:50:59.895Z 5 hello '));
test('no size', parseFailure('MSG abcd $ts hello '));
test('incorrect size', parseFailure('MSG abcd $ts 6 hello '));
test('no trailing space', parseFailure('MSG abcd $ts 5 hello'));
test('double space 1', parseFailure('MSG abcd $ts 5 hello '));
test('double space 2', parseFailure('MSG abcd $ts 5 hello '));
test('double space 3', parseFailure('MSG abcd $ts 5 hello '));
test('double space 4', parseFailure('MSG abcd $ts 5 hello '));
});
group("ERR", () {
test("ok 1", parseSuccess("ERR AUTH"));
test("ok 2", parseSuccess("ERR CMD SYNTAX"));
test("unknown error", parseFailure("ERR HELLO"));
test("unknown CMD error", parseFailure("ERR CMD HELLO"));
test("bad sub-error", parseFailure("ERR AUTH SYNTAX"));
test("double space 1", parseFailure("ERR AUTH"));
test("double space 2", parseFailure("ERR CMD SYNTAX"));
test("double space 3", parseFailure("ERR CMD SYNTAX"));
group('ERR', () {
test('ok 1', parseSuccess('ERR AUTH'));
test('ok 2', parseSuccess('ERR CMD SYNTAX'));
test('unknown error', parseFailure('ERR HELLO'));
test('unknown CMD error', parseFailure('ERR CMD HELLO'));
test('bad sub-error', parseFailure('ERR AUTH SYNTAX'));
test('double space 1', parseFailure('ERR AUTH'));
test('double space 2', parseFailure('ERR CMD SYNTAX'));
test('double space 3', parseFailure('ERR CMD SYNTAX'));
});
});
});

View File

@ -1,3 +1,3 @@
library simplexmq_io;
export "src/socket.dart";
export 'src/socket.dart';

View File

@ -1,9 +1,9 @@
import "dart:async";
import "dart:collection";
import "dart:io";
import "dart:typed_data";
import 'dart:async';
import 'dart:collection';
import 'dart:io';
import 'dart:typed_data';
import "package:simplexmq/simplexmq.dart";
import 'package:simplexmq/simplexmq.dart';
class _STReaders {
final Completer<Uint8List> completer = Completer();
@ -76,7 +76,7 @@ class SocketTransport implements Transport {
_socket.destroy();
while (_readers.isNotEmpty) {
final r = _readers.removeFirst();
r.completer.completeError(Exception("socket closed"));
r.completer.completeError(Exception('socket closed'));
}
}