making map assertions less confusing

This commit is contained in:
Steven Degutis
2012-03-29 07:43:04 -05:00
parent ee69689991
commit fbabfca583
2 changed files with 4 additions and 3 deletions

View File

@@ -11,11 +11,11 @@ func aboutMaps() {
assert(age == __int__) // map syntax is warmly familiar
age, ok := ages["bob"]
assert(ok == __bool__) // with a handy addition for presence checking
assert(ok == __bool__) // with a handy multiple-assignment variation
age, ok = ages["steven"]
assert(age == __int__) // the zero value is used when absent
assert(__bool__) // though there are better ways to check for presence
assert(ok == __boolean__) // though there are better ways to check for presence
assert(len(ages) == __int__) // length is based on keys
@@ -27,5 +27,5 @@ func aboutMaps() {
delete(ages, "steven")
age, ok = ages["steven"]
assert(__bool__) // key/value pairs can be removed
assert(ok == __boolean__) // key/value pairs can be removed
}

View File

@@ -15,6 +15,7 @@ const (
__int__ int = -1
__byte__ byte = 255
__bool__ bool = false // ugh
__boolean__ bool = true // oh well
__float32__ float32 = -1.0
__delete_me__ bool = false
)