summaryrefslogtreecommitdiff
path: root/hamlet.go
diff options
context:
space:
mode:
Diffstat (limited to 'hamlet.go')
-rw-r--r--hamlet.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/hamlet.go b/hamlet.go
new file mode 100644
index 0000000..1bdcc94
--- /dev/null
+++ b/hamlet.go
@@ -0,0 +1,57 @@
+package hamlet
+
+import "reflect"
+
+type Assertion struct {
+ value bool
+}
+
+func (a Assertion) Value() bool {
+ return a.value
+}
+
+// False reports whether v contains a zero value for its type.
+func False(v any) Assertion {
+ return Assertion{reflect.ValueOf(v).IsZero()}
+}
+
+// True reports whether v contains a non-zero value for its type.
+func True(v any) Assertion {
+ return Assertion{!reflect.ValueOf(v).IsZero()}
+}
+
+func New(v any) Assertion {
+ return Assertion{!reflect.ValueOf(v).IsZero()}
+}
+
+func Not(a Assertion) Assertion {
+ negation := !a.value
+
+ return Assertion{negation}
+}
+
+func Or(a Assertion, b Assertion) Assertion {
+ av := a.value
+ bv := b.value
+
+ return Assertion{av || bv}
+}
+
+func And(a Assertion, b Assertion) Assertion {
+ av := a.value
+ bv := b.value
+
+ return Assertion{av && bv}
+}
+
+func If(a Assertion, b Assertion) Assertion {
+ return Or(Not(a), b)
+}
+
+func Iff(a Assertion, b Assertion) Assertion {
+ return And(If(a, b), If(b, a))
+}
+
+func Xor(a Assertion, b Assertion) Assertion {
+ return Not(Iff(a, b))
+}