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: linter:
rules: rules:
prefer_double_quotes: true prefer_single_quotes: true
constant_identifier_names: false constant_identifier_names: false
always_declare_return_types: true always_declare_return_types: true
avoid_dynamic_calls: true avoid_dynamic_calls: true

View File

@ -3,5 +3,5 @@
/// More dartdocs go here. /// More dartdocs go here.
library simplexmq; library simplexmq;
export "src/protocol.dart"; export 'src/protocol.dart';
export "src/transport.dart" show Transport; 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); Uint8List encodeAscii(String s) => Uint8List.fromList(s.codeUnits);
@ -29,8 +29,8 @@ Uint8List concatN(List<Uint8List> bs) {
return a; return a;
} }
final charSpace = " ".codeUnitAt(0); final charSpace = ' '.codeUnitAt(0);
final charEqual = "=".codeUnitAt(0); final charEqual = '='.codeUnitAt(0);
final empty = Uint8List(0); final empty = Uint8List(0);
Uint8List unwords(Uint8List b1, Uint8List b2) { Uint8List unwords(Uint8List b1, Uint8List b2) {
@ -61,7 +61,7 @@ Uint8List unwordsN(List<Uint8List> bs) {
} }
final _base64chars = Uint8List.fromList( final _base64chars = Uint8List.fromList(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
.codeUnits); .codeUnits);
List<int?> __base64lookup() { List<int?> __base64lookup() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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