Chromium Code Reviews| Index: test/backend/metadata_test.dart |
| diff --git a/test/backend/metadata_test.dart b/test/backend/metadata_test.dart |
| index ab14a74bde550a52a9b895f5b73e4085b75c0a37..799fac228f5c83756f840af1d440edaf1efccf34 100644 |
| --- a/test/backend/metadata_test.dart |
| +++ b/test/backend/metadata_test.dart |
| @@ -9,6 +9,106 @@ import 'package:test/src/frontend/skip.dart'; |
| import 'package:test/test.dart'; |
| void main() { |
| + group("Metadata", () { |
| + void expectTags(tags, expected) { |
| + expect(new Metadata.parse(tags: tags).tags, unorderedEquals(expected)); |
| + |
| + if (tags == null || tags is Iterable) { |
| + expect(new Metadata(tags: tags).tags, unorderedEquals(expected)); |
| + } |
| + |
| + if (tags is Iterable) { |
| + var serialized = { |
| + "tags": tags, |
| + "timeout": "none", |
| + "onPlatform": [], |
| + }; |
| + expect(new Metadata.deserialize(serialized).tags, |
| + unorderedEquals(expected)); |
|
nweiz
2015/11/16 21:59:44
I don't think we should explicitly test the serial
yjbanov
2015/11/26 06:30:27
Done.
|
| + } |
| + } |
| + |
| + void expectArgumentError(ArgumentError error, tags, String message) { |
|
nweiz
2015/11/16 21:59:44
We usually don't test argument errors' values in t
yjbanov
2015/11/26 06:30:27
Done.
|
| + expect(error.message, message); |
| + expect(error.invalidValue, tags); |
| + expect(error.name, "tags"); |
| + } |
| + |
| + void expectTagsError({tags, String message}) { |
| + [ |
| + () => new Metadata(tags: tags), |
| + () => new Metadata.parse(tags: tags), |
| + ].forEach((fn()) { |
| + try { |
| + fn(); |
| + fail("Expected ArgumentError for $tags"); |
| + } on ArgumentError catch(e) { |
|
nweiz
2015/11/16 21:59:44
Use the throwsArgumentError matcher here.
yjbanov
2015/11/26 06:30:27
Done.
|
| + expectArgumentError(e, tags, message); |
| + } |
| + }); |
| + } |
| + |
| + test("takes no tags", () { |
| + expectTags(null, []); |
| + expectTags("", []); |
| + expectTags(" ", []); |
| + expectTags([], []); |
| + }); |
| + |
| + test("takes some tags as Iterable", () { |
| + var tags = ["a", "b"]; |
| + expectTags(tags, tags); |
| + expectTags(new Set.from(tags), tags); |
| + }); |
| + |
| + test("takes some tags as String", () { |
| + expectTags("a", ["a"]); |
| + expectTags("a,b", ["a", "b"]); |
| + expectTags(" a,,,b , c\n,d\t", ["a", "b", "c", "d"]); |
| + }); |
| + |
| + test("parse refuses bad tag types", () { |
| + try { |
| + new Metadata.parse(tags: 1); |
| + fail("Expected ArgumentError for 1"); |
| + } on ArgumentError catch(e) { |
| + expectArgumentError(e, 1, |
| + "must be either String or Iterable"); |
| + } |
| + }); |
| + |
| + test("refuses non-String tag names", () { |
| + expectTagsError( |
| + tags: [1], |
| + message: "tag name must be String"); |
| + expectTagsError( |
| + tags: [null], |
| + message: "tag name must be String"); |
| + }); |
| + |
| + test("refuses blank tag names", () { |
| + var errorMsg = "tag name must contain non-whitespace characters"; |
| + expectTagsError( |
| + tags: [""], |
| + message: errorMsg); |
| + expectTagsError( |
| + tags: [" "], |
| + message: errorMsg); |
| + }); |
| + |
| + test("merges tags by computing the union of the two tag sets", () { |
| + var merged = new Metadata(tags: ["a", "b"]) |
| + .merge(new Metadata(tags: ["b", "c"])); |
| + expect(merged.tags, unorderedEquals(["a", "b", "c"])); |
| + }); |
| + |
| + test("serializes tags to a List", () { |
| + var serialized = new Metadata(tags: ["a", "b"]).serialize()['tags']; |
| + expect(serialized, new isInstanceOf<List>()); |
| + expect(serialized, ["a", "b"]); |
| + }); |
| + }); |
| + |
| group("onPlatform", () { |
| test("parses a valid map", () { |
| var metadata = new Metadata.parse(onPlatform: { |