Skip to content

Commit

Permalink
Remove upper case constants (dart-lang#99)
Browse files Browse the repository at this point in the history
Remove usage of upper-case constants.

Update SDK version
Remove stable from travis config.
  • Loading branch information
lrhn authored May 4, 2018
1 parent 69101bb commit 6fe378b
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 29 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: dart

dart:
- dev
- stable

dart_task:
- test: --platform vm
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ abstract class Message {
/// This calls [read] internally, which can only be called once.
Future<String> readAsString([Encoding encoding]) {
if (encoding == null) encoding = this.encoding;
if (encoding == null) encoding = UTF8;
if (encoding == null) encoding = utf8;
return encoding.decodeStream(read());
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: shelf
version: 0.7.3
version: 0.7.3+1
author: Dart Team <[email protected]>
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'
Expand Down
2 changes: 1 addition & 1 deletion test/io_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion test/message_change_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 9 additions & 9 deletions test/message_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void main() {
body: new Stream.fromIterable([
[195, 168]
]));
expect(request.readAsString(LATIN1), completion(equals("è")));
expect(request.readAsString(latin1), completion(equals("è")));
});
});

Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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",
Expand All @@ -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", () {
Expand All @@ -289,31 +289,31 @@ 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]
])));
});

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'));
});

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'));
});

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(
Expand All @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion test/response_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'});

Expand Down
6 changes: 3 additions & 3 deletions test/server_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down
12 changes: 6 additions & 6 deletions test/shelf_io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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', () {
Expand Down Expand Up @@ -435,15 +435,15 @@ 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});
});

var request =
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, "));
Expand Down Expand Up @@ -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 {
Expand All @@ -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 /');
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/ssl_certs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dart:convert';

List<int> certChainBytes = UTF8.encode("""
List<int> certChainBytes = utf8.encode("""
-----BEGIN CERTIFICATE-----
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVpbnRl
cm1lZGlhdGVhdXRob3JpdHkwHhcNMTUxMDI3MTAyNjM1WhcNMjUxMDI0MTAyNjM1
Expand Down Expand Up @@ -66,7 +66,7 @@ hGiCpWlwziW2xLV1l2qSRLko2kIafLZP18N0ThM9zKbU5ps9NgFOf//wqSGtLaE=
-----END CERTIFICATE-----
""");

List<int> certKeyBytes = UTF8.encode("""
List<int> certKeyBytes = utf8.encode("""
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIE4zAcBgoqhkiG9w0BDAEBMA4ECBMCjlg8JYZ4AgIIAASCBMFd9cBoZ5xcTock
AVQcg/HzYJtMceKn1gtMDdC7mmXuyN0shoxhG4BpQInHkFARL+nenesXFxEm4X5e
Expand Down

0 comments on commit 6fe378b

Please sign in to comment.