-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#feat: Add value or absent option #449
Changes from 4 commits
d6dc397
a08b382
9f32323
f00c4f6
f8be367
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,33 +2,107 @@ import 'package:gql_tristate_value/gql_tristate_value.dart'; | |
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test("requireValue on absent throws", () { | ||
final absent = const AbsentValue(); | ||
group( | ||
'requireValue', | ||
() { | ||
test('on $AbsentValue throws', () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure |
||
final absent = const AbsentValue(); | ||
|
||
expect(() => absent.requireValue, throwsA(isA<StateError>())); | ||
}); | ||
expect(() => absent.requireValue, throwsA(isA<StateError>())); | ||
}); | ||
|
||
test("requireValue on present returns value", () { | ||
final present = Value.present(42); | ||
test('on $PresentValue with valuereturns value', () { | ||
final present = Value.present(42); | ||
|
||
expect(present.requireValue, equals(42)); | ||
}); | ||
expect(present.requireValue, equals(42)); | ||
}); | ||
|
||
test("requireValue on null returns null", () { | ||
final nullValue = Value<String>.present(null); | ||
test('on $PresentValue with null returns null', () { | ||
final nullValue = Value<String>.present(null); | ||
|
||
expect(nullValue.requireValue, isNull); | ||
}); | ||
expect(nullValue.requireValue, isNull); | ||
}); | ||
|
||
test("valueOrNull on absent returns null", () { | ||
final absent = const AbsentValue(); | ||
test('on ${Value.ofNullable} with value returns value', () { | ||
final present = Value.ofNullable(42); | ||
|
||
expect(absent.valueOrNull, isNull); | ||
}); | ||
expect(present.requireValue, equals(42)); | ||
}); | ||
|
||
test("valueOrNull on present returns value", () { | ||
final present = Value.present(42); | ||
test('on ${Value.ofNullable} with null throws', () { | ||
final nullValue = Value<String>.ofNullable(null); | ||
|
||
expect(present.valueOrNull, equals(42)); | ||
}); | ||
expect(() => nullValue.requireValue, throwsA(isA<StateError>())); | ||
}); | ||
}, | ||
); | ||
|
||
group( | ||
'valueOrNull ', | ||
() { | ||
test('on $AbsentValue returns null', () { | ||
final absent = const AbsentValue(); | ||
|
||
expect(absent.valueOrNull, isNull); | ||
}); | ||
|
||
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); | ||
|
||
expect(present.valueOrNull, equals(42)); | ||
}); | ||
|
||
test('on ${Value.ofNullable} with null returns null', () { | ||
final present = Value<String>.ofNullable(null); | ||
|
||
expect(present.valueOrNull, isNull); | ||
}); | ||
}, | ||
); | ||
|
||
group( | ||
'isPresent ', | ||
() { | ||
test('on $AbsentValue returns false', () { | ||
final absent = const AbsentValue(); | ||
|
||
expect(absent.isPresent, false); | ||
}); | ||
|
||
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); | ||
|
||
expect(present.isPresent, true); | ||
}); | ||
|
||
test('on ${Value.ofNullable} with null returns false', () { | ||
final present = Value<String>.ofNullable(null); | ||
|
||
expect(present.isPresent, false); | ||
}); | ||
}, | ||
); | ||
|
||
group( | ||
'toString ', | ||
() { | ||
test('on $PresentValue', () { | ||
final present = Value.present(42); | ||
|
||
expect(present.toString(), 'PresentValue<int>(value: 42)'); | ||
}); | ||
}, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be... My mistake. I am used to having a lint
prefer_const_constructors
😅 Thanks 🙏There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I know, gql_pedantic should be modernized at some point ;)