summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hamlet.go57
-rw-r--r--hamlet_test.go14
2 files changed, 71 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))
+}
diff --git a/hamlet_test.go b/hamlet_test.go
new file mode 100644
index 0000000..d216617
--- /dev/null
+++ b/hamlet_test.go
@@ -0,0 +1,14 @@
+package hamlet
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestAssertion(t *testing.T) {
+ prop1 := New(4)
+ prop2 := New("")
+
+ fmt.Println(If(prop2, prop1))
+ fmt.Println(If(prop1, prop2))
+}