Skip to content

Commit

Permalink
chore: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LiLatee committed Feb 20, 2024
1 parent f00c4f6 commit f8be367
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions codegen/gql_tristate_value/lib/src/value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ sealed class Value<T extends Object> {

/// If the value is non-null, it will be serialized as the value.
/// If the value is null. It will not be serialized.
factory Value.ofNullable(T? value) {
factory Value.absentWhenNull(T? value) {
if (value == null) {
return AbsentValue();
return const AbsentValue();
}
return Value.present(value);
}
Expand Down
46 changes: 23 additions & 23 deletions codegen/gql_tristate_value/test/value_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,100 @@ void main() {
group(
'requireValue',
() {
test('on $AbsentValue throws', () {
test('on AbsentValue throws', () {
final absent = const AbsentValue();

expect(() => absent.requireValue, throwsA(isA<StateError>()));
});

test('on $PresentValue with valuereturns value', () {
test('on PresentValue with valuereturns value', () {
final present = Value.present(42);

expect(present.requireValue, equals(42));
});

test('on $PresentValue with null returns null', () {
test('on PresentValue with null returns null', () {
final nullValue = Value<String>.present(null);

expect(nullValue.requireValue, isNull);
});

test('on ${Value.ofNullable} with value returns value', () {
final present = Value.ofNullable(42);
test('on Value.ofNullable with value returns value', () {
final present = Value.absentWhenNull(42);

expect(present.requireValue, equals(42));
});

test('on ${Value.ofNullable} with null throws', () {
final nullValue = Value<String>.ofNullable(null);
test('on Value.ofNullable with null throws', () {
final nullValue = Value<String>.absentWhenNull(null);

expect(() => nullValue.requireValue, throwsA(isA<StateError>()));
});
},
);

group(
'valueOrNull ',
'valueOrNull',
() {
test('on $AbsentValue returns null', () {
test('on AbsentValue returns null', () {
final absent = const AbsentValue();

expect(absent.valueOrNull, isNull);
});

test('on $PresentValue with value returns value', () {
test('on PresentValue with value returns value', () {
final present = Value.present(42);

expect(present.valueOrNull, equals(42));
});

test('on ${Value.ofNullable} with value returns value', () {
final present = Value.ofNullable(42);
test('on Value.ofNullable with value returns value', () {
final present = Value.absentWhenNull(42);

expect(present.valueOrNull, equals(42));
});

test('on ${Value.ofNullable} with null returns null', () {
final present = Value<String>.ofNullable(null);
test('on Value.ofNullable with null returns null', () {
final present = Value<String>.absentWhenNull(null);

expect(present.valueOrNull, isNull);
});
},
);

group(
'isPresent ',
'isPresent',
() {
test('on $AbsentValue returns false', () {
test('on AbsentValue returns false', () {
final absent = const AbsentValue();

expect(absent.isPresent, false);
});

test('on $PresentValue with value returns true', () {
test('on PresentValue with value returns true', () {
final present = Value.present(42);

expect(present.isPresent, true);
});

test('on ${Value.ofNullable} with value returns true', () {
final present = Value.ofNullable(42);
test('on Value.ofNullable with value returns true', () {
final present = Value.absentWhenNull(42);

expect(present.isPresent, true);
});

test('on ${Value.ofNullable} with null returns false', () {
final present = Value<String>.ofNullable(null);
test('on Value.ofNullable with null returns false', () {
final present = Value<String>.absentWhenNull(null);

expect(present.isPresent, false);
});
},
);

group(
'toString ',
'toString',
() {
test('on $PresentValue', () {
test('on PresentValue', () {
final present = Value.present(42);

expect(present.toString(), 'PresentValue<int>(value: 42)');
Expand Down

0 comments on commit f8be367

Please sign in to comment.