@@ -2,6 +2,8 @@ import 'package:checks/checks.dart';
22import 'package:test/scaffolding.dart' ;
33import 'package:zulip/api/model/json.dart' ;
44
5+ import '../../stdlib_checks.dart' ;
6+
57void main () {
68 group ('JsonNullable' , () {
79 test ('value' , () {
@@ -18,6 +20,23 @@ void main() {
1820 check (JsonNullable .readFromJson ({'a' : 3 }, 'a' )).equals (const JsonNullable (3 ));
1921 });
2022
23+ test ('readFromJsonAssertingPresent' , () {
24+ check (() => JsonNullable .readFromJsonAssertingPresent ({}, 'a' ))
25+ .throws <TypeError >();
26+ check (() => JsonNullable .readFromJsonAssertingPresent ({'a' : null }, 'a' ))
27+ .returnsNormally ().isNull ();
28+ check (() => JsonNullable .readFromJsonAssertingPresent ({'a' : 3 }, 'a' ))
29+ .returnsNormally ().equals (3 );
30+ });
31+
32+ test ('toJson / round-tripping' , () {
33+ check (JsonNullable <int >(3 ).toJson ()).equals (3 );
34+ check (JsonNullable <int >(null ).toJson ()).equals (null );
35+
36+ check (JsonNullable .readFromJson ({'a' : null }, 'a' )).jsonEquals (null );
37+ check (JsonNullable .readFromJson ({'a' : 3 }, 'a' )).jsonEquals (3 );
38+ });
39+
2140 test ('==/hashCode' , () {
2241 // ignore: prefer_const_constructors
2342 check (JsonNullable <int >(null )).equals (JsonNullable (null ));
0 commit comments