From 6fe378bcae650347a686f5b44cf124eefe1de627 Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Fri, 4 May 2018 12:16:44 +0200 Subject: [PATCH] Remove upper case constants (#99) Remove usage of upper-case constants. Update SDK version Remove stable from travis config. --- .travis.yml | 1 - CHANGELOG.md | 4 ++++ lib/src/body.dart | 4 ++-- lib/src/message.dart | 2 +- pubspec.yaml | 4 ++-- test/io_server_test.dart | 2 +- test/message_change_test.dart | 2 +- test/message_test.dart | 18 +++++++++--------- test/response_test.dart | 2 +- test/server_handler_test.dart | 6 +++--- test/shelf_io_test.dart | 12 ++++++------ test/ssl_certs.dart | 4 ++-- 12 files changed, 32 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 004ef375..4e8126de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: dart dart: - dev - - stable dart_task: - test: --platform vm diff --git a/CHANGELOG.md b/CHANGELOG.md index 74928dae..c2263960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.7.3+1 + +* Updated SDK version to 2.0.0-dev.17.0. + ## 0.7.3 * Fix some Dart 2 runtime errors. diff --git a/lib/src/body.dart b/lib/src/body.dart index 77c3d1b9..a91ed736 100644 --- a/lib/src/body.dart +++ b/lib/src/body.dart @@ -44,10 +44,10 @@ class Body { stream = new Stream.fromIterable([]); } else if (body is String) { if (encoding == null) { - var encoded = UTF8.encode(body); + var encoded = utf8.encode(body); // If the text is plain ASCII, don't modify the encoding. This means // that an encoding of "text/plain" will stay put. - if (!_isPlainAscii(encoded, body.length)) encoding = UTF8; + if (!_isPlainAscii(encoded, body.length)) encoding = utf8; contentLength = encoded.length; stream = new Stream.fromIterable([encoded]); } else { diff --git a/lib/src/message.dart b/lib/src/message.dart index 22651200..7a55ef51 100644 --- a/lib/src/message.dart +++ b/lib/src/message.dart @@ -140,7 +140,7 @@ abstract class Message { /// This calls [read] internally, which can only be called once. Future readAsString([Encoding encoding]) { if (encoding == null) encoding = this.encoding; - if (encoding == null) encoding = UTF8; + if (encoding == null) encoding = utf8; return encoding.decodeStream(read()); } diff --git a/pubspec.yaml b/pubspec.yaml index d65e6bce..315579fe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: shelf -version: 0.7.3 +version: 0.7.3+1 author: Dart Team description: Web Server Middleware for Dart homepage: https://github.com/dart-lang/shelf environment: - sdk: '>=1.24.0 <2.0.0' + sdk: '>=2.0.0-dev.17.0 <2.0.0' dependencies: async: '>=1.10.0 <3.0.0' collection: '^1.5.0' diff --git a/test/io_server_test.dart b/test/io_server_test.dart index f29e31bb..79058611 100644 --- a/test/io_server_test.dart +++ b/test/io_server_test.dart @@ -33,7 +33,7 @@ void main() { test("delays HTTP requests until a handler is mounted", () async { expect(http.read(server.url), completion(equals('Hello from /'))); - await new Future.delayed(Duration.ZERO); + await new Future.delayed(Duration.zero); server.mount(asyncHandler); }); diff --git a/test/message_change_test.dart b/test/message_change_test.dart index e3c5b766..cea323e6 100644 --- a/test/message_change_test.dart +++ b/test/message_change_test.dart @@ -46,7 +46,7 @@ void _testChange( var request = factory(body: 'Hello, world'); var copy = request.change( body: new Stream.fromIterable(['Goodbye, world']) - .transform(UTF8.encoder)); + .transform(utf8.encoder)); var newBody = await copy.readAsString(); diff --git a/test/message_test.dart b/test/message_test.dart index 86a7a798..62cff274 100644 --- a/test/message_test.dart +++ b/test/message_test.dart @@ -116,7 +116,7 @@ void main() { body: new Stream.fromIterable([ [195, 168] ])); - expect(request.readAsString(LATIN1), completion(equals("è"))); + expect(request.readAsString(latin1), completion(equals("è"))); }); }); @@ -186,7 +186,7 @@ void main() { var request = _createMessage(body: 'fööbär'); expect(request.contentLength, 9); - request = _createMessage(body: 'fööbär', encoding: LATIN1); + request = _createMessage(body: 'fööbär', encoding: latin1); expect(request.contentLength, 6); }); @@ -267,7 +267,7 @@ void main() { _createMessage( headers: {'content-type': 'text/plain; charset=iso-8859-1'}) .encoding, - equals(LATIN1)); + equals(latin1)); }); test("comes from the content-type charset parameter with a different case", @@ -276,7 +276,7 @@ void main() { _createMessage( headers: {'Content-Type': 'text/plain; charset=iso-8859-1'}) .encoding, - equals(LATIN1)); + equals(latin1)); }); test("defaults to encoding a String as UTF-8", () { @@ -289,7 +289,7 @@ void main() { test("uses the explicit encoding if available", () { expect( - _createMessage(body: "è", encoding: LATIN1).read().toList(), + _createMessage(body: "è", encoding: latin1).read().toList(), completion(equals([ [232] ]))); @@ -297,7 +297,7 @@ void main() { test("adds an explicit encoding to the content-type", () { var request = _createMessage( - body: "è", encoding: LATIN1, headers: {'content-type': 'text/plain'}); + body: "è", encoding: latin1, headers: {'content-type': 'text/plain'}); expect(request.headers, containsPair('content-type', 'text/plain; charset=iso-8859-1')); }); @@ -305,7 +305,7 @@ void main() { test("adds an explicit encoding to the content-type with a different case", () { var request = _createMessage( - body: "è", encoding: LATIN1, headers: {'Content-Type': 'text/plain'}); + body: "è", encoding: latin1, headers: {'Content-Type': 'text/plain'}); expect(request.headers, containsPair('Content-Type', 'text/plain; charset=iso-8859-1')); }); @@ -313,7 +313,7 @@ void main() { test( "sets an absent content-type to application/octet-stream in order to " "set the charset", () { - var request = _createMessage(body: "è", encoding: LATIN1); + var request = _createMessage(body: "è", encoding: latin1); expect( request.headers, containsPair( @@ -323,7 +323,7 @@ void main() { test("overwrites an existing charset if given an explicit encoding", () { var request = _createMessage( body: "è", - encoding: LATIN1, + encoding: latin1, headers: {'content-type': 'text/plain; charset=whatever'}); expect(request.headers, containsPair('content-type', 'text/plain; charset=iso-8859-1')); diff --git a/test/response_test.dart b/test/response_test.dart index f236f0eb..c5e2de55 100644 --- a/test/response_test.dart +++ b/test/response_test.dart @@ -91,7 +91,7 @@ void main() { var request = new Response(345, body: 'hèllo, world', - encoding: LATIN1, + encoding: latin1, headers: {'header1': 'header value 1'}, context: {'context1': 'context value 1'}); diff --git a/test/server_handler_test.dart b/test/server_handler_test.dart index a98dd757..521a5266 100644 --- a/test/server_handler_test.dart +++ b/test/server_handler_test.dart @@ -29,7 +29,7 @@ void main() { () async { var serverHandler = new ServerHandler(localhostUri); var future = makeSimpleRequest(serverHandler.handler); - await new Future.delayed(Duration.ZERO); + await new Future.delayed(Duration.zero); serverHandler.server.mount(syncHandler); var response = await future; @@ -58,11 +58,11 @@ void main() { closeDone = true; }); expect(onCloseCalled, isTrue); - await new Future.delayed(Duration.ZERO); + await new Future.delayed(Duration.zero); expect(closeDone, isFalse); completer.complete(); - await new Future.delayed(Duration.ZERO); + await new Future.delayed(Duration.zero); expect(closeDone, isTrue); }); diff --git a/test/shelf_io_test.dart b/test/shelf_io_test.dart index 414a3f3d..894c06e0 100644 --- a/test/shelf_io_test.dart +++ b/test/shelf_io_test.dart @@ -186,7 +186,7 @@ void main() { test('post with request content', () async { await _scheduleServer((request) async { expect(request.mimeType, 'text/plain'); - expect(request.encoding, UTF8); + expect(request.encoding, utf8); expect(request.method, 'POST'); expect(request.contentLength, 9); @@ -280,7 +280,7 @@ void main() { } expect( - await UTF8.decodeStream(socket), contains('500 Internal Server Error')); + await utf8.decodeStream(socket), contains('500 Internal Server Error')); }); group('date header', () { @@ -435,7 +435,7 @@ void main() { await _scheduleServer((request) { controller.add("Hello, "); - return new Response.ok(UTF8.encoder.bind(controller.stream), + return new Response.ok(utf8.encoder.bind(controller.stream), context: {"shelf.io.buffer_output": false}); }); @@ -443,7 +443,7 @@ void main() { new http.Request("GET", Uri.parse('http://localhost:$_serverPort/')); var response = await request.send(); - var stream = new StreamQueue(UTF8.decoder.bind(response.stream)); + var stream = new StreamQueue(utf8.decoder.bind(response.stream)); var data = await stream.next; expect(data, equals("Hello, ")); @@ -492,7 +492,7 @@ void main() { var response = await req.close(); expect(response.statusCode, HttpStatus.OK); - expect(await response.transform(UTF8.decoder).single, 'Hello from /'); + expect(await response.transform(utf8.decoder).single, 'Hello from /'); }); test('secure async handler returns a value to the client', () async { @@ -501,7 +501,7 @@ void main() { var req = await _scheduleSecureGet(); var response = await req.close(); expect(response.statusCode, HttpStatus.OK); - expect(await response.transform(UTF8.decoder).single, 'Hello from /'); + expect(await response.transform(utf8.decoder).single, 'Hello from /'); }); }); } diff --git a/test/ssl_certs.dart b/test/ssl_certs.dart index 47a25068..be86de3d 100644 --- a/test/ssl_certs.dart +++ b/test/ssl_certs.dart @@ -4,7 +4,7 @@ import 'dart:convert'; -List certChainBytes = UTF8.encode(""" +List certChainBytes = utf8.encode(""" -----BEGIN CERTIFICATE----- MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl cm1lZGlhdGVhdXRob3JpdHkwHhcNMTUxMDI3MTAyNjM1WhcNMjUxMDI0MTAyNjM1 @@ -66,7 +66,7 @@ hGiCpWlwziW2xLV1l2qSRLko2kIafLZP18N0ThM9zKbU5ps9NgFOf//wqSGtLaE= -----END CERTIFICATE----- """); -List certKeyBytes = UTF8.encode(""" +List certKeyBytes = utf8.encode(""" -----BEGIN ENCRYPTED PRIVATE KEY----- MIIE4zAcBgoqhkiG9w0BDAEBMA4ECBMCjlg8JYZ4AgIIAASCBMFd9cBoZ5xcTock AVQcg/HzYJtMceKn1gtMDdC7mmXuyN0shoxhG4BpQInHkFARL+nenesXFxEm4X5e