blob: 4ae286fa5fa7af0d8c93a7e4aa31f81e2ed06b43 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion HeaderValue parse(
/// String value, {
/// String parameterSeparator: ";",
/// String valueSeparator: null,
/// bool preserveBackslash: false
/// })
/// Creates a new header value object from parsing a header value string with
/// both value and optional parameters.
/// @description Checks that this method parses header value
/// @author sgrekhov@unipro.ru
import "dart:io";
import "../../../Utils/expect.dart";
main() {
String toParse = "value1; param1=val1; param2=val2";
HeaderValue parsed = HeaderValue.parse(toParse);
Expect.equals("value1", parsed.value);
Expect.mapEquals({"param1": "val1", "param2": "val2"}, parsed.parameters);
toParse = "";
parsed = HeaderValue.parse(toParse);
Expect.equals("", parsed.value);
Expect.mapEquals({}, parsed.parameters);
toParse = ";";
parsed = HeaderValue.parse(toParse);
Expect.equals("", parsed.value);
Expect.mapEquals({}, parsed.parameters);
toParse = ";;";
parsed = HeaderValue.parse(toParse);
Expect.equals("", parsed.value);
Expect.mapEquals({}, parsed.parameters);
toParse = "some string";
parsed = HeaderValue.parse(toParse);
Expect.equals("some", parsed.value);
Expect.mapEquals({"string": null}, parsed.parameters);
toParse = ";param1;";
parsed = HeaderValue.parse(toParse);
Expect.equals("", parsed.value);
Expect.mapEquals({"param1": null}, parsed.parameters);
toParse = ";param1=;";
parsed = HeaderValue.parse(toParse);
Expect.equals("", parsed.value);
Expect.mapEquals({"param1": ""}, parsed.parameters);
toParse = ';param1="a';
Expect.throws(() {HeaderValue.parse(toParse);});
}