Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: test/db/properties_test.dart

Issue 774213002: Bugfix in ListProperty(), correctly handle list values of length 1 (Closed) Base URL: git@github.com:dart-lang/gcloud.git@master
Patch Set: Added entry in CHANGELOG.md Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/db/annotations.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/db/properties_test.dart
diff --git a/test/db/properties_test.dart b/test/db/properties_test.dart
index f20c25090cb4f657fdca5505a64dcfdf8684a33e..d0ae074f61baeb1432746d1a9498845b1f33c5b0 100644
--- a/test/db/properties_test.dart
+++ b/test/db/properties_test.dart
@@ -111,6 +111,7 @@ main() {
expect(prop.validate(null, null), isFalse);
expect(prop.validate(null, []), isTrue);
+ expect(prop.validate(null, [true]), isTrue);
expect(prop.validate(null, [true, false]), isTrue);
expect(prop.validate(null, [true, false, 1]), isFalse);
expect(prop.encodeValue(null, []), equals(null));
@@ -123,6 +124,28 @@ main() {
equals([true, false]));
});
+ test('composed_list_property', () {
+ var prop = const ListProperty(const CustomProperty());
+
+ var c1 = new Custom()..customValue = 'c1';
+ var c2 = new Custom()..customValue = 'c2';
+
+ expect(prop.validate(null, null), isFalse);
+ expect(prop.validate(null, []), isTrue);
+ expect(prop.validate(null, [c1]), isTrue);
+ expect(prop.validate(null, [c1, c2]), isTrue);
+ expect(prop.validate(null, [c1, c2, 1]), isFalse);
+ expect(prop.encodeValue(null, []), equals(null));
+ expect(prop.encodeValue(null, [c1]), equals(c1.customValue));
+ expect(prop.encodeValue(null, [c1, c2]),
+ equals([c1.customValue, c2.customValue]));
+ expect(prop.decodePrimitiveValue(null, null), equals([]));
+ expect(prop.decodePrimitiveValue(null, []), equals([]));
+ expect(prop.decodePrimitiveValue(null, c1.customValue), equals([c1]));
+ expect(prop.decodePrimitiveValue(null, [c1.customValue, c2.customValue]),
+ equals([c1, c2]));
+ });
+
test('modelkey_property', () {
var datastoreKey = new datastore.Key(
[new datastore.KeyElement('MyKind', 42)],
@@ -146,6 +169,36 @@ main() {
});
}
+class Custom {
+ String customValue;
+
+ int get hashCode => customValue.hashCode;
+
+ bool operator==(other) {
+ return other is Custom && other.customValue == customValue;
+ }
+}
+
+class CustomProperty extends StringProperty {
+ const CustomProperty(
+ {String propertyName: null, bool required: false, bool indexed: true});
+
+ bool validate(ModelDB db, Object value) {
+ if (required && value == null) return false;
+ return value == null || value is Custom;
+ }
+
+ Object decodePrimitiveValue(ModelDB db, Object value) {
+ if (value == null) return null;
+ return new Custom()..customValue = value;
+ }
+
+ Object encodeValue(ModelDB db, Object value) {
+ if (value == null) return null;
+ return (value as Custom).customValue;
+ }
+}
+
class KeyMock implements Key {
datastore.Key _datastoreKey;
« no previous file with comments | « lib/src/db/annotations.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698