[fidl][dart] Bits support: add $none, and & operator
Change-Id: I4fcf830ca102b51b9853eb9c2601f0b49577407b
diff --git a/bin/fidl_bindings_test/test/test/oneway_test.dart b/bin/fidl_bindings_test/test/test/oneway_test.dart
index 13c1dea..e23a69d 100644
--- a/bin/fidl_bindings_test/test/test/oneway_test.dart
+++ b/bin/fidl_bindings_test/test/test/oneway_test.dart
@@ -118,5 +118,12 @@
expect(received, equals(
ExampleBits.memberB | ExampleBits.memberC));
});
+
+ test('bits with no bit set', () async {
+ await server.proxy.oneWayExampleBits(ExampleBits.$none);
+ final received = await server.proxy.receivedOneWayExampleBits();
+ expect(received, equals(
+ ExampleBits.memberB & ExampleBits.memberA /* 0 too */));
+ });
});
}
diff --git a/bin/fidl_bindings_test/test/test/tostring_test.dart b/bin/fidl_bindings_test/test/test/tostring_test.dart
index 94e5a6d..649ebde 100644
--- a/bin/fidl_bindings_test/test/test/tostring_test.dart
+++ b/bin/fidl_bindings_test/test/test/tostring_test.dart
@@ -8,6 +8,9 @@
void main() {
print('toString-test');
group('bits', () {
+ test('no bit', () {
+ expect(ExampleBits.$none.toString(), equals(r'ExampleBits.$none'));
+ });
test('single bit', () {
expect(ExampleBits.memberC.toString(), equals(r'ExampleBits.memberC'));
});
diff --git a/bin/fidlgen_dart/backend/templates/bits.tmpl.go b/bin/fidlgen_dart/backend/templates/bits.tmpl.go
index 03d620c..6f06202 100644
--- a/bin/fidlgen_dart/backend/templates/bits.tmpl.go
+++ b/bin/fidlgen_dart/backend/templates/bits.tmpl.go
@@ -17,6 +17,7 @@
{{- end }}
static const {{ $.Name }} {{ .Name }} = {{ $.Name }}._({{ .Value }});
{{- end }}
+ static const {{ .Name }} $none = {{ .Name }}._(0);
const {{ .Name }}._(this.$value);
@@ -24,6 +25,10 @@
return {{ .Name }}._($value | other.$value);
}
+ {{ .Name }} operator &({{ .Name }} other) {
+ return {{ .Name }}._($value & other.$value);
+ }
+
@override
final int $value;